内容介绍
内容介绍
根据要求完成如下任务:
任务一:
利用扩展接口,自由选择连接三到五个传感器,并将采集的数据显示在LCD屏幕上,并解释数据的含义。
并通过对开发板的显示屏显示采集到的数据。
初始化bmp280、DHT11、串口1 配置:
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
tft.begin();
tft.setRotation(3);
tft.fillScreen(TFT_BLACK); //Black background
tft.setFreeFont(&FreeSansBoldOblique12pt7b); //select Free, Sans, Bold, Oblique, 12pt.
tft.drawString("bmp280",10,10);//prints string at (70,80)
tft.setFreeFont(FF10); //select Free, Mono, Oblique, 12pt.
tft.drawString(" C",10,40);//prints string at (70,110)
tft.setFreeFont(FF10); //select Free, Serif, 12pt.
tft.drawString(" mbar",10,60);//prints string at (70,140)
tft.setFreeFont(FF10); //select Free, Serif, 12pt.
tft.drawString("AIR------",10,80);//prints string at (70,140)
tft.setFreeFont(FF10); //select Free, Serif, 12pt.
tft.drawString("HUMI %",10,100);//prints string at (70,140)
tft.setFreeFont(FF10); //select Free, Serif, 12pt.
tft.drawString("PM1.0 ",10,120);//prints string at (70,140)
tft.setFreeFont(FF10); //select Free, Serif, 12pt.
tft.drawString("PM2.5 ",10,140);//prints string at (70,140)
tft.setFreeFont(FF10); //select Free, Serif, 12pt.
tft.drawString("PM10 ",10,160);//prints string at (70,140)
if (!bme.begin(0x76)) {
Serial.println("I Have some problem to initialize the sensor");
}
pinMode(D2, INPUT);
}
下边是采集到的传感器值并进行显示(其中气压气温是通过IIC采集,DHT11是 单总线采集,空气颗粒物是通过串口1采集):
void loop() {
// float temp = bme.readTemperature();
// float press = bme.readPressure();
//采集温度
Serial.print("Tempe ");
sprintf(te,"%.2f",bme.readTemperature());
drawTemperature(bme.readTemperature());
tft.drawString(te,10,40);//prints string at (70,140)
Serial.println(bme.readTemperature());
//采集气压
Serial.print("press ");
sprintf(pr,"%.2f",bme.readPressure()/100);
drawTemperature(bme.readPressure()/10);
tft.drawString(pr,10,60);//prints string at (70,110)
Serial.println(bme.readPressure());
// float heatIndex = computeHeatIndex(temp, hum);
Serial.println("loop");
delay(1000);
//采集DHT11的湿度
read_DHT11();
Serial1.println("DHT11");
//采集激光传感器的 pm1.0 pm2.5 pm10 值
while(Serial1.available()>0){
Serial1.readBytes(serialin,32);
delay(100);
PM1 = (serialin[4]<<8) + serialin[5];
PM2 = (serialin[6]<<8) + serialin[7];
PM10 = (serialin[8]<<8) + serialin[9];
sprintf(pm_1,"%d.%d",PM1,PM1%10);
sprintf(pm_2,"%d.%d",PM2,PM2%10);
sprintf(pm_10,"%d.%d",PM10,PM10%10);
//显示到屏幕上 pm1.0 pm2.5 pm10 值
tft.drawString(pm_1,100,120);
tft.drawString(pm_2,100,140);
tft.drawString(pm_10,100,160);
Serial1.println("AIR --- ");
for(int a=0;a<32;a++)
{
Serial1.write(serialin[a]);
}
}
}
如下所示lcd显示屏显示数据的图片:
活动的心得体会:作为一个嵌入式开发人员,熟练掌握Arduino开发技能是必须的,这也是我参加本次活动的初衷;当然对这次的开发学习的过程来说,用 Arduino 硬件可以快速搭建原型,并用于测试、验证,这点对嵌入式工程师来说,太友好了。
意见:希望 Funpack 明年的活动,多出一些有趣的基础活动,比如简单的FPGA实验等等,这样更多小白可以快速入门参与进来。
附件下载
wio代码.rar
团队介绍
评论
0 / 100
查看更多