issue170:micro-ci_micro-la
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue170:micro-ci_micro-la [2021/06/26 10:08] – créée auntiee | issue170:micro-ci_micro-la [2021/06/30 15:55] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | I want to apologize if this month’s article seems a bit dis-jointed. I’ve been having multiple medical issues the last few weeks, and I REALLY wanted to get this article out to you. | + | **I want to apologize if this month’s article seems a bit dis-jointed. I’ve been having multiple medical issues the last few weeks, and I REALLY wanted to get this article out to you. |
Last month, I told you that we will be looking at the SparkFun Thing Plus ESP-32 WROOM (https:// | Last month, I told you that we will be looking at the SparkFun Thing Plus ESP-32 WROOM (https:// | ||
- | Arduino has finally released their Nano RP2040 Connect which costs about $26 USD. It supports Wi-Fi, Bluetooth, and Bluetooth Low-Energy (v4.2), a built-in microphone for sound or voice activation, an RGB LED, and a six-axis motion sensor. | + | Arduino has finally released their Nano RP2040 Connect which costs about $26 USD. It supports Wi-Fi, Bluetooth, and Bluetooth Low-Energy (v4.2), a built-in microphone for sound or voice activation, an RGB LED, and a six-axis motion sensor. |
- | Seeed Studio has released the Wio RP2040 mini development board which includes 2.4 GHz 802.11b/g/n WiFi 4 supporting AP & station modes, but no Bluetooth support. The estimated price will be about $13 USD and is available only for pre-order at this point. It’s still unclear when the board will start shipping. | + | Je tiens à m' |
- | Finally, there is really big news from Adafruit. I’ll quote the headline from Tom’s Hardware site…”CircuitPython Libraries Slither Into MicroPython on the Raspberry Pi Pico”. That’s right. This is a big thing for the RPi Pico, since eventually the entire CircuitPython library should be available to MicroPython users. Currently, there are many drivers that don’t work, but it’s early days yet. Congratulations to Adafruit for making this move! You can find more about it at https://learn.adafruit.com/circuitpython-libraries-on-micropython-using-the-raspberry-pi-pico | + | Le mois dernier, je vous ai dit que nous allions examiner le SparkFun Thing Plus ESP-32 WROOM (https://www.sparkfun.com/products/ |
- | Sparkfun Thing Plus 32 Wroom | + | Arduino a enfin sorti son Nano RP2040 Connect qui coûte environ 26 dollars US. Il prend en charge les technologies Wi-Fi, Bluetooth et Bluetooth Low-Energy (v4.2) ; il a un microphone intégré pour le son ou l' |
+ | |||
+ | |||
+ | **Seeed Studio has released the Wio RP2040 mini development board which includes 2.4 GHz 802.11b/g/n WiFi 4 supporting AP & station modes, but no Bluetooth support. The estimated price will be about $13 USD and is available only for pre-order at this point. It’s still unclear when the board will start shipping. | ||
+ | |||
+ | Finally, there is really big news from Adafruit. I’ll quote the headline from Tom’s Hardware site…”CircuitPython Libraries Slither Into MicroPython on the Raspberry Pi Pico”. That’s right. This is a big thing for the RPi Pico, since eventually the entire CircuitPython library should be available to MicroPython users. Currently, there are many drivers that don’t work, but it’s early days yet. Congratulations to Adafruit for making this move! You can find more about it at https:// | ||
+ | |||
+ | Seeed Studio a sorti la mini-carte de développement Wio RP2040 qui inclut le WiFi 4 2.4 GHz 802.11b/g/n supportant les modes AP et station, mais sans support du Bluetooth. Le prix est estimé à environ 13 dollars US et elle n'est disponible pour le moment qu'en pré-commande. On ne sait toujours pas quand la carte sera livrée. | ||
+ | |||
+ | Enfin, il y a de très grandes nouvelles en provenance d' | ||
+ | |||
+ | |||
+ | **Sparkfun Thing Plus 32 Wroom | ||
On to the real subject of my article for this month. The SparkFun Thing Plus 32 Wroom is an awesome little microcontroller and easily runs MicroPython. The price of the board is a bit steep, about $21 USD. If the cost is too high for your budget, you can find a similar generic board with the Wroom WiFi chip on the web. I found an Aokin ESP32 Development board from Amazon in a three-pack for just under $17 USD. The pinout and form factor between the two are different, but the same MicroPython firmware works on both. Just be sure to find a pinout for whichever board you choose. In addition, the generic ESP32 Development board might not fit properly on your breadboard. | On to the real subject of my article for this month. The SparkFun Thing Plus 32 Wroom is an awesome little microcontroller and easily runs MicroPython. The price of the board is a bit steep, about $21 USD. If the cost is too high for your budget, you can find a similar generic board with the Wroom WiFi chip on the web. I found an Aokin ESP32 Development board from Amazon in a three-pack for just under $17 USD. The pinout and form factor between the two are different, but the same MicroPython firmware works on both. Just be sure to find a pinout for whichever board you choose. In addition, the generic ESP32 Development board might not fit properly on your breadboard. | ||
Ligne 21: | Ligne 33: | ||
Above is the ESP32 Generic Dev board… | Above is the ESP32 Generic Dev board… | ||
- | Now, let’s get into our projects for this month... | + | Now, let’s get into our projects for this month...** |
+ | |||
+ | Sparkfun Thing Plus 32 Wroom | ||
+ | |||
+ | Venons-en au véritable sujet de mon article de ce mois-ci. Le SparkFun Thing Plus 32 Wroom est un petit microcontrôleur génial qui fait tourner facilement MicroPython. Le prix de la carte est un peu élevé, environ 21 dollars US. Si le prix est trop élevé pour votre budget, vous pouvez trouver une carte générique similaire avec la puce WiFi Wroom sur le Web. J'ai trouvé une carte de développement Aokin ESP32 sur Amazon dans un pack de trois pour un peu moins de 17 dollars US. Le brochage et le format des deux cartes sont différents, | ||
+ | |||
+ | Pour la carte générique, | ||
+ | |||
+ | Les deux cartes prennent en charge le WiFi 2,4 Ghz et le Bluetooth, ainsi que les capteurs tactiles capacitifs, le capteur de Hall (capteur magnétique) et d' | ||
+ | |||
+ | Vous trouverez ci-dessous le brochage de la carte Sparkfun Thing Plus 32 WROOM : | ||
+ | |||
+ | Ci-dessus, la carte de développement générique ESP32. | ||
+ | |||
+ | Maintenant, entrons dans nos projets de ce mois-ci. | ||
- | Project Program #1 - TouchPad | + | **Project Program #1 - TouchPad |
Both the SparkFun Thing Plus and the generic ESP32 development board come with multiple touchpad sensor inputs. For the Thing Plus, there are 8 that are broken out to the external pins. For the Generic that I am using, there are 9 broken out and one that is set to GPIO 0. Just which pins are which input, will be shown on the pinout diagram for your board. When you specify the pin number, be sure to use the GPIO pin number, not the touch number or the physical pin. In this case, we will simply use a male-to-male jumper connected to GPIO pin #27 as our input “pad” denoted as Touch7. The import and setup will be as follows... | Both the SparkFun Thing Plus and the generic ESP32 development board come with multiple touchpad sensor inputs. For the Thing Plus, there are 8 that are broken out to the external pins. For the Generic that I am using, there are 9 broken out and one that is set to GPIO 0. Just which pins are which input, will be shown on the pinout diagram for your board. When you specify the pin number, be sure to use the GPIO pin number, not the touch number or the physical pin. In this case, we will simply use a male-to-male jumper connected to GPIO pin #27 as our input “pad” denoted as Touch7. The import and setup will be as follows... | ||
+ | |||
+ | import machine | ||
+ | |||
+ | import utime | ||
+ | |||
+ | touch7 = machine.TouchPad(machine.Pin(27))** | ||
+ | |||
+ | Programme du projet n° 1 - Pavé tactile | ||
+ | |||
+ | Le SparkFun Thing Plus et la carte de développement générique ESP32 sont tous deux dotés de plusieurs entrées de capteur de pavé tactile. Pour le Thing Plus, il y en a 8 qui sont réparties sur les broches externes. Pour le Generic que j' | ||
import machine | import machine | ||
Ligne 33: | Ligne 70: | ||
touch7 = machine.TouchPad(machine.Pin(27)) | touch7 = machine.TouchPad(machine.Pin(27)) | ||
- | Now (top right), we’ll create a variable called lowvalue and initialize it to 1000. When running, the touch pad actually floats between 700 and 600. Then we start a “forever loop”. We’ll read the value of the touch pin and compare that with the last recorded lowvalue figure. If the current touchvalue is lower than the last lowvalue, we set lowvalue to the touchvalue. We also print the lowvalue at this point. Finally we sleep for 100 milliseconds and loop again. We can use the {Stop} button in Thonny to quit the program. | + | |
+ | **Now (top right), we’ll create a variable called lowvalue and initialize it to 1000. When running, the touch pad actually floats between 700 and 600. Then we start a “forever loop”. We’ll read the value of the touch pin and compare that with the last recorded lowvalue figure. If the current touchvalue is lower than the last lowvalue, we set lowvalue to the touchvalue. We also print the lowvalue at this point. Finally we sleep for 100 milliseconds and loop again. We can use the {Stop} button in Thonny to quit the program. | ||
Here is what the printout looks like. It takes about 1 ½ to 2 seconds to get to the lowest value. | Here is what the printout looks like. It takes about 1 ½ to 2 seconds to get to the lowest value. | ||
Ligne 54: | Ligne 92: | ||
LowValue = 87 | LowValue = 87 | ||
- | Now (below), we can modify the program a little bit to allow the program to self terminate… | + | Now (below), we can modify the program a little bit to allow the program to self terminate…** |
- | Notice that we haven’t changed it that much. We just added an assignment to a variable called loopit, changed the while statement to “while loopit:” instead of “while True:”, and then check to see if the lowvalue is less than 90 as a “trigger”. If it is, then we set the loopit value to False to make the loop fail. | + | Maintenant (en haut à droite), nous allons créer une variable appelée lowvalue et l' |
+ | |||
+ | Voici à quoi ressemble l' | ||
+ | |||
+ | LowValue = 677 | ||
+ | LowValue = 671 | ||
+ | LowValue = 667 | ||
+ | LowValue = 658 | ||
+ | LowValue = 616 | ||
+ | LowValue = 456 | ||
+ | LowValue = 390 | ||
+ | LowValue = 347 | ||
+ | LowValue = 227 | ||
+ | LowValue = 128 | ||
+ | LowValue = 107 | ||
+ | LowValue = 100 | ||
+ | LowValue = 94 | ||
+ | LowValue = 92 | ||
+ | LowValue = 88 | ||
+ | LowValue = 87 | ||
+ | |||
+ | À présent (ci-dessous), | ||
+ | |||
+ | |||
+ | **Notice that we haven’t changed it that much. We just added an assignment to a variable called loopit, changed the while statement to “while loopit:” instead of “while True:”, and then check to see if the lowvalue is less than 90 as a “trigger”. If it is, then we set the loopit value to False to make the loop fail. | ||
I have to hold and gently squeeze the male jumper to get the value to go low enough to trigger the exit. | I have to hold and gently squeeze the male jumper to get the value to go low enough to trigger the exit. | ||
Ligne 71: | Ligne 133: | ||
- | passwd = ' | + | passwd = ' |
- | Now (top right) we’ll create the function to do the actual communications with the router (essid). We set the network object (wlan) to station mode, which is like a “normal” computer on the network. You could also set it up as an access point. Next, we set the network object to active and then try to connect. Once we have connected, we print out the network information (ip address, etc). The final line calls the connection function. | + | Remarquez que nous ne l' |
+ | |||
+ | Je dois tenir et presser doucement le cavalier mâle pour que la valeur soit suffisamment basse pour déclencher la sortie. | ||
+ | |||
+ | Programme du projet n° 2 - Programmation du réseau | ||
+ | |||
+ | Ceci est un exemple simple de la façon de se connecter à votre routeur local. Tout ce qu'il fait réellement est de se connecter au routeur avec votre mot de passe, obtenir une adresse IP et l' | ||
+ | |||
+ | Tout d' | ||
+ | |||
+ | import network | ||
+ | |||
+ | essid = 'Votre RouteurRéseau' | ||
+ | |||
+ | |||
+ | passwd = 'Votre mot de passe réseau' | ||
+ | |||
+ | |||
+ | **Now (top right) we’ll create the function to do the actual communications with the router (essid). We set the network object (wlan) to station mode, which is like a “normal” computer on the network. You could also set it up as an access point. Next, we set the network object to active and then try to connect. Once we have connected, we print out the network information (ip address, etc). The final line calls the connection function. | ||
As I said, this is a very simple example that really does nothing other than connect to the local router and return an IP address. Using sockets will be covered in a future article. | As I said, this is a very simple example that really does nothing other than connect to the local router and return an IP address. Using sockets will be covered in a future article. | ||
Ligne 79: | Ligne 159: | ||
Project Program #3 - Web Server and DHT-11/22 | Project Program #3 - Web Server and DHT-11/22 | ||
- | Our final project for this month involves using the ESP32/ | + | Our final project for this month involves using the ESP32/ |
- | The entire project is described in detail at: https:// | + | Maintenant (en haut à droite), nous allons créer la fonction pour effectuer les communications réelles avec le routeur (essid). Nous définissons l' |
+ | |||
+ | Comme je l'ai dit, il s'agit d'un exemple très simple qui ne fait rien d' | ||
+ | |||
+ | Programme du projet #3 - Serveur Web et DHT-11/22 | ||
+ | |||
+ | Notre projet final pour ce mois-ci implique l' | ||
+ | |||
+ | |||
+ | **The entire project is described in detail at: https:// | ||
This project uses the PicoWeb library which can be found at https:// | This project uses the PicoWeb library which can be found at https:// | ||
Ligne 97: | Ligne 186: | ||
upip.install(' | upip.install(' | ||
- | You can find out more about upip at: https:// | + | You can find out more about upip at: https:// |
- | There is the code, diagrams and step-by-step projects leading up to the full webserver project. The code for the webserver project is pretty long and includes both the python file and the index.html file that displays the web information. I won’t duplicate it here, but I will point out a few changes that I had to make to get the project to work the way that I wanted it to. | + | L' |
+ | |||
+ | Ce projet utilise la bibliothèque PicoWeb qui se trouve à l' | ||
+ | |||
+ | Bien entendu, vous devez ajouter Picoweb et ses dépendances. Vous pouvez essayer de suivre les instructions dans le lien pour le projet lui-même, ou vous pouvez utiliser upip dans le REPL de Thonny. Vous devrez installer micropython-pkg_resources, | ||
+ | |||
+ | import upip | ||
+ | |||
+ | upip.install(' | ||
+ | |||
+ | upip.install(' | ||
+ | |||
+ | upip.install(' | ||
+ | |||
+ | upip.install(' | ||
+ | |||
+ | Vous pouvez trouver plus d' | ||
+ | |||
+ | |||
+ | **There is the code, diagrams and step-by-step projects leading up to the full webserver project. The code for the webserver project is pretty long and includes both the python file and the index.html file that displays the web information. I won’t duplicate it here, but I will point out a few changes that I had to make to get the project to work the way that I wanted it to. | ||
I saved the main code to a file named ESP32-DHT-Touch-Picoweb.py | I saved the main code to a file named ESP32-DHT-Touch-Picoweb.py | ||
Ligne 109: | Ligne 217: | ||
Line 33 (in my code) needs to be modified to support your network. | Line 33 (in my code) needs to be modified to support your network. | ||
- | sta_if.connect(' | + | sta_if.connect(' |
+ | |||
+ | Il y a le code, les diagrammes et les projets, étape par étape, menant au projet complet de serveur Web. Le code du projet de serveur Web est assez long et comprend à la fois le fichier python et le fichier index.html qui affiche les informations Web. Je ne vais pas le reproduire ici, mais je vais signaler quelques changements que j'ai dû faire pour que le projet fonctionne comme je le voulais. | ||
+ | |||
+ | J'ai enregistré le code principal dans un fichier nommé ESP32-DHT-Touch-Picoweb.py. | ||
+ | |||
+ | Les lignes 18, 19 et 20 définissent les broches pour les LEDs. J'ai décidé de n' | ||
+ | r_led = machine.Pin(2, | ||
+ | |||
+ | Et j'ai laissé les lignes 19 et 20 telles quelles. | ||
+ | |||
+ | La ligne 33 (dans mon code) doit être modifiée pour supporter votre réseau. | ||
+ | sta_if.connect(' | ||
- | Line 58 defines the callback for the touchpad timer interrupt handler. I modified lines 62, 70 and 78. They each are an if statement testing the touchpad.read() value to be less than 100. Since I’m just using just wires, not true copper pads, the earlier tests showed that I can achieve a value of under 100, but it takes a number of seconds for it to get that low. So, I changed the test value to less than 200 for all three values. It still takes around 2 ½ seconds to 3 seconds and a fairly tight squeeze to get it to trigger, but it does. So line 62 was changed to: | + | **Line 58 defines the callback for the touchpad timer interrupt handler. I modified lines 62, 70 and 78. They each are an if statement testing the touchpad.read() value to be less than 100. Since I’m just using just wires, not true copper pads, the earlier tests showed that I can achieve a value of under 100, but it takes a number of seconds for it to get that low. So, I changed the test value to less than 200 for all three values. It still takes around 2 ½ seconds to 3 seconds and a fairly tight squeeze to get it to trigger, but it does. So line 62 was changed to: |
if t7 < 200: | if t7 < 200: | ||
Ligne 121: | Ligne 242: | ||
Lines 87, 89 and 90 (my code) reference the DHT11 sensor. Since I’m using a DHT22, I had to change the three instances from DHT11 to DHT22. | Lines 87, 89 and 90 (my code) reference the DHT11 sensor. Since I’m using a DHT22, I had to change the three instances from DHT11 to DHT22. | ||
+ | |||
+ | d = dht.DHT22(machine.Pin(23)) | ||
+ | |||
+ | dht22_timer = machine.Timer(0) | ||
+ | |||
+ | dht22_timer.init(period=1000, | ||
+ | |||
+ | La ligne 58 définit le callback pour le gestionnaire d' | ||
+ | if t7 < 200 : | ||
+ | |||
+ | La ligne 70 a été changée en : | ||
+ | if t8 < 200 : | ||
+ | |||
+ | Et la ligne 78 a été changée en : | ||
+ | if t9 < 200 : | ||
+ | |||
+ | Les lignes 87, 89 et 90 (mon code) font référence au capteur DHT11. Comme j' | ||
d = dht.DHT22(machine.Pin(23)) | d = dht.DHT22(machine.Pin(23)) | ||
Ligne 128: | Ligne 266: | ||
dht22_timer.init(period=1000, | dht22_timer.init(period=1000, | ||
- | Also, in the index.html file I made a change to make the temperature and humidity display text smaller. Around line 45, you will find the code: | + | |
+ | **Also, in the index.html file I made a change to make the temperature and humidity display text smaller. Around line 45, you will find the code: | ||
| | ||
Ligne 148: | Ligne 287: | ||
Next time, we’ll take a look at NeoPixel devices and how to program them using the ESP-32 and the RPI Pico. | Next time, we’ll take a look at NeoPixel devices and how to program them using the ESP-32 and the RPI Pico. | ||
- | Until then, as always; stay safe, healthy, positive and creative! | + | Until then, as always; stay safe, healthy, positive and creative!** |
+ | |||
+ | De plus, dans le fichier index.html, j'ai fait une modification pour rendre le texte d' | ||
+ | |||
+ | | ||
+ | font-size : 160px ; | ||
+ | color : #999 ; | ||
+ | } | ||
+ | |||
+ | J'ai trouvé que la taille de la police était beaucoup trop grande pour moi. Je l'ai changée en : | ||
+ | |||
+ | .table-value { | ||
+ | font-size : 60px ; | ||
+ | color : #999 ; | ||
+ | } | ||
+ | |||
+ | ce qui fonctionne beaucoup mieux, du moins pour moi. Vous pouvez faire ce changement si vous le souhaitez. | ||
+ | |||
+ | Mon code peut être trouvé sur mon dépôt github à l' | ||
+ | |||
+ | La prochaine fois, nous verrons les dispositifs NeoPixel et comment les programmer en utilisant l' | ||
+ | |||
+ | D'ici là, comme toujours, restez en sécurité, en bonne santé, positifs et créatifs ! | ||
issue170/micro-ci_micro-la.1624694904.txt.gz · Dernière modification : 2021/06/26 10:08 de auntiee