from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf, sys
import utime
from time import sleep
import ds18x20
import onewire
import bmp180
i2c = I2C(0,scl=Pin(1),sda=Pin(0),freq=100000)
print("Scanning I2C....")
devices = i2c.scan()
print("I2C Devices Found:",devices)
sensor = bmp180.BMP180(i2c)
sensor.oversample_sett=2
sensor.sea_level_pressure=101325
DATA_PIN = Pin(22)
ds_sensor = ds18x20.DS18X20(onewire.OneWire(DATA_PIN))
roms = ds_sensor.scan()
def init_i2c(scl_pin, sda_pin):
i2c_dev = I2C(1,scl =Pin(scl_pin),sda=Pin(sda_pin),freq=200000)
i2c_addr = [hex(ii) for ii in i2c_dev.scan()]
if not i2c_addr:
print('No I2C Display Found')
sys.exit()
else:
print("I2C Address : {}".format(i2c_addr[0]))
print("I2C Configuration: {}".format(i2c_dev))
return i2c_dev
pix_res_x = 128
pix_res_y = 64
i2c_dev = init_i2c(scl_pin=27,sda_pin=26)
oled=SSD1306_I2C(pix_res_x,pix_res_y,i2c_dev)
oled.text("Iot Comms Lab",5,5)
oled.text("SMIT Sikkim",5,15)
while True:
#oled.fill(0)
oled.fill_rect(5,25,128,40,0)
ds_sensor.convert_temp()
sleep(0.01)
for rom in roms:
temperature = ds_sensor.read_temp(rom)
pressure=sensor.pressure
alt = sensor.altitude()
print ("Temprature: {:.2f}°C".format(temperature))
msg="Temp:"+str(temperature)+"deg"
msg1="Pres:"+str(pressure)+"Pa"
msg2="Alt:"+str(alt)+"m"
oled.text(msg,5,25)
oled.text(msg1,5,35)
oled.text(msg2,5,45)
oled.show()
temp = sensor.temperature
pressure=sensor.pressure
alt = sensor.altitude()
print('-------------------------')
print("Temperature:", temp)
print("Pressure:", pressure)
print("Altitude:", alt)
sleep(1)Loading
bmp180
bmp180