issue166:python
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 | ||
issue166:python [2021/02/28 08:11] – d52fr | issue166:python [2021/03/04 14:28] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 13: | Ligne 13: | ||
• Low power. All GPIOs use 3.3VDC (NOT 5V) | • Low power. All GPIOs use 3.3VDC (NOT 5V) | ||
• And more** | • And more** | ||
+ | |||
+ | Je ne sais pas si vous en avez entendu parler, mais le 21 janvier 2021, les gens de Raspberry Pi ont annoncé la création d'une nouvelle carte. Elle s' | ||
+ | - Un processeur ARM Cortex M0+ à double cœur fonctionnant jusqu' | ||
+ | - 264 Ko de SRAM et 2 Mo de mémoire Flash embarquée | ||
+ | - Programmation par glisser-déposer utilisant le stockage de masse via USB | ||
+ | - 26 broches GPIO (Entrées/ | ||
+ | - 2 x I2c, 2 x SPI, 2 x UARTs et 3 x ports ADC 12 bits | ||
+ | - 16 broches PWM contrôlables | ||
+ | - Port série ARM 3 broches pour le débogage (SWD) | ||
+ | - Capteur de température intégré | ||
+ | - 8 machines d' | ||
+ | - Port Micro-USB B pour l' | ||
+ | - Le développement de la carte supporte à la fois un SDK C/C++ et un portage officiel de MicroPython | ||
+ | - Faible consommation. Tous les GPIO utilisent 3,3 VDC (PAS 5 V) | ||
+ | - Et plus encore... | ||
+ | |||
**Now, some of these specs might not get your blood pumping faster, but consider the 2 I2c ports, 2 SPI ports and 2 UARTS, that’s a lot of interface possibilities, | **Now, some of these specs might not get your blood pumping faster, but consider the 2 I2c ports, 2 SPI ports and 2 UARTS, that’s a lot of interface possibilities, | ||
Ligne 20: | Ligne 36: | ||
Of course, I went on the Internet to try to buy one the very first day. I was extremely lucky to find an online retailer that still had some left. It hasn’t arrived yet, so I can’t give you any information on how the board performs quite yet. In addition, I had to find a Micro-USB type B cable before I could use it. Luckily, I have some header pins from an old project that are left over, so I should be good to go as soon as it comes in.** | Of course, I went on the Internet to try to buy one the very first day. I was extremely lucky to find an online retailer that still had some left. It hasn’t arrived yet, so I can’t give you any information on how the board performs quite yet. In addition, I had to find a Micro-USB type B cable before I could use it. Luckily, I have some header pins from an old project that are left over, so I should be good to go as soon as it comes in.** | ||
- | **You can find more on the Raspberry Pi Pico at https:// | + | Certaines de ces spécifications ne feront peut-être pas battre votre cœur plus rapidement, mais si on considère les 2 ports I2c, les 2 ports SPI et les 2 UARTS, cela fait beaucoup de possibilités d' |
+ | |||
+ | La carte elle-même ne fait que 51x21mm (c'est à peu près 2x0.8 pouces dans la tête d'une américaine) ! | ||
+ | |||
+ | Bien sûr, je suis allé sur Internet pour essayer d'en acheter une dès le premier jour. J'ai eu beaucoup de chance de trouver un détaillant en ligne qui en avait encore. Elle n'est pas encore arrivée, donc je ne peux pas encore vous donner d' | ||
+ | |||
+ | |||
+ | **You can find more on the Raspberry Pi Pico at https:// | ||
In addition to all of that, the very next day (January 22, 2021), the Arduino group announced they also will be releasing a new board based on the 2040 chipset along with some extras like WIFI and Bluetooth as well as 9-axis IMU sensor and microphone. They have stated that they will be updating their IDE to support the new board. It’s expected to be called the Arduino Nano RP2040. Very little is known at this point beyond these details. You can see the announcement at https:// | In addition to all of that, the very next day (January 22, 2021), the Arduino group announced they also will be releasing a new board based on the 2040 chipset along with some extras like WIFI and Bluetooth as well as 9-axis IMU sensor and microphone. They have stated that they will be updating their IDE to support the new board. It’s expected to be called the Arduino Nano RP2040. Very little is known at this point beyond these details. You can see the announcement at https:// | ||
+ | |||
+ | Vous pouvez trouver plus d' | ||
+ | |||
+ | Outre tout cela, le lendemain (le 22 janvier 2021), le groupe Arduino a annoncé la sortie d'une nouvelle carte basée sur le chipset 2040, avec quelques extras comme le Wifi et le Bluetooth, ainsi qu'un capteur IMU 9 axes et un microphone. Ils ont déclaré qu'ils mettront à jour leur IDE pour supporter la nouvelle carte. Elle devrait s' | ||
+ | |||
**If you are interested in the Raspberry Pi Pico or the new Arduino Nano RP2040, or if you are still on the fence about it all, check out this link. https:// | **If you are interested in the Raspberry Pi Pico or the new Arduino Nano RP2040, or if you are still on the fence about it all, check out this link. https:// | ||
+ | |||
+ | Si vous êtes intéressé par le Raspberry Pi Pico ou le nouvel Arduino Nano RP2040, ou si vous êtes toujours hésitant à ce sujet, consultez ce lien : https:// | ||
+ | |||
**Now that the announcements are over, we’ll get back to Python things. Most of you readers have been with me for a while, and you might remember back to late 2015 and early 2016 where I started talking about the Raspberry Pi and Python programming. I’ve been having to do some small-board computer programming development lately and one project specifically had me creating a prototype test program on the RPi for GPIO use. I am somewhat proud of the fact that I have at least one of every RPi board model – from the original version 1 to the latest version 4, and a RPi zero. There are three boards that are in constant use, one as a media center, one as a network server, and one that is for “current” RPi type projects. | **Now that the announcements are over, we’ll get back to Python things. Most of you readers have been with me for a while, and you might remember back to late 2015 and early 2016 where I started talking about the Raspberry Pi and Python programming. I’ve been having to do some small-board computer programming development lately and one project specifically had me creating a prototype test program on the RPi for GPIO use. I am somewhat proud of the fact that I have at least one of every RPi board model – from the original version 1 to the latest version 4, and a RPi zero. There are three boards that are in constant use, one as a media center, one as a network server, and one that is for “current” RPi type projects. | ||
One of the downsides of working with the Raspberry Pi is that they are slow. Even the RPi 4 with 8 Gig of Ram is somewhat slow compared to my “big boy” Linux box. But, as they say, needs must. When you need to deal with GPIO programming and sensors, there are very few options out there that don’t include the RPi. IOT (Internet Of Things) and sensors pretty much require either the RPi or an Arduino (which is another story all together).** | One of the downsides of working with the Raspberry Pi is that they are slow. Even the RPi 4 with 8 Gig of Ram is somewhat slow compared to my “big boy” Linux box. But, as they say, needs must. When you need to deal with GPIO programming and sensors, there are very few options out there that don’t include the RPi. IOT (Internet Of Things) and sensors pretty much require either the RPi or an Arduino (which is another story all together).** | ||
+ | |||
+ | Maintenant que ces annonces sont faites, nous allons revenir aux choses en Python. La plupart d' | ||
+ | |||
+ | L'un des inconvénients du travail avec les Raspberry Pi, c'est qu'ils sont lents. Même le RPi 4 avec 8 Go de Ram est un peu lent par rapport à mon grand boîtier Linux. Mais, comme on dit, les besoins doivent être satisfaits. Quand vous devez vous occuper de la programmation de GPIO et de capteurs, il y a très peu d' | ||
+ | |||
**However, some of that frustration might be gone. I recently found a small device that allows us to do GPIO programming directly on a Linux box, Windows machine, or Mac, without the use of the remote GPIO and a RPi in the mix. (We’ll talk about remote GPIO another time). In theory, you should be able to create and test Python GPIO programs on your main development machine, and then simply copy the code over to your target RPi, make the connections to your sensor, and, with (possibly) one change to the code, be running on the RPi immediately. Are you thinking “If it sounds too good to be true, it has to be?” We’ll find out. I ordered one just about the same time that I ordered the RPi PICO and it came in just last night.** | **However, some of that frustration might be gone. I recently found a small device that allows us to do GPIO programming directly on a Linux box, Windows machine, or Mac, without the use of the remote GPIO and a RPi in the mix. (We’ll talk about remote GPIO another time). In theory, you should be able to create and test Python GPIO programs on your main development machine, and then simply copy the code over to your target RPi, make the connections to your sensor, and, with (possibly) one change to the code, be running on the RPi immediately. Are you thinking “If it sounds too good to be true, it has to be?” We’ll find out. I ordered one just about the same time that I ordered the RPi PICO and it came in just last night.** | ||
+ | |||
+ | Cependant, une partie de cette frustration pourrait bien avoir disparu. J'ai récemment trouvé un petit appareil qui nous permet de faire de la programmation de GPIO directement sur un boîtier Linux, une machine Windows ou un Mac, sans utiliser le GPIO distant et un RPi dans ce mélange. (Nous parlerons des GPIO distants une autre fois). En théorie, vous devriez pouvoir créer et tester des programmes en Python pour les GPIO sur votre machine de développement principale, puis copier le code sur votre RPi cible, établir les connexions avec votre capteur et, avec (éventuellement) une modification du code, les exécuter immédiatement sur le RPi. Vous vous dites : « Si ça semble trop beau pour être vrai, ça doit l' | ||
+ | |||
**Check out https:// | **Check out https:// | ||
Ligne 37: | Ligne 76: | ||
sudo usermod -a -G dialout $USER** | sudo usermod -a -G dialout $USER** | ||
+ | |||
+ | Consultez le site https:// | ||
+ | |||
+ | En suivant les instructions sur https:// | ||
+ | |||
+ | sudo usermod -a -G dialout $USER | ||
+ | |||
**The reason for this, just in case you are interested, is that the connection to the RTK.GPIO board not only powers the board, but communicates via one of the serial ports on the Linux box. | **The reason for this, just in case you are interested, is that the connection to the RTK.GPIO board not only powers the board, but communicates via one of the serial ports on the Linux box. | ||
Ligne 47: | Ligne 93: | ||
sudo -H pip3 install RTk** | sudo -H pip3 install RTk** | ||
+ | |||
+ | La raison en est, au cas où cela vous intéresserait, | ||
+ | |||
+ | Ensuite, nous devons nous assurer que certains logiciels existent sur notre machine principale. Ces logiciels sont probablement déjà sur votre machine, mais juste au cas où, nous entrerons la commande suivante dans le terminal : | ||
+ | |||
+ | sudo apt-get install python3-pip python3-setuptools python3-wheel | ||
+ | |||
+ | Ils vous suggèrent de redémarrer votre machine à ce stade. Enfin, nous devons installer la bibliothèque Python. | ||
+ | |||
+ | sudo -H pip3 install RTk | ||
+ | |||
**Now that that is all done, we can start adding the components to our protoboard. Of course, you’ll need a protoboard, a few jumpers, an LED, a resistor (220 ohm), and a momentary switch. | **Now that that is all done, we can start adding the components to our protoboard. Of course, you’ll need a protoboard, a few jumpers, an LED, a resistor (220 ohm), and a momentary switch. | ||
Ligne 52: | Ligne 109: | ||
Remember that LEDs have a positive and negative leg. The Anode is the longer leg and should be connected to the positive voltage, the Cathode is the negative (shorter) leg. | Remember that LEDs have a positive and negative leg. The Anode is the longer leg and should be connected to the positive voltage, the Cathode is the negative (shorter) leg. | ||
In our circuit (next page, top left), we’ll be setting the GPIO pin to a low level in order to turn the LED on, so we’ll connect the 220 ohm resistor directly between the 3.3 volt pin and the Anode of the LED, then connect the Cathode to our GPIO pin to complete the circuit. For the switch, we’ll connect one side of the switch directly to ground and the other directly to a different GPIO pin** | In our circuit (next page, top left), we’ll be setting the GPIO pin to a low level in order to turn the LED on, so we’ll connect the 220 ohm resistor directly between the 3.3 volt pin and the Anode of the LED, then connect the Cathode to our GPIO pin to complete the circuit. For the switch, we’ll connect one side of the switch directly to ground and the other directly to a different GPIO pin** | ||
+ | |||
+ | Maintenant que tout cela est fait, nous pouvons commencer à ajouter les composants à notre carte d' | ||
+ | |||
+ | N' | ||
+ | |||
+ | Dans notre circuit (page suivante, en haut à gauche), nous allons mettre la broche GPIO à un niveau bas afin d' | ||
+ | |||
**Now for the code. I’m using the same code that we did in the original FCM# 104 article, with a few modifications where needed. | **Now for the code. I’m using the same code that we did in the original FCM# 104 article, with a few modifications where needed. | ||
Ligne 60: | Ligne 124: | ||
First, of course, we need to import the GPIO library. On the RPi, we used the RPi.GPIO library, but for our RTK board, we need to use the RTk library.** | First, of course, we need to import the GPIO library. On the RPi, we used the RPi.GPIO library, but for our RTK board, we need to use the RTk library.** | ||
+ | |||
+ | Passons maintenant au code. J' | ||
+ | |||
+ | # importer RTk.GPIO en tant que GPIO | ||
+ | |||
+ | import RTk.GPIO as GPIO | ||
+ | |||
+ | Tout d' | ||
+ | |||
**In the original code, we had the option to use either the BCM GPIO pin numbers or the physical board numbers. At this point, it looks like the RTK board supports only the BCM pin numbering scheme. I have yet to verify this, but for the sake of time, we’ll stick with the BCM numbering scheme. Luckily, the RTK board has the pin numbers silk screened directly on the board right next to the GPIO pins. In the original code, I opted to use the board numbers, so I’ve just commented out those commands and uncommented the code that deals with the BCM numbering (top right). | **In the original code, we had the option to use either the BCM GPIO pin numbers or the physical board numbers. At this point, it looks like the RTK board supports only the BCM pin numbering scheme. I have yet to verify this, but for the sake of time, we’ll stick with the BCM numbering scheme. Luckily, the RTK board has the pin numbers silk screened directly on the board right next to the GPIO pins. In the original code, I opted to use the board numbers, so I’ve just commented out those commands and uncommented the code that deals with the BCM numbering (top right). | ||
So we have our LED connected to GPIO pin 18 and the button connected to GPIO pin 17. Now we can create a function to do all the setup commands (above).** | So we have our LED connected to GPIO pin 18 and the button connected to GPIO pin 17. Now we can create a function to do all the setup commands (above).** | ||
+ | |||
+ | Dans le code d' | ||
+ | |||
+ | Ainsi, nous avons notre LED connectée à la broche GPIO 18 et le bouton connecté à la broche GPIO 17. Nous pouvons maintenant créer une fonction pour effectuer toutes les commandes de configuration (ci-dessus). | ||
+ | |||
**Next, we’ll create a loop function (bottom left) to constantly look for the button to be pressed. When we see that, we’ll drive the LED pin to a low state, turning on the LED. | **Next, we’ll create a loop function (bottom left) to constantly look for the button to be pressed. When we see that, we’ll drive the LED pin to a low state, turning on the LED. | ||
Ligne 77: | Ligne 155: | ||
Finally, we’ll create the entry point code to get things started (next page, top right).** | Finally, we’ll create the entry point code to get things started (next page, top right).** | ||
+ | |||
+ | Ensuite, nous allons créer une fonction en boucle (en bas à gauche) pour surveiller en permanence le bouton qui sera enfoncé. Lorsque nous verrons cela, nous mettrons la broche de la LED dans un état bas, ce qui allumera la LED. | ||
+ | |||
+ | Ensuite, nous créerons une fonction destroy (détruire) qui réinitialisera la broche de la LED et libérera correctement le code de la bibliothèque GPIO. | ||
+ | |||
+ | def destroy() : | ||
+ | |||
+ | GPIO.output(LedPin, | ||
+ | |||
+ | GPIO.cleanup() | ||
+ | |||
+ | |||
+ | Enfin, nous allons créer le code du point d' | ||
+ | |||
**When you run the program, you’ll see the LED turn on as long as the button is pressed. | **When you run the program, you’ll see the LED turn on as long as the button is pressed. | ||
So, at this point, I can say that, for simple GPIO work, the RTK.GPIO board works well for development of RPi programs that access the GPIO pins. Will it work with other sensors and modules designed for the RPi? Well, that’s yet to be seen, since my RTK.GPIO board just came last night. I’ll be spending some of my self-imposed quarantine time working with this new board. I do know from the board website, that there is some question about working with SOME i2c devices, and I haven’t heard anything about the support of SPI devices. So my testing will include both of those along with some other simple modules like relays and trying some other “normal” components. I will keep you advised.** | So, at this point, I can say that, for simple GPIO work, the RTK.GPIO board works well for development of RPi programs that access the GPIO pins. Will it work with other sensors and modules designed for the RPi? Well, that’s yet to be seen, since my RTK.GPIO board just came last night. I’ll be spending some of my self-imposed quarantine time working with this new board. I do know from the board website, that there is some question about working with SOME i2c devices, and I haven’t heard anything about the support of SPI devices. So my testing will include both of those along with some other simple modules like relays and trying some other “normal” components. I will keep you advised.** | ||
+ | |||
+ | Lorsque vous exécuterez le programme, vous verrez la LED s' | ||
+ | |||
+ | Donc, à ce stade, je peux dire que, pour un simple travail sur les GPIO, la carte RTK.GPIO fonctionne bien pour le développement de programmes RPi qui accèdent aux broches GPIO. Est-ce qu' | ||
+ | |||
**I have placed the code on my github repository, as I often do. You can find it at: | **I have placed the code on my github repository, as I often do. You can find it at: | ||
Ligne 88: | Ligne 185: | ||
As always, until next time; stay safe, healthy, positive and creative!** | As always, until next time; stay safe, healthy, positive and creative!** | ||
+ | |||
+ | J'ai mis le code sur mon dépôt github, comme je le fais souvent. Vous pouvez le trouver à l' | ||
+ | https:// | ||
+ | |||
+ | Avec un peu de chance, le mois prochain, je me pencherai sur le RPi Pico, MicroPython et peut-être aussi CircuitPython. Mon Pico devrait arriver le 28 ou le 29 janvier, ainsi que le câble USB micro B qui alimente et communique avec l' | ||
+ | |||
+ | Comme toujours, jusqu' | ||
+ |
issue166/python.1614496268.txt.gz · Dernière modification : 2021/02/28 08:11 de d52fr