
NOTE: this device operates at 3.3V and does not need a voltage level shifter, so you can connect SDA and SCL pins of this device directly to the correspondent Gpio pins of the router

Connections:
3V0 pin = 3.3V of the router
SDA = SDA GPIO the router
SCL = SCL GPIO of the router
GND = GND of the router
prerequsites:
- Codice: Seleziona tutto
opkg update
opkg install kmod-i2c-gpio kmod-i2c-gpio-custom kmod-i2c-core kmod-i2c-algo-bit
opkg install kmod-i2c-smbus
opkg install python
opkg install python-dev
opkg install python-smbus
opkg install bash
opkg install git-http
I2C configuration:
Note: I'm using GPIO 2 & 3 of TP-Link TL-WDR 4300 for I2C
gpio-2 (SDA) = JP1-7
gpio-3 (SCL) = JP1-7
set pins for I2C:
- Codice: Seleziona tutto
/sbin/rmmod leds-gpio
/sbin/insmod i2c-dev
/sbin/insmod i2c-gpio-custom bus0=0,2,3
note: add the above lines to /etc/rc.local to set I2C pins at startup
- Codice: Seleziona tutto
check I2C:
/bin/dmesg |grep i2c
if everything is OK you shoud see the following:
- Codice: Seleziona tutto
root@OpenWrt:~# /bin/dmesg |grep i2c
[ 34.835378] i2c /dev entries driver
[ 78.331772] i2c-gpio i2c-gpio.0: using pins 2 (SDA) and 3 (SCL)
---------------------------------------------------------------------------------------------------------------
lets start:
to check if the system detects the device and to check the I2C address (it should be 77), do the following:
- Codice: Seleziona tutto
i2cdetect -y 0
test if everything worked. A device should be displayed. For me it looks like this:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77
BMP180 Software:
The easiest way to address the sensor is to take an existing library that already has all the functions. Adafruit offers such a library for Raspberry but luckily it also works for OpenWrt

We need to clone the repository of Adafruit (git must be installed).
- Codice: Seleziona tutto
git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
cd Adafruit-Raspberry-Pi-Python-Code/
git checkout 9ff733d59242a02f7ccd0222001ce80f6090a978
cd Adafruit_BMP085
Then we can do the first test:
- Codice: Seleziona tutto
python Adafruit_BMP085_example.py
The script will provide an output similar to this one:
Temperature: 25.70 C
Pressure: 1007.08 hPa
Altitude: 50.83