issue186:micro-ci
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue186:micro-ci [2022/10/29 10:19] – créée auntiee | issue186:micro-ci [2022/11/03 12:03] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | It’s been a while since I’ve been able to write a ‘Micro This Micro That’ article. I apologize that it’s been so long. Too many things have been in my way, but at least for this month, I can provide you with something. | + | **It’s been a while since I’ve been able to write a ‘Micro This Micro That’ article. I apologize that it’s been so long. Too many things have been in my way, but at least for this month, I can provide you with something. |
I also know that I had promised a long time ago that we would complete the compass app and I still intend to do that, but so much has changed in the Microcontroller world, I felt that I needed to discuss some of the new things. With any luck, the next ‘Micro This Micro That’ article will finish that. | I also know that I had promised a long time ago that we would complete the compass app and I still intend to do that, but so much has changed in the Microcontroller world, I felt that I needed to discuss some of the new things. With any luck, the next ‘Micro This Micro That’ article will finish that. | ||
- | For this month, we’ll be discussing the new Raspberry Pi Pico board, the Pico-W. You can find out a good bit of information from https:// | + | For this month, we’ll be discussing the new Raspberry Pi Pico board, the Pico-W. You can find out a good bit of information from https:// |
- | You can see that the pinout is pretty much the same as the original Pico, so, for the most part, you can use the software you’ve already developed, but you need to get the latest MicroPython version that is designed to support the Pico-W. You can get that from the website above or from the MicroPython.org site. The process of flashing the board is the same as the original board, so I won’t bore you with that. | + | Cela fait un moment que je n'ai pas pu écrire un article dans la rubrique « Micro-ci micro-là ». Je m' |
+ | |||
+ | Je sais aussi que j' | ||
+ | |||
+ | Ce mois-ci, nous allons parler de la nouvelle carte Raspberry Pi Pico, la Pico-W. Vous pouvez trouver un bon nombre d' | ||
+ | |||
+ | |||
+ | **You can see that the pinout is pretty much the same as the original Pico, so, for the most part, you can use the software you’ve already developed, but you need to get the latest MicroPython version that is designed to support the Pico-W. You can get that from the website above or from the MicroPython.org site. The process of flashing the board is the same as the original board, so I won’t bore you with that. | ||
One of the new things that the Pico-W brings to the table is that the onboard LED pin is not connected to a GPIO pin on the board, but is connected to a GPIO pin on the wireless module (and the MicroPython version has been modified to handle it). So it makes it much easier to access it in your code. Here is a quick demo program that shows how to do it. | One of the new things that the Pico-W brings to the table is that the onboard LED pin is not connected to a GPIO pin on the board, but is connected to a GPIO pin on the wireless module (and the MicroPython version has been modified to handle it). So it makes it much easier to access it in your code. Here is a quick demo program that shows how to do it. | ||
Ligne 13: | Ligne 20: | ||
import time | import time | ||
+ | led=machine.Pin(" | ||
+ | |||
+ | led.on() | ||
+ | |||
+ | time.sleep(3) | ||
+ | |||
+ | led.off()** | ||
+ | |||
+ | Vous pouvez voir que le brochage est à peu près le même que celui de la Pico originale ; ainsi, dans l' | ||
+ | |||
+ | L'une des nouveautés du Pico-W est que le contact de la LED intégrée n'est pas connecté à un picot GPIO de la carte, mais à une broche GPIO du module sans fil (et la version de MicroPython a été modifiée pour le gérer). Il est donc beaucoup plus facile d'y accéder dans votre code. Voici un programme de démonstration rapide qui montre comment faire : | ||
+ | |||
+ | import machine | ||
+ | |||
+ | import time | ||
led=machine.Pin(" | led=machine.Pin(" | ||
Ligne 21: | Ligne 43: | ||
led.off() | led.off() | ||
+ | |||
- | As you can see, it is very simple. We define the led object, then we simply call the led.on() and led.off methods to turn on and off the led. You can use this to provide a visual indication that you have a wireless connection. | + | **As you can see, it is very simple. We define the led object, then we simply call the led.on() and led.off methods to turn on and off the led. You can use this to provide a visual indication that you have a wireless connection. |
Since the pinout of the Pico-W is pretty much the same as the original, we can use our original i2cscan program to probe the i2c bus and provide the address of all the i2c devices attached to our Pico-W (shown previous page, top right). | Since the pinout of the Pico-W is pretty much the same as the original, we can use our original i2cscan program to probe the i2c bus and provide the address of all the i2c devices attached to our Pico-W (shown previous page, top right). | ||
Ligne 34: | Ligne 57: | ||
Address 0x19 is the lsm303 accelerator and 0x1e is the lsm303 magnetometer. Address 0x40 is the SI7021 temperature/ | Address 0x19 is the lsm303 accelerator and 0x1e is the lsm303 magnetometer. Address 0x40 is the SI7021 temperature/ | ||
- | Since there are now three RPi Pico boards, how can you tell which device you are working with (other than looking at it)? | + | Since there are now three RPi Pico boards, how can you tell which device you are working with (other than looking at it)?** |
- | The micropython versions for the Pico boards now support a sys method named implementation (shown top right). Of course you have to import the sys module first. I threw together a simple program that shows how to access the information. | + | Comme vous pouvez le voir, c'est très simple. Nous définissons l' |
+ | |||
+ | Puisque le brochage de la Pico-W est à peu près le même que celui de l' | ||
+ | |||
+ | Comme je le fais habituellement, | ||
+ | |||
+ | 0x19 25 | ||
+ | 0x1e 30 | ||
+ | 0x40 64 | ||
+ | |||
+ | L' | ||
+ | |||
+ | Puisqu' | ||
+ | |||
+ | |||
+ | **The micropython versions for the Pico boards now support a sys method named implementation (shown top right). Of course you have to import the sys module first. I threw together a simple program that shows how to access the information. | ||
When you run the program, here’s what it returns. | When you run the program, here’s what it returns. | ||
Ligne 52: | Ligne 90: | ||
Now, let’s look at how to work with the wireless portion of the Pico-W. It is very similar to what we’ve done with the ESP-32 and the ESP-8266 microcontrollers. | Now, let’s look at how to work with the wireless portion of the Pico-W. It is very similar to what we’ve done with the ESP-32 and the ESP-8266 microcontrollers. | ||
- | As a minimum, you need to import the network, time and a special file named secret.py. | + | As a minimum, you need to import the network, time and a special file named secret.py.** |
- | Secret.py contains | + | Les versions de Micropython pour les cartes Pico supportent maintenant dans sys une méthode nommée implementation (montrée en haut à droite). Bien sûr, vous devez d' |
+ | |||
+ | Lorsque vous exécutez le programme, voici ce qu'il retourne : | ||
+ | |||
+ | (name=' | ||
+ | Raspberry Pi Pico W with RP2040 | ||
+ | Pico with Wireless | ||
+ | |||
+ | Ainsi, which1 renvoie un tuple qui contient le fait que nous utilisons Micropython, | ||
+ | |||
+ | Tout cela peut se résumer à une simple fonction (en bas à droite). | ||
+ | |||
+ | Et on obtient un True. J'ai enregistré cette fonction sous le nom de WhichPico2.py. | ||
+ | |||
+ | Maintenant, regardons comment travailler avec la partie sans fil du Pico-W. C'est très similaire à ce que nous avons fait avec les microcontrôleurs ESP-32 et ESP-8266. | ||
+ | |||
+ | Au minimum, vous devez importer le réseau, l' | ||
+ | |||
+ | |||
+ | **Secret.py contains | ||
# secret.py | # secret.py | ||
Ligne 68: | Ligne 125: | ||
Here is the output from the program | Here is the output from the program | ||
+ | |||
+ | 3 | ||
+ | |||
+ | (' | ||
+ | |||
+ | Secret.py contient | ||
+ | |||
+ | # secret.py | ||
+ | # ============= | ||
+ | SSID = "" | ||
+ | PASSWORD = "" | ||
+ | |||
+ | De cette façon, vous pouvez garder secrets le point d' | ||
+ | |||
+ | Une fois la section des importations terminée, il ne vous reste plus qu'à ajouter le code suivant (page précédente, | ||
+ | |||
+ | Nous créons l' | ||
+ | |||
+ | Voici le résultat du programme : | ||
3 | 3 | ||
Ligne 73: | Ligne 149: | ||
(' | (' | ||
- | The status value of 3 means that we are properly connected to the wireless network. The ifconfig information is (from left to right) IP address, netmask, gateway, DNS. Here are all the possible values for the status method. | ||
- | // Return value of cyw43_wifi_link_status | + | **The status value of 3 means that we are properly connected to the wireless network. The ifconfig information is (from left to right) IP address, netmask, gateway, DNS. Here are all the possible values for the status method. |
+ | |||
+ | < | ||
#define CYW43_LINK_DOWN (0) | #define CYW43_LINK_DOWN (0) | ||
#define CYW43_LINK_JOIN (1) | #define CYW43_LINK_JOIN (1) | ||
Ligne 92: | Ligne 169: | ||
import sys | import sys | ||
- | Check that the board is a Pico-W with wireless support (previous page, top right). | + | Check that the board is a Pico-W with wireless support (previous page, top right). |
- | First, set up the led object and turn off the led (just in case). Next, set up all the things we need to do for the wireless support, including getting the SSID and PASSWORD from the secret.py file, and call the wlan.connect with these values (previous page, bottom right). | + | La valeur d' |
+ | |||
+ | < | ||
+ | #define CYW43_LINK_DOWN (0) | ||
+ | #define CYW43_LINK_JOIN (1) | ||
+ | #define CYW43_LINK_NOIP (2) | ||
+ | #define CYW43_LINK_UP (3) | ||
+ | #define CYW43_LINK_FAIL (-1) | ||
+ | #define CYW43_LINK_NONET (-2) | ||
+ | #define CYW43_LINK_BADAUTH (-3) | ||
+ | |||
+ | J'ai créé un programme simple qui regroupe tous les programmes de test que nous avons utilisés en un seul. Je l'ai nommé net1a.py. J'ai changé la plupart des commentaires en lignes d' | ||
+ | |||
+ | import machine | ||
+ | import network | ||
+ | import time | ||
+ | import secret | ||
+ | import sys | ||
+ | |||
+ | Vérifiez que la carte est une Pico-W avec support sans-fil (page précédente, | ||
+ | |||
+ | |||
+ | **First, set up the led object and turn off the led (just in case). Next, set up all the things we need to do for the wireless support, including getting the SSID and PASSWORD from the secret.py file, and call the wlan.connect with these values (previous page, bottom right). | ||
In the event the board is NOT a Pico-W, print that we can’t deal with wireless on this board and end the program (top right). | In the event the board is NOT a Pico-W, print that we can’t deal with wireless on this board and end the program (top right). | ||
Ligne 102: | Ligne 201: | ||
I’ve set up a github repository for the code that we’ve used this month. You can find it at https:// | I’ve set up a github repository for the code that we’ve used this month. You can find it at https:// | ||
- | Until next time, as always; stay safe, healthy, positive and creative! | + | Until next time, as always; stay safe, healthy, positive and creative!** |
+ | |||
+ | Tout d' | ||
+ | |||
+ | Dans le cas où la carte n'est pas une Pico-W, indiquez que nous ne pouvons pas gérer le sans-fil sur cette carte et terminez le programme (en haut à droite). | ||
+ | |||
+ | Voilà donc en quelques mots comment utiliser le réseau de la RPi Pico-W. Le site que j'ai mentionné précédemment contient un très bon PDF sur l' | ||
+ | |||
+ | J'ai mis en place un dépôt github pour le code que nous avons utilisé ce mois-ci. Vous pouvez le trouver à https:// | ||
+ | |||
+ | Jusqu' | ||
+ | |||
+ | // Dans les encadrés : // | ||
+ | //p 35, en haut :// | ||
+ | **If the board actually is a Pico-W, we can try to connect to the wireless network: | ||
+ | Si la carte est vraiment une Pico-W, nous pouvons essayer de nous connecter au résau sans fil : | ||
+ | |||
+ | //p 53, en bas :// | ||
+ | **Now loop until we get connected: | ||
+ | Maintenant, boucler jusqu' | ||
+ | |||
+ | **Print the status value and the ifconfig values, and turn the onboard LED on:** | ||
+ | Imprimer la valeur d' | ||
+ | |||
+ | //p 36 : // | ||
+ | **When the program runs (assuming it is a Pico-W board), here is the output from my machine.** | ||
+ | Quand le programme tourne (en supposant que c'est une carte Pico-W), voici la sortie de ma machine. |
issue186/micro-ci.1667031569.txt.gz · Dernière modification : 2022/10/29 10:19 de auntiee