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:54] – 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 |
- | ==== Programme en python ==== | ||
- | <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 | ||
- | addr = 0x8 # bus address | + | == Installer le module smsbus python3 == |
- | bus = SMBus(1) # indicates /dev/ic2-1 | + | |
- | numb = 1 | + | sudo apt-get install |
- | print ("Enter 1 for ON or 0 for OFF") | + | faire : |
+ | sudo pip list ( pour verifier l' | ||
+ | ==== Programme en python sur RPI ==== | ||
+ | |||
+ | <code python exemple010.py> | ||
+ | from smbus import SMBus | ||
+ | |||
+ | addr = 0x55 # L' | ||
+ | bus = SMBus(1) # indique le repertoire /dev/ic2-1 | ||
+ | |||
+ | numb = 1 | ||
+ | |||
+ | print (" | ||
+ | |||
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.1740934495.txt.gz · Dernière modification : 2025/03/02 17:54 de admin