LCD5110实时显示温度、湿度、光照度、颗粒物

先上图自己看
从上到下分别是 温度、湿度、光照度、颗粒物上接线图:
自己看
[mw_shl_code=c,true]
/*
BH1750光照强度传感器接法:
VCC-5v
GND-GND
SCL-SCL(A5)
SDA-SDA(A4)

DHT11接法:
VCC–>5V
GND–>GND
DATA–>D9

PPD42NS接法:
针脚冲下,从右至左为1-5接口
Pin 1 => GND
Pin 3 => 5VDC
Pin 4 => D8

LCD5110接法:
clk = D7 //clock
din = D6, // data-in
dc = D5, // data select
reset = D2, //reset
sce = D3); // enable
*/

include

include

include

include

include

define DHT11PIN 9

//bh1750相关
int BH1750address = 0x23;
byte buff[2];

//lcd5110相关
LCD_PCD8544 lcd;

//PPD42NS颗粒物传感器相关
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
double concentration = 0;

void setup() {
Serial.begin(9600);
//初始化LCD
lcd.begin();
lcd.clear();
lcd.setCursor(0, 0);//在第一行打印出 Environment 字符串
lcd.print(” Environment “);
lcd.setCursor(0, 1);//光标移至第2行(从0开始数算起) 第1个像素(下同)
lcd.print(“Temp :”);//显示出温度提示(下同)
lcd.setCursor(73, 1);//光标移至第2行(从0开始数算起) 第72个像素
lcd.print(“oC”);//显示出温度单位(下同)
lcd.setCursor(0, 2);
lcd.print(“Humi :”);
lcd.setCursor(79, 2);
lcd.print(“%”);
lcd.setCursor(0, 3);
lcd.print(“Light:”);
lcd.setCursor(73,3);
lcd.print(“lx”);
lcd.setCursor(0, 4);
lcd.print(“PM :”);
lcd.setCursor(0, 5);//光标移至第6行(从0开始数算起) 第37个像素
lcd.print(” Best wishes”);//显示出 Best wishes

pinMode(pin,INPUT);
starttime = millis();
}

void loop() {
//计算颗粒物
duration = pulseIn(pin, LOW);
lowpulseoccupancy = lowpulseoccupancy+duration;

if ((millis()-starttime) > sampletime_ms)
{
  ratio = lowpulseoccupancy/(sampletime_ms*10.0);
  concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62;
//串口打印出颗粒物数据
  Serial.print(lowpulseoccupancy);
  Serial.print(",");
  Serial.print(ratio);
  Serial.print(",");
  Serial.println(concentration);
  lowpulseoccupancy = 0;

//串口打印出DHT11测出的温湿度数据
DHT11.read(DHT11PIN);
int dht11temp = DHT11.temperature;
Serial.print(“temperature:”);
Serial.println(dht11temp);
int dht11hum = DHT11.humidity;
Serial.print(“humidity:”);
Serial.println(dht11hum);

//串口打印出BH750光照度数据
double light = BH1750();
Serial.print(“light:”);
Serial.println(light);

//lcd上显示数据
lcd.setCursor(37, 1);//光标移至第2行(从0开始数,1就是第二个) 第37个像素(下同)
lcd.print(dht11temp);//显示出温度(下同)
lcd.setCursor(37, 2);
lcd.print(dht11hum);
lcd.setCursor(37, 3);
lcd.print(light);
lcd.setCursor(37, 4);
lcd.print(concentration);

starttime=millis();
}

}

//BH1750相关函数
double BH1750()
{
int i=0;
double val=0;
Wire.beginTransmission(BH1750address);
Wire.write(0x10);//1lx reolution 120ms
Wire.endTransmission();
delay(200);
Wire.beginTransmission(BH1750address);
Wire.requestFrom(BH1750address, 2);
while(Wire.available()) //
{
buff = Wire.read(); // receive one byte
i++;
}
Wire.endTransmission();
if(2==i)
{
val=((buff[0]<<8)|buff[1])/1.2;
}
return val;
}

[/mw_shl_code]

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的 tkinter 界面,可以显示温度湿度、光照和土壤湿度数据。您需要使用传感器等硬件设备来获取这些数据,并在下面的代码中进行相应的修改。 ```python import tkinter as tk class SensorApp: def __init__(self, master): # 创建 GUI 窗口 self.master = master master.title("传感器数据") # 创建显示温度的标签 self.temp_label = tk.Label(master, text="温度: ") self.temp_label.pack() # 创建显示湿度的标签 self.humidity_label = tk.Label(master, text="湿度: ") self.humidity_label.pack() # 创建显示光照的标签 self.light_label = tk.Label(master, text="光照: ") self.light_label.pack() # 创建显示土壤湿度的标签 self.soil_moisture_label = tk.Label(master, text="土壤湿度: ") self.soil_moisture_label.pack() def update_data(self, temp, humidity, light, soil_moisture): # 更新标签的显示文本 self.temp_label.config(text=f"温度: {temp}℃") self.humidity_label.config(text=f"湿度: {humidity}%") self.light_label.config(text=f"光照: {light}lux") self.soil_moisture_label.config(text=f"土壤湿度: {soil_moisture}%") # 模拟传感器数据更新 def update_sensor_data(app): temp = 25.0 humidity = 50 light = 500 soil_moisture = 80 app.update_data(temp, humidity, light, soil_moisture) # 每隔 5 秒钟更新一次数据 app.master.after(5000, update_sensor_data, app) # 启动 GUI 窗口和数据更新 root = tk.Tk() app = SensorApp(root) root.after(0, update_sensor_data, app) root.mainloop() ``` 注意,上面的示例程序中的数据仅为模拟数据。您需要使用实际的传感器数据来替换 `update_sensor_data` 函数中的数据获取部分。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值