issue167:micro_this_micro_that
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue167:micro_this_micro_that [2021/03/28 11:31] – créée auntiee | issue167:micro_this_micro_that [2021/04/04 17:24] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | + | **March 2021 - Welcome to the first of the “Micro This Micro That” series of articles. Hopefully I will be able to keep up with doing two articles each month. | |
- | March 2021 - Welcome to the first of the “Micro This Micro That” series of articles. Hopefully I will be able to keep up with doing two articles each month. | + | |
So what is Micro This Micro That? The goal is to provide readers with information and projects to demonstrate MicroPython and CircuitPython compatible microcontroller boards and sensors. Occasionally, | So what is Micro This Micro That? The goal is to provide readers with information and projects to demonstrate MicroPython and CircuitPython compatible microcontroller boards and sensors. Occasionally, | ||
- | Before we get into any of the projects, let’s take a look at exactly what a microcontroller actually is. From the AllAboutCircuits website, we get a very clear explanation of this... | + | Before we get into any of the projects, let’s take a look at exactly what a microcontroller actually is. From the AllAboutCircuits website, we get a very clear explanation of this...** |
+ | |||
+ | Mars 2021 - Bienvenue au premier article de la série « Micro Ceci Micro Cela ». J' | ||
+ | |||
+ | Alors, qu' | ||
+ | |||
+ | Avant d' | ||
+ | |||
+ | |||
+ | **“Microcontrollers are small, versatile, inexpensive devices that can be successfully implemented and programmed not only by experienced electrical engineers but also by hobbyists, students, and professionals from other disciplines.” | ||
+ | |||
+ | Today, there are many different types of Microcontrollers out there. The line of Arduino products is a prime example of Microcontrollers. The group at Adafruit also have many products as well as the folks at Sparkfun. Most recently, the Raspberry Pi Foundation announced and released the Raspberry Pi Pico board that is based on their brand new RP2040 chip, which is their first Microcontroller product. The response to the RPi Pico has been astounding, and there have been many companies that have announced products based on the RP2040 chip. The most exciting thing for those of us who program in Python is that the RPi Pico can not only be programmed using C/C++, like the Arduino, but with both MicroPython and CircuitPython. Many of the products from Adafruit can be programmed using CircuitPython, | ||
+ | |||
+ | « Les microcontrôleurs sont de petits dispositifs polyvalents et peu coûteux qui peuvent être mis en œuvre et programmés avec succès non seulement par des ingénieurs électriciens expérimentés, | ||
- | “Microcontrollers are small, versatile, inexpensive devices that can be successfully implemented and programmed not only by experienced electrical engineers but also by hobbyists, students, and professionals from other disciplines.” | + | Aujourd' |
- | Today, there are many different types of Microcontrollers out there. The line of Arduino products is a prime example of Microcontrollers. The group at Adafruit also have many products as well as the folks at Sparkfun. Most recently, the Raspberry Pi Foundation announced and released the Raspberry Pi Pico board that is based on their brand new RP2040 chip, which is their first Microcontroller product. The response to the RPi Pico has been astounding, and there have been many companies that have announced products based on the RP2040 chip. The most exciting thing for those of us who program in Python is that the RPi Pico can not only be programmed using C/C++, like the Arduino, but with both MicroPython and CircuitPython. Many of the products from Adafruit can be programmed using CircuitPython, | ||
- | Let’s look at MicroPython, | + | **Let’s look at MicroPython, |
As cool as that sounds, there are some limitations. If you normally program using Python 3.7+, you will find things like the “f-strings” will throw syntax errors. | As cool as that sounds, there are some limitations. If you normally program using Python 3.7+, you will find things like the “f-strings” will throw syntax errors. | ||
- | At this writing, libraries like numpy, pandas and matplotlib are not currently available in the forms you are used to. However, a small subset of numpy is currently under development, | + | At this writing, libraries like numpy, pandas and matplotlib are not currently available in the forms you are used to. However, a small subset of numpy is currently under development, |
- | For years, I’ve told my son, and many others “If you live or work on the bleeding edge, you WILL get cut!”, and believe me, that’s SO very true when dealing with Microcontrollers. I’ll explain more in a little bit. | + | Penchons-nous un instant sur MicroPython en général. MicroPython est le fruit de l' |
- | All that having been said, I won’t only deal with the RPi Pico board in this series of articles. Yes, I will concentrate on it for a few articles, but I also intend on talking about the Adafruit FeatherS2 microcontroller and some of the Arduino boards, and maybe some of the boards from Sparkfun and others as my budget allows. | + | Aussi cool que cela puisse paraître, il y a quelques limitations. Si vous programmez normalement en utilisant Python 3.7+, vous trouverez que des choses comme les « f-strings » retournent des erreurs de syntaxe. |
- | Raspberry Pi Pico | + | À ce jour, des bibliothèques comme numpy, pandas et matplotlib ne sont pas disponibles sous les formes auxquelles vous êtes habitués. Cependant, un petit sous-ensemble de numpy est en cours de développement, |
+ | |||
+ | |||
+ | **For years, I’ve told my son, and many others “If you live or work on the bleeding edge, you WILL get cut!”, and believe me, that’s SO very true when dealing with Microcontrollers. I’ll explain more in a little bit. | ||
+ | |||
+ | All that having been said, I won’t only deal with the RPi Pico board in this series of articles. Yes, I will concentrate on it for a few articles, but I also intend on talking about the Adafruit FeatherS2 microcontroller and some of the Arduino boards, and maybe some of the boards from Sparkfun and others as my budget allows.** | ||
+ | |||
+ | Pendant des années, j'ai dit à mon fils, et à beaucoup d' | ||
+ | |||
+ | Tout cela étant dit, je ne traiterai pas uniquement de la carte RPi Pico dans cette série d' | ||
+ | |||
+ | |||
+ | **Raspberry Pi Pico | ||
As I write this, the RPi Pico has been available for a little over one month. As you can see in the image below, it’s a tiny little thing that’s about 2” x 1”. | As I write this, the RPi Pico has been available for a little over one month. As you can see in the image below, it’s a tiny little thing that’s about 2” x 1”. | ||
Ligne 26: | Ligne 49: | ||
You don’t actually need to have any external LEDs or sensors to see the board work, since there is an addressable LED already on the board. You don’t even need to solder the header pins for our first two projects. | You don’t actually need to have any external LEDs or sensors to see the board work, since there is an addressable LED already on the board. You don’t even need to solder the header pins for our first two projects. | ||
- | Of course, you’ll also need a computer to talk to and power the RPi Pico. You can use any type of computer. Many people use a Raspberry Pi 3 or 4, and I use my normal Linux Desktop. I am sure that it also will work on a Windows or Mac PC. | + | Of course, you’ll also need a computer to talk to and power the RPi Pico. You can use any type of computer. Many people use a Raspberry Pi 3 or 4, and I use my normal Linux Desktop. I am sure that it also will work on a Windows or Mac PC.** |
- | In addition, you will need a copy of Thonny IDE. If you are using a Raspberry Pi as your connection to the Pico, you probably already have Thonny. Just make sure that it’s version 3.3.3 or better. If you are using a Linux or other OS PC, you probably will need to download it. You need version 3.3.3 or greater. The latest version (as of this writing) is 3.3.5. To install it on your Linux machine, you can simply use wget in a terminal… | + | Raspberry Pi Pico |
+ | |||
+ | Au moment où j' | ||
+ | |||
+ | Il n'est pas nécessaire d' | ||
+ | |||
+ | Bien entendu, vous aurez également besoin d'un ordinateur pour communiquer avec la RPi Pico et l' | ||
+ | |||
+ | |||
+ | **In addition, you will need a copy of Thonny IDE. If you are using a Raspberry Pi as your connection to the Pico, you probably already have Thonny. Just make sure that it’s version 3.3.3 or better. If you are using a Linux or other OS PC, you probably will need to download it. You need version 3.3.3 or greater. The latest version (as of this writing) is 3.3.5. To install it on your Linux machine, you can simply use wget in a terminal… | ||
wget -O thonny-latest.sh https:// | wget -O thonny-latest.sh https:// | ||
Ligne 36: | Ligne 68: | ||
sudo apt install wget | sudo apt install wget | ||
- | Once you have the file, change the permission to executable, then run it from the terminal command prompt. | + | Once you have the file, change the permission to executable, then run it from the terminal command prompt.** |
- | Now start Thonny, and get your RPi Pico and Micro USB cable ready. On the Pico, hold down the white BOOTSEL button and, while holding it down, plug in the cable. Make sure the other end is connected to your computer. In a moment, you will see a new file manager window pop open. | + | En outre, vous aurez besoin d'une copie de l'IDE Thonny. Si vous utilisez un Raspberry Pi pour vous connecter au Pico, vous avez probablement déjà Thonny. Assurez-vous simplement qu'il s'agit de la version 3.3.3 ou supérieure. Si vous utilisez un PC sous Linux ou un autre système d' |
+ | |||
+ | wget -O thonny-latest.sh https:// | ||
+ | |||
+ | Si vous n'avez pas wget, vous pouvez l' | ||
+ | |||
+ | sudo apt install wget | ||
+ | |||
+ | Une fois que vous avez le fichier, changez la permission en exécutable, | ||
+ | |||
+ | |||
+ | **Now start Thonny, and get your RPi Pico and Micro USB cable ready. On the Pico, hold down the white BOOTSEL button and, while holding it down, plug in the cable. Make sure the other end is connected to your computer. In a moment, you will see a new file manager window pop open. | ||
Once you see this window, you can release the BOOTSEL button. Now back to Thonny, and select Run|Select Interpreter from the main menu. You should see a window pop up that looks something like this: | Once you see this window, you can release the BOOTSEL button. Now back to Thonny, and select Run|Select Interpreter from the main menu. You should see a window pop up that looks something like this: | ||
Click on the [Install] button; you should see it start to download the MicroPython for the Pico. When it’s finished, you will see a window like this… | Click on the [Install] button; you should see it start to download the MicroPython for the Pico. When it’s finished, you will see a window like this… | ||
- | Now we can start programming! | + | Now we can start programming!** |
- | Project #1 | + | Maintenant, démarrez Thonny, et préparez votre RPi Pico et votre câble Micro USB. Sur le Pico, maintenez le bouton BOOTSEL blanc enfoncé et, tout en le maintenant enfoncé, branchez le câble. Assurez-vous que l' |
+ | |||
+ | Dès que vous voyez cette fenêtre, vous pouvez relâcher le bouton BOOTSEL. Revenez maintenant à Thonny, et sélectionnez Run|Select Interpreter dans le menu principal. Vous devriez voir apparaître une fenêtre qui ressemble à quelque chose comme ceci : | ||
+ | |||
+ | Cliquez sur le bouton [Install] ; vous devriez voir démarrer le téléchargement de MicroPython pour le Pico. Lorsque le téléchargement est terminé, vous verrez une fenêtre comme celle-ci : | ||
+ | |||
+ | Maintenant, nous pouvons commencer à programmer ! | ||
+ | |||
+ | |||
+ | **Project #1 | ||
In project #1, we’ll do a very simple program that simply blinks the onboard LED. The code is below. | In project #1, we’ll do a very simple program that simply blinks the onboard LED. The code is below. | ||
Ligne 51: | Ligne 103: | ||
Now before I explain the code, click on the Run button in Thonny and see what happens. You should see the LED near the USB port come on for about 3 seconds and then go off for three seconds, and start all over again. | Now before I explain the code, click on the Run button in Thonny and see what happens. You should see the LED near the USB port come on for about 3 seconds and then go off for three seconds, and start all over again. | ||
- | Now I’ll explain the code. First, you will need to import two libraries, machine and utime. The machine library will almost always be needed, and utime is a MicroPython time library similar to the “big brother Python” time library, only smaller and designed just for MicroPython. | + | Now I’ll explain the code. First, you will need to import two libraries, machine and utime. The machine library will almost always be needed, and utime is a MicroPython time library similar to the “big brother Python” time library, only smaller and designed just for MicroPython.** |
- | Next, we create an object by pointing to the pin number and telling it whether it’s supposed to be an input or an output pin. We’ll call this object “led_onboard”. Notice that we are using the GPIO number, not the physical pin number. Other systems like CircuitPython use the physical pin instead of the GPIO number. We’ll get more into that another time, but for now, just remember that when you are using MicroPython, | + | Projet n° 1 |
+ | |||
+ | Dans le projet n° 1, nous allons faire un programme très simple qui fait seulement clignoter la LED intégrée. Le code est ci-dessous. | ||
+ | |||
+ | Avant que je n' | ||
+ | |||
+ | Je vais maintenant vous expliquer le code. Tout d' | ||
+ | |||
+ | |||
+ | **Next, we create an object by pointing to the pin number and telling it whether it’s supposed to be an input or an output pin. We’ll call this object “led_onboard”. Notice that we are using the GPIO number, not the physical pin number. Other systems like CircuitPython use the physical pin instead of the GPIO number. We’ll get more into that another time, but for now, just remember that when you are using MicroPython, | ||
Next, we create a forever loop that sets the value to 1 (high) or 0 (low). When the pin switches to high, the voltage (in this case) goes to 3.3 volts which turns on the LED. When the pin switches to low, the voltage goes to 0 volts. Once we set the value to 1, we sleep for three seconds then set the value 0 and sleep 3 more seconds, then start it all over again. | Next, we create a forever loop that sets the value to 1 (high) or 0 (low). When the pin switches to high, the voltage (in this case) goes to 3.3 volts which turns on the LED. When the pin switches to low, the voltage goes to 0 volts. Once we set the value to 1, we sleep for three seconds then set the value 0 and sleep 3 more seconds, then start it all over again. | ||
- | Be sure to save your code on your main machine, just in case something happens to your Pico. | + | Be sure to save your code on your main machine, just in case something happens to your Pico.** |
+ | |||
+ | Ensuite, nous créons un objet en pointant le numéro de la broche en lui indiquant s'il s'agit d'une broche d' | ||
+ | |||
+ | Ensuite, nous créons une boucle sans fin qui fixe la valeur à 1 (haut) ou 0 (bas). Lorsque la broche passe au niveau haut, la tension (dans ce cas) passe à 3,3 volts, ce qui allume la LED. Lorsque la broche passe au niveau bas, la tension passe à 0 volt. Une fois que nous avons fixé la valeur à 1, nous veillons pendant trois secondes, puis nous fixons la valeur à 0 et nous veillons encore trois secondes, puis nous recommençons. | ||
+ | |||
+ | Assurez-vous de sauvegarder votre code sur votre machine principale, juste au cas où quelque chose arriverait à votre Pico. | ||
- | Project #2 | + | **Project #2 |
In project #2, we’ll make the onboard LED do something a little bit different. Rather than just blinking on and off, we’ll use the PWM (Pulse Width Modulation) function. We’ve done this a long time ago on the Raspberry Pi. | In project #2, we’ll make the onboard LED do something a little bit different. Rather than just blinking on and off, we’ll use the PWM (Pulse Width Modulation) function. We’ve done this a long time ago on the Raspberry Pi. | ||
Ligne 65: | Ligne 133: | ||
I won’t go too deeply into the code with you right now, we’ll revisit this in a future article, plus, as I said, we did a similar project on the Raspberry Pi a few years ago. I just think that the throbbing LED is cool and especially with the onboard led. | I won’t go too deeply into the code with you right now, we’ll revisit this in a future article, plus, as I said, we did a similar project on the Raspberry Pi a few years ago. I just think that the throbbing LED is cool and especially with the onboard led. | ||
- | You should be able to find the code presented here at my github repository at: https:// | + | You should be able to find the code presented here at my github repository at: https:// |
- | Since we have used the onboard LED for these two projects, there were no external components required. However, for our upcoming projects, we’ll need a breadboard, LEDs, jumper wires, resistors, etc. One word of warning though. ALL voltages for the RPi Pico are 3.3 volts. Many older sensors and displays are 5 volt, and will cause problems with the Pico, up to and including burning out the Pico. You should consider getting a Logic Level Converter that will safely change the voltages from 5 volts to 3 volts. Here are two sources that can get you started in your search… | + | Projet n° 2 |
+ | |||
+ | Dans le projet n° 2, nous allons faire en sorte que la LED intégrée fasse quelque chose d'un peu différent. Au lieu de seulement clignoter, nous allons utiliser la fonction PWM (Pulse Width Modulation - Modulation de largeur d' | ||
+ | |||
+ | Je ne vais pas m' | ||
+ | |||
+ | Vous devriez pouvoir trouver le code présenté ici sur mon dépôt github à l' | ||
+ | |||
+ | |||
+ | **Since we have used the onboard LED for these two projects, there were no external components required. However, for our upcoming projects, we’ll need a breadboard, LEDs, jumper wires, resistors, etc. One word of warning though. ALL voltages for the RPi Pico are 3.3 volts. Many older sensors and displays are 5 volt, and will cause problems with the Pico, up to and including burning out the Pico. You should consider getting a Logic Level Converter that will safely change the voltages from 5 volts to 3 volts. Here are two sources that can get you started in your search… | ||
https:// | https:// | ||
Ligne 74: | Ligne 151: | ||
Also, before you start interfacing devices to your Pico, you should get your hands on the pinout of the board. You can download a copy of the RPi Pico pinout for your easy reference… | Also, before you start interfacing devices to your Pico, you should get your hands on the pinout of the board. You can download a copy of the RPi Pico pinout for your easy reference… | ||
+ | |||
+ | https:// | ||
+ | |||
+ | Puisque nous avons utilisé la LED intégrée pour ces deux projets, aucun composant externe n'a été nécessaire. Cependant, pour nos prochains projets, nous aurons besoin d'un circuit d' | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | En outre, avant de commencer à interfacer des appareils à votre Pico, vous devez mettre la main sur le brochage de la carte. Vous pouvez télécharger une copie du brochage du RPi Pico pour vous y référer facilement : | ||
https:// | https:// | ||
- | One final thought. Earlier I said “If you live or work on the bleeding edge, you WILL get cut!”. The RPi Pico has only been out a little over a month as I write this. The MicroPython for the Pico (http:// | ||
- | This is all to be expected this early in the process. Sales of the Pico are so swift, that many retailers haven’t gotten a single stick and are still in a “back order” mode, or they have gotten some, but sold out within a day or two. The Arduino RP2040 device is coming with WiFi support, but still doesn’t have a release date or price. Sparkfun and Adafruit have boards coming out based on the RP2040, but still haven’t been released. If your display or sensor is extremely old or had limited sales, you might have to “bite the bullet” and consider getting a newer version that does have support, or look into writing your own driver library. | + | **One final thought. Earlier I said “If you live or work on the bleeding edge, you WILL get cut!”. The RPi Pico has only been out a little over a month as I write this. The MicroPython for the Pico (http:// |
+ | |||
+ | Une dernière pensée. Plus haut, j'ai dit « Si vous vivez ou travaillez à la pointe de l' | ||
+ | |||
+ | |||
+ | **This is all to be expected this early in the process. Sales of the Pico are so swift, that many retailers haven’t gotten a single stick and are still in a “back order” mode, or they have gotten some, but sold out within a day or two. The Arduino RP2040 device is coming with WiFi support, but still doesn’t have a release date or price. Sparkfun and Adafruit have boards coming out based on the RP2040, but still haven’t been released. If your display or sensor is extremely old or had limited sales, you might have to “bite the bullet” and consider getting a newer version that does have support, or look into writing your own driver library. | ||
I’m certain that in the next month or so, many of these issues will be solved. I don’t think that anyone thought that the Pico or the RP2040 would take off as strongly as it has. The price of the Pico makes it perfect for someone who wants to break into Microcontroller programming and experimentation. | I’m certain that in the next month or so, many of these issues will be solved. I don’t think that anyone thought that the Pico or the RP2040 would take off as strongly as it has. The price of the Pico makes it perfect for someone who wants to break into Microcontroller programming and experimentation. | ||
- | Until next time, as always; stay safe, healthy, positive and creative! | + | Until next time, as always; stay safe, healthy, positive and creative!** |
+ | |||
+ | Il fallait s'y attendre au début du processus. Les ventes du Pico sont si rapides que de nombreux détaillants n'ont pas encore reçu la moindre pièce et sont toujours en mode « précommande », ou bien ils en ont reçu quelques-unes, | ||
+ | |||
+ | Je suis certain que d'ici un mois environ, la plupart de ces problèmes seront résolus. Je ne pense pas que quiconque ait pensé que le Pico ou le RP2040 connaîtrait un tel essor. Le prix du Pico le rend parfait pour quelqu' | ||
+ | |||
+ | Jusqu' | ||
issue167/micro_this_micro_that.1616923906.txt.gz · Dernière modification : 2021/03/28 11:31 de auntiee