Ligne 95 : |
Ligne 95 : |
| == Code == | | == Code == |
| === BUS I2C === | | === BUS I2C === |
− | La carte MOD-IO utilise le bus I2C (adresse par défaut est 0x21) pour communiquer avec le MicroContrôleur. | + | La carte MOD-IO2 utilise le bus I2C (adresse par défaut est 0x21) pour communiquer avec le MicroContrôleur. |
| | | |
| Ce bus I2C est disponible sur le connecteur UEXT de notre ESP8266-EVB comme le montre le tableau suivant. | | Ce bus I2C est disponible sur le connecteur UEXT de notre ESP8266-EVB comme le montre le tableau suivant. |
Ligne 101 : |
Ligne 101 : |
| [[Fichier:ESP8266-DEV-12.jpg|480px]] | | [[Fichier:ESP8266-DEV-12.jpg|480px]] |
| | | |
− | En adaptant le code (et les raccordements du bus I2C), vous pourriez tout aussi facilement faire fonctionner des cartes ESP8266 comme {{pl|67|Feather ESP8266 Huzza}} ou {{cl|121|Wemos D1}}. | + | En adaptant le code (et les raccordements du bus I2C), vous pourriez tout aussi facilement faire fonctionner des cartes ESP8266 comme {{pl|67|Feather ESP8266 Huzza}} ou {{cl|121|Wemos D1}} ou même {{pl|570|MicroPython Pyboard}} |
| | | |
| === Fonctions GPIOs du MOD-IO2 === | | === Fonctions GPIOs du MOD-IO2 === |
Ligne 188 : |
Ligne 188 : |
| print( "That's the end folks") | | print( "That's the end folks") |
| </syntaxhighlight> | | </syntaxhighlight> |
− |
| |
− |
| |
− |
| |
| | | |
| === Exemple PWM === | | === Exemple PWM === |
Ligne 205 : |
Ligne 202 : |
| | | |
| <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
− | # Modifier l'adresse de MOD-IO2 d'Olimex vers 0x22 | + | # Test PWM sur le MOD-IO2 d'Olimex avec un ESP8266 sous MicroPython |
| # | | # |
− | # Shop: http://shop.mchobby.be/product.php?id_product=1408 | + | # Shop: http://shop.mchobby.be/product.php?id_product=1409 |
| # GitHub: https://github.com/mchobby/esp8266-upy/tree/master/modio2 | | # GitHub: https://github.com/mchobby/esp8266-upy/tree/master/modio2 |
| | | |
| from machine import I2C, Pin | | from machine import I2C, Pin |
| + | from time import sleep_ms |
| from modio2 import MODIO2 | | from modio2 import MODIO2 |
| | | |
| i2c = I2C( sda=Pin(2), scl=Pin(4) ) | | i2c = I2C( sda=Pin(2), scl=Pin(4) ) |
− | brd = MODIO2( i2c, addr=0x1 ) | + | brd = MODIO2( i2c ) # Adresse par défaut=0x21 |
− | brd.change_address( 0x22 ) | + | |
| + | print( "GPIO 5 - IN") |
| + | brd.gpios.pin_mode( 5, Pin.IN ) |
| + | |
| + | print( "GPIO 6 - PWM" ) |
| + | brd.gpios.pwm( gpio=6, cycle=0 ) |
| + | |
| + | cycle=0 |
| + | while cycle<255: |
| + | val = brd.gpios.analog( 5, raw = True ) |
| + | cycle = val // 4 # de 0..1023 a 0..254 |
| + | if cycle >= 254: # Assure 100% du cycle utile |
| + | cycle = 255 |
| + | brd.gpios.pwm( 6, cycle ) |
| + | print( "val=%s -> cycle=%s" %(val,cycle) ) |
| + | sleep_ms( 1000 ) |
| + | |
| + | print( "That's the end folks") |
| + | </syntaxhighlight> |
| + | |
| + | Ce qui affiche le résultat suivant à l'écran pendant que l'on exécute le script: |
| + | <syntaxhighlight lang="python"> |
| + | MicroPython v1.9.4-8-ga9a3caad0 on 2018-05-11; ESP module with ESP8266 |
| + | Type "help()" for more information. |
| + | >>> |
| + | >>> import test2pwm |
| + | GPIO 5 - IN |
| + | GPIO 6 - PWM |
| + | val=698 -> cycle=174 |
| + | val=698 -> cycle=174 |
| + | val=620 -> cycle=155 |
| + | val=614 -> cycle=153 |
| + | val=597 -> cycle=149 |
| + | val=496 -> cycle=124 |
| + | val=494 -> cycle=123 |
| + | val=701 -> cycle=175 |
| + | val=880 -> cycle=220 |
| + | val=978 -> cycle=244 |
| + | val=979 -> cycle=244 |
| + | val=982 -> cycle=245 |
| + | val=1023 -> cycle=255 |
| + | That's the end folks |
| + | >>> |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
Ligne 235 : |
Ligne 275 : |
| | | |
| i2c = I2C( sda=Pin(2), scl=Pin(4) ) | | i2c = I2C( sda=Pin(2), scl=Pin(4) ) |
− | brd = MODIO2( i2c, addr=0x1 ) | + | brd = MODIO2( i2c, addr=0x21 ) |
| brd.change_address( 0x22 ) | | brd.change_address( 0x22 ) |
| </syntaxhighlight> | | </syntaxhighlight> |