当前位置:网站首页>Measure the current temperature
Measure the current temperature
2022-06-25 08:22:00 【yangsf_】
Measure the current temperature
We use Mongoose OS + esp8266 + DHT11 To do it .
Mongoose OS: An Internet of things The firmware Development framework . Official documents
esp8266:ESP8266 Is a A serial port WiFi modular .
DHT11: A temperature sensor .
The firmware : It can be understood as the operating system of an electronic product , It is the software at the bottom of the hardware .
A serial port : Look at the picture directly


You can send eight bits of data at one time , Mutual interference , If one bit of parallel port transmission error occurs, it is necessary to resend the eight bit data , One bit of serial port transmission error only needs to be sent again .
One 、Hello World
download mongoose OS The official tool of mos.exe, Double click or enter a command
mos uiYou can start it UI Interface . If it doesn't start , Open Command Prompt , Inputcd c:\mosthenmos --start-webview=false. Need to close when closing 1992 Service of port ( Otherwise, double clicking again will not open ui Interface ).
With a data cable ( It must be a data line that can transmit data , Some cables can only be charged ) Connect esp8266, Install the corresponding driver according to your own requirements .
Lexin motherboard Silabs The driver
Lexin development board CH43x The driver
CC3200、CC3220 Of FTDI The driver
Installation driver :1. Right click this computer -> management -> Device manager -> Other equipment
The yellow exclamation point is the driver we need to install , After installation, you can see which port the device is on in the port .
open mos, Select port and model , The port and model shall be selected according to the actual situation , I use it esp8266 2m All choices of memory esp8266 flash 2m.
stay ui There is a line of text box below which you can enter commands , Input
mos clone https://github.com/mongoose-os-apps/demo-c app1Clone a template . After cloning, we can see a in the corresponding directory app1 Folder , The contents of this catalog are src In the catalog main.c It's our code ,mos.yml It's a configuration file , Describe the entire application .open main.c, find

It is amended as follows :

stay mos Of ui Input... In the interface
mos buildCompile code .After a long wait, enter
mos flashBrush the firmware into .One sentence per second will be output after success hello world!

Two 、 Use DHT11 Thermometry
First put our dht11 Connect to esp8266 On ,vcc or + Connect 3v The pin of , GND or - even GND, DAT or out even IO Pin (IO Just remember , Like I take it IO2 Pin , It will be configured as IO2 Pin ).
esp8266 Pin figure :

After the connection is completed, we just need to hello world The program is slightly modified :
Add dependency :
stay mos.yml Of libs Add below dht Driven dependency ( These drivers can be used in mongoose Find... On the official website ), if necessary rpc Services can be added rpc rely on .
libs: - location: https://github.com/mongoose-os-libs/boards - location: https://github.com/mongoose-os-libs/demo-bundle - location: https://github.com/mongoose-os-libs/rpc-service-config - location: https://github.com/mongoose-os-libs/rpc-service-fs - location: https://github.com/mongoose-os-libs/rpc-uart - location: https://github.com/mongoose-os-libs/wifi - location: https://github.com/mongoose-os-libs/dhtConfigure pins , Modify the code :
stay mos.yml Add :
config_schema: - ["app.pin", "i", 2, { title: "GPIO pin a sensor is attached to"}] # Because just now I was io2 Pin , So this is 2main.c:
#include "mgos.h" #include "mgos_dht.h" static void timer_cb(void *dht) { LOG(LL_INFO, ("Temperature: %lf", mgos_dht_get_temp(dht))); } enum mgos_app_init_result mgos_app_init(void) { struct mgos_dht *dht = mgos_dht_create(mgos_sys_config_get_app_pin(), DHT11); mgos_set_timer(1000, true, timer_cb, dht); return MGOS_APP_INIT_SUCCESS; }It seems complicated , There are actually only two important functions :
mgos_dht_create(mgos_sys_config_get_app_pin(), DHT11);mgos_dht_get_temp(dht)initialization dht And get the temperature .
compile & Firmware brush in
stay mos Of ui Input... In the interface
mos buildAfter successful compilation, entermos flashBrush in the firmware .effect :

边栏推荐
- 共话云原生数据库的未来
- STM32CubeMX 学习(5)输入捕获实验
- 4個不可不知的采用“安全左移”的理由
- After using the remote control of the working machine, problems occurred in the use of the local ROS, and the roscore did not respond
- Electronics: Lesson 008 - Experiment 6: very simple switches
- How do I install the software using the apt get command?
- STM32CubeMX 學習(5)輸入捕獲實驗
- DNS protocol and its complete DNS query process
- Luogu p5994 [pa2014]kuglarz (XOR thinking +mst)
- 初体验完全托管型图数据库 Amazon Neptune
猜你喜欢

leetcode. 13 --- Roman numeral to integer

Quickly build a real-time face mask detection system in five minutes (opencv+paddlehub with source code)

Opencv minimum filtering (not limited to images)

Allgero reports an error: program has encoded a problem and must exit The design will be saved as a . SAV file

What is SKU and SPU? What is the difference between SKU and SPU

Overview of image super score: the past and present life of image super score in a single screen (with core code)

TCP and UDP

Stm32cubemx Learning (5) Input capture Experiment

Electronics: Lesson 008 - Experiment 6: very simple switches

Talk about the future of cloud native database
随机推荐
[thesis study] vqmivc
TS environment setup
A solution to slow startup of Anaconda navigator
Opencv daily function structure analysis and shape descriptor (8) Fitline function fitting line
电子学:第010课——实验 9:时间与电容器
自制坡道,可是真的很香
Websocket understanding and application scenarios
Data-centric vs. Model-centric. The Answer is Clear!
想转行学软件测试担心哪些问题?
Is it safe to open an account through the haircut account opening link now?
电子学:第010课——实验 8:继电振荡器
使用apt-get命令如何安装软件?
In 2022, which industry will graduates prefer when looking for jobs?
打新债安不安全 有风险吗
想开个户,网上股票开户安不安全?
Solving some interesting problems with recurrence of function
每日刷题记录 (三)
Electronics: Lesson 010 - Experiment 9: time and capacitors
TCP and UDP
Black dot = = white dot (MST)