start:raspberry:i2c
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 | ||
| start:raspberry:i2c [2025/03/02 17:59] – [Programme en python] admin | start:raspberry:i2c [2025/03/02 18:34] (Version actuelle) – [Installer le module smsbus python3] admin | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ======== I2C raspberry ======== | + | ======== I2C raspberry |
| Ligne 7: | Ligne 7: | ||
| sudo apt-get install | sudo apt-get install | ||
| - | faire : sudo pip list ( pour verifier l' | + | faire : |
| + | sudo pip list ( pour verifier l' | ||
| - | ==== Programme en python ==== | + | ==== Programme en python |
| <code python exemple010.py> | <code python exemple010.py> | ||
| - | # Raspberry Pi Master for Arduino Slave | ||
| - | # i2c_master_pi.py | ||
| - | # Connects to Arduino via I2C | ||
| - | # DroneBot Workshop 2019 | ||
| - | # https:// | ||
| from smbus import SMBus | from smbus import SMBus | ||
| - | + | ||
| - | addr = 0x8 # bus address | + | addr = 0x55 # L' |
| - | bus = SMBus(1) # indicates | + | bus = SMBus(1) # indique le repertoire |
| + | |||
| numb = 1 | numb = 1 | ||
| - | + | ||
| - | print ("Enter 1 for ON or 0 for OFF" | + | print ("taper 1 pour ON ou 0 pour |
| + | |||
| while numb == 1: | while numb == 1: | ||
| ledstate = input(">>>>" | ledstate = input(">>>>" | ||
| - | if ledstate == " | + | if ledstate == " |
| - | bus.write_byte(addr, | + | bus.write_byte(addr, |
| - | elif ledstate == " | + | elif ledstate == " |
| - | bus.write_byte(addr, | + | bus.write_byte(addr, |
| else: | else: | ||
| numb = 0 | numb = 0 | ||
| - | | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ==== Programme | ||
| + | |||
| + | <code c exemple012.ino> | ||
| + | /*Arduino Slave for Raspberry Pi Master | ||
| + | i2c_slave_ard.ino | ||
| + | Connects to Raspberry Pi via I2C | ||
| + | | ||
| + | DroneBot Workshop 2019 | ||
| + | https:// | ||
| + | */ | ||
| + | |||
| + | // Include the Wire library for I2C | ||
| + | #include < | ||
| + | |||
| + | // LED on pin 12 | ||
| + | const int ledPin = 12; | ||
| + | |||
| + | void setup() { | ||
| + | // Configure | ||
| + | Wire.begin(0x55); | ||
| + | | ||
| + | // Recoit les données du bus I2C | ||
| + | Wire.onReceive(receiveEvent); | ||
| + | | ||
| + | // Active la LED 13 sur GPIO 12 et l ' | ||
| + | pinMode(ledPin, | ||
| + | digitalWrite(ledPin, | ||
| + | } | ||
| + | |||
| + | |||
| + | void receiveEvent(int howMany) { | ||
| + | while (Wire.available()) { // boucle tant que l on recoit des caractéres sur le bus I2C | ||
| + | char c = Wire.read(); | ||
| + | digitalWrite(ledPin, | ||
| + | } | ||
| + | } | ||
| + | void loop() { | ||
| + | delay(100); | ||
| + | } | ||
| + | </ | ||
/home/chanteri/www/fablab37110/data/attic/start/raspberry/i2c.1740934787.txt.gz · Dernière modification : de admin
