Ligne 54 : |
Ligne 54 : |
| Wire.write(0xAA); // send 0xAA | | Wire.write(0xAA); // send 0xAA |
| }</nowiki> | | }</nowiki> |
| + | |
| + | == Préparé votre Pi == |
| + | |
| + | Activate I2C: |
| + | |
| + | <nowiki>$ sudo modprobe i2c_bcm2708 baudrate=100000 |
| + | $ sudo modprobe i2c-dev</nowiki> |
| + | |
| + | Install i2c-tools and python-smbus: |
| + | |
| + | <nowiki>$ sudo apt-get update |
| + | $ sudo apt-get install i2c-tools |
| + | $ sudo apt-get install python-smbus</nowiki> |
| + | |
| + | Test I2C bus: |
| + | |
| + | $ sudo i2cdetect -y 1 |
| + | |
| + | The Raspberry Pi hardware revision 1 boards connect I2C bus 0 (GPIO 0 + 1) and revision 2 boards connect I2C bus 1 (GPIO 2 + 3) to the GPIO connector. |
| + | |
| + | Note: As default the reset pin of the Arduino is connected to GPIO18 (Pin 12) of the Raspberry Pi (GPIO18 high = reset on, GPIO18 low = reset off). |
| + | |
| + | To disable the reset: |
| + | |
| + | <nowiki>$ sudo -i |
| + | $ echo 18 > /sys/class/gpio/export |
| + | $ echo out > /sys/class/gpio/gpio18/direction |
| + | $ echo 0 > /sys/class/gpio/gpio18/value |
| + | $ exit</nowiki> |
| + | |
| + | Or if you have installed WiringPi (voir [[Pi-WiringPi|notre tutoriel WiringPi]]): |
| + | |
| + | <nowiki>gpio -g mode 18 out |
| + | gpio -g write 18 1</nowiki> |
| + | |
| + | == Tester == |
| + | |
| + | === Commande Shell === |
| + | |
| + | Switch on LED: |
| + | |
| + | $ sudo i2cset -y 1 0x30 0x01 |
| + | |
| + | Switch off LED: |
| + | |
| + | $ sudo i2cset -y 1 0x30 0x00 |
| + | |
| + | === Python === |
| + | Create a test script named i2ctest.py: |
| + | |
| + | $ nano i2ctest.py |
| + | |
| + | Et copiez y le code suivant: |
| + | |
| + | <nowiki>#!/usr/bin/env python |
| + | # -*- coding: latin-1 -*- |
| + | |
| + | import time |
| + | import smbus |
| + | bus = smbus.SMBus(1) |
| + | addr = 0x30 |
| + | |
| + | while True: |
| + | bus.write_byte(addr, 0x01) |
| + | print "on" |
| + | time.sleep(1) |
| + | bus.write_byte(addr, 0x00) |
| + | print "off" |
| + | time.sleep(1)</nowiki> |
| + | |
| + | |
| + | Run the script: |
| + | |
| + | $ sudo python i2ctest.py |
| + | |
| + | |
| + | |
| {{RPI-ShieldBridge-TRAILER}} | | {{RPI-ShieldBridge-TRAILER}} |