fab-lab.eu
Published

#ESP8266 - I2C sensor example with BMP180 that works!

Turning ESP8266 into a #SENSableTHING using I2C sensor like the Bosch Sensortec BMP180

IntermediateWork in progress31,149
#ESP8266 - I2C sensor example with BMP180 that works!

Things used in this project

Hardware components

SparkFun ESP8266 Thing - Dev Board
SparkFun ESP8266 Thing - Dev Board
×1
Sparkfun BMP180 breakout
×1

Story

Read more

Code

bmp.lua

Lua
this is the script which does the actual sensor reading, make sure you are using the right SDA / SCL pin mapping, this one works for the Sparkfun ESP8266 Thing where SCL is on GPIO15 (!)
OSS = 1 -- oversampling setting (0-3)
SDA_PIN = 4 -- sda pin, GPIO2
SCL_PIN = 5 -- scl pin, GPIO15

bmp180 = require("bmp180")
bmp180.init(SDA_PIN, SCL_PIN)
bmp180.read(OSS)
t = bmp180.getTemperature()
p = bmp180.getPressure()

-- temperature in degrees Celsius  and Farenheit
print("Temperature: "..(t/10).."."..(t%10).." deg C")
print("Temperature: "..(9 * t / 50 + 32).."."..(9 * t / 5 % 10).." deg F")

-- pressure in differents units
print("Pressure: "..(p).." Pa")
print("Pressure: "..(p / 100).."."..(p % 100).." hPa")
print("Pressure: "..(p / 100).."."..(p % 100).." mbar")
print("Pressure: "..(p * 75 / 10000).."."..((p * 75 % 10000) / 1000).." mmHg")

-- release module
bmp180 = nil
package.loaded["bmp180"]=nil

The BMP180 sensor library

you can use any BMP085 or BMP180, we do use the one from javieryanez

Credits

fab-lab.eu

fab-lab.eu

14 projects • 152 followers
Maker!
Contact

Comments