issue167:micro_this_micro_that
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| issue167:micro_this_micro_that [2021/04/01 18:44] – d52fr | issue167:micro_this_micro_that [2021/04/04 17:24] (Version actuelle) – andre_domenech | ||
|---|---|---|---|
| Ligne 4: | Ligne 4: | ||
| 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.” | **“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, | 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, | ||
| + | |||
| + | Aujourd' | ||
| + | |||
| **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, | ||
| + | |||
| + | Penchons-nous un instant sur MicroPython en général. MicroPython est le fruit de l' | ||
| + | |||
| + | 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. | ||
| + | |||
| + | À 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, | ||
| - | **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. | **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.** | 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 | **Raspberry Pi Pico | ||
| Ligne 26: | Ligne 50: | ||
| 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.** | ||
| + | |||
| + | 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… | **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… | ||
| Ligne 36: | Ligne 69: | ||
| 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.** | ||
| + | |||
| + | 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. | **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. | ||
| Ligne 43: | Ligne 87: | ||
| 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!** | ||
| + | |||
| + | 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 | **Project #1 | ||
| Ligne 51: | Ligne 104: | ||
| 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.** | ||
| + | |||
| + | 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 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, | ||
| Ligne 57: | Ligne 119: | ||
| 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 | ||
| Ligne 65: | Ligne 134: | ||
| 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:// | ||
| + | |||
| + | 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… | **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… | ||
| Ligne 75: | Ligne 153: | ||
| https:// | 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:// | ||
| + | |||
| **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:// | **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. | **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. | ||
| Ligne 83: | Ligne 175: | ||
| 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.1617295475.txt.gz · Dernière modification : 2021/04/01 18:44 de d52fr
