In the "Thermometer Monitor Project Using Raspberry Pi Kit", we utilize the Picobricks Raspberry Pi kit to measure and display environmental temperature and humidity. This project involves block programming to write Python code, providing a hands-on learning experience in using humidity and temperature sensors. You'll learn to monitor and see the temp and humidity data on a monitor, enhancing your understanding of Python programming and sensor integration.
from machine import Pin,I2C,ADC #to acces the hardware picobricks
from picobricks import SSD1306_I2C, DHT11 #oled library
import utime #time library
#to acces the hardware picobricks
WIDTH=128
HEIGHT=64
#define the weight and height picobricks
sda=machine.Pin(4)
scl=machine.Pin(5)
#we define sda and scl pins for inter-path communication
i2c=machine.I2C(0, sda=sda, scl=scl, freq=2000000)#determine the frequency values
oled=SSD1306_I2C(128, 64, i2c)
pico_temp=DHT11(Pin(11))
current_time=utime.time()
while True:
if(utime.time() - current_time > 2):
current_time = utime.time()
pico_temp.measure()
oled.fill(0)#clear OLED
oled.show()
temperature=pico_temp.temperature
humidity=pico_temp.humidity
oled.text("Temperature: ",15,10)#print "Temperature: " on the OLED at x=15 y=10
oled.text(str(int(temperature)),55,20)
oled.text("Humidty: ", 15,40)
oled.text(str(int(humidity)),55,50)
oled.show()#show on OLED
utime.sleep(0.5)#wait for a half second
Arduino C Codes of the PicoBricks
#include
#include
#include "ACROBOTIC_SSD1306.h"
#define DHTPIN 11
#define DHTTYPE DHT11
//define the library
DHT dht(DHTPIN, DHTTYPE);
float temperature;
//define the temperature veriable
void setup() {
//define dht sensor and Oled screen
Serial.begin(115200);
dht.begin();
Wire.begin();
oled.init();
oled.clearDisplay();
}
void loop() {
temperature = dht.readTemperature();
Serial.print("Temp: ");
Serial.println(temperature);
oled.setTextXY(3,1);
oled.putString("Temperature: ");
//print "Temperature: " on the OLED at x=3 y=1
oled.setTextXY(4,3);
oled.putString(String(temperature));
//print the value from the temperature sensor to the oled screen at x=4 y=3
Serial.println(temperature);
delay(100);
}
GitHub Project Page
Tags: