Raspberry Pi und I²C

GPIO

SPI und I²C aktivieren

sudo raspi-config

Interfacing Options

Dort kann man die I2C aktivieren…

I²C Baudrate anpassen

Die Baudrate muss nicht zwangsläufig angepasst werden. Wenn man dies tun will, dann geht es bspw. so:

#Remove Module
modprobe -r i2c_bcm2708

#Change baudrate
sudo bash
cd /etc/modprobe.d
nano i2c_bcm2708.conf
options i2c_bcm2708 baudrate=400000

#Load module
modprobe i2c_bcm2708

I²C und PHP über Apache

Damit der www-Dienst direkt den I2C-Bus steuern kann, muss www-data (das Konto vom Apache) zu der I2C Gruppe hinzugefügt werden.

sudo adduser www-data i2c

Ggf. apache neustarten

sudo service apache2 restart

In die PHP-Datei muss folgender Auruf rein (Beispiel)

shell_exec ('/usr/sbin/i2cset -y 1 0x20 0x12 12');

Leave a comment

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

4 − 1 =