[How To] Add barometric pressure and temperature sensor to Openwrt


#1

This is the How To connect a I2C BMP085 barometric pressure and temperature sensor to Openwrt.

For Python, I2C installation and I2C hardware configuration tips, please read my previous post here:

[[How To] Add 20x4 LCD (HD44780) to a OpenWrt router via I2C](http://[How To] Add 20x4 LCD (HD44780) to a OpenWrt router via I2C)


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 :grinning:

Connections:

3V0 pin = 3.3V of the router
SDA = SDA GPIO the router
SCL = SCL GPIO of the router
GND = GND of the router


lets start:

to check if the system detects the device and to check the I2C address (it should be 77), do the following:

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 :grinning:

We need to clone the repository of Adafruit (git must be installed).

opkg update
opkg install install git-http
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:

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


Credits: http://49v.com/viewtopic.php?f=24&t=230&p=515#p515


#2

Did you try using pip to install the required libraries in a venv, or did you go direct into the root install of Python?

I use the BME280, BME680, MAX30205, MCP9808, and HDC1010 in various applications and the basic approach would be the same for any of them. I do tend to write my own drivers, as the Adafruit Python drivers have been somewhat abandoned in favor of their own "flavor" of Python.


#3

I go direct into the root install of Python


#4

@ pilovis Could you please add targeted hardware to subject line e.g. Raspberry if there is some place left?


#5

Why do you want to restrict this to Raspi? Every device where I2C is accessible should do.


#6

You are right, I couldn't imagine someone is poking around at a standard router without proper pin header for I²C ;- )

Does "all" routers have an I²C bus? Estimated around %?


#7

I'm not sure, but the inexpensive GL.iNet devices have a header for I2C called out. At under US$20 in a case, they're an interesting platform.


#8

Hi Jeff,
yes I took a short look at https://www.gl-inet.com/ and indeed nearly all are marked with "GPIO header" although I don't ckecked if this also means I2C bus.

As a "normal" usr my first thoughts where centered around standard consumer routers. I superficial ckecked for R7800 and found nothing so probably it's a niche for enthusiasts, nevertheless not uninteresting e.g. for some people to add a LCD matrix display for router status.

What surely would have a heavy commercial impact would be some kind of controllable RGB lightning for routers ;- )


#9

I agree that many consumer devices can be "challenging" to find the right pads, if they exist at all. I'll be checking my Archer C7's unpopulated header one of these days.

On the GL.iNet, for example, https://openwrt.org/toh/gl.inet/gl.inet_gl-ar300m-lite shows two GPIOs "tagged" as I2C and two "tagged" for serial.


#10

People are doing the strangest things if they are only desperate enough... :slight_smile:


#11

For this project I used the TP-Link TL WDR4300 (TL-WDR3600 is almost the same) and OpenWrt 18.06.1


#12

Any Router that supports OpenWrt 18.06.1 and has at least two free GPIO pins availabe and 32 Mbytes or more of ram, is OK for this project.


#13

if you don't want to open your router and solder any pin inside, simply buy an USB to I2C dongle and use kmod-i2c-tiny-usb :grinning: