518 views|3 replies

22

Posts

3

Resources
The OP
 

[Digi-Key Follow Me Issue 3] Task 5: Using External Sensors [Copy link]

 This post was last edited by Baicai Chongchong on 2023-11-29 17:46

[Digi-Key Follow Me Issue 3] Task 5: Using External Sensors

Task 5: Using External Sensors (Required)

Connect ambient light sensor or temperature and humidity sensor to obtain sensor value and convert it into real physical quantity

搭配器件: Seeed Studio XIAO ESP32C3、Seeed Studio Expansion Board Base for XIAO、 Grove - AHT20 I2C Industrial Grade Temperature and Humidity Sensor、Grove - Light Sensor v1.2

Operation process:

1. Download the driver file .

By checking the help('modules') command, you can know that the standard microPython firmware of ESP32C3 does not contain the driver file of aht20. You can choose your favorite aht20 driver file. I searched and downloaded a file on github. The address is as follows:

链接已隐藏,如需查看请登录或者注册

2. Try to obtain temperature and humidity .

At the same time, a routine is also given on this GitHub interface. Let's copy and test it.

import utime
from machine import Pin, I2C
import ahtx0

i2c = I2C(scl=Pin(7), sda=Pin(6))
sensor = ahtx0.AHT10(i2c)

while True:
print("\nTemperature: %0.2f C" % sensor.temperature)
print("Humidity: %0.2f %%" % sensor.relative_humidity)
	utime.sleep(5)

Note that the IIC pins should be replaced with the pins of our XIAO C3 just like SSD1306.

Connect the aht20 module of SEEED to the expansion board, click to run the program, if there is output similar to the following, it means that the aht20 module is driven successfully.

3. Use SSD1306 to display temperature and humidity.

Next, we will expand the process and use SSD1306 to display temperature and humidity.

The procedure is as follows:

import machine
import ssd1306
import utime
import ahtx0
from machine import SoftI2C,Pin,
i2c = SoftI2C(scl=Pin(7),sda=Pin(6),freq=100000)

Pin(4).value(0)
Pin(5).value(1)
# 初始化SSD1306显示屏
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
sensor = ahtx0.AHT10(i2c)
# 清除屏幕

while True:
    oled.fill(0)
    oled.text("Temperature:", 0, 10)
    oled.text("{:.2f} C".format(sensor.temperature), 40, 20)
    print("\nTemperature: %0.2f C" % sensor.temperature)
    oled.text("Humidity: ", 0, 40)
    oled.text("{:.2f} %".format(sensor.relative_humidity), 40, 50)
    print("Humidity: %0.2f %%" % sensor.relative_humidity)
    oled.show()
    utime.sleep(2)


# 在屏幕上显示文本


Click Run to display the temperature and humidity on the SSD1306 screen synchronously.

任务5

This post is from DigiKey Technology Zone

Latest reply

If I get a chance I'll try it too, just to see how it itches to play.   Details Published on 2023-11-30 10:31
 
 

6748

Posts

2

Resources
2
 

Micropython is great. It can get temperature data with just two statements.

This post is from DigiKey Technology Zone

Comments

Yes, and it doesn't need to be compiled. It's especially comfortable when you are making programs that don't require high performance and are not very complicated.  Details Published on 2023-11-29 17:42
 
 
 

22

Posts

3

Resources
3
 
wangerxian posted on 2023-11-29 17:14 Micropython is great. It can get temperature data with just two statements.

Yes, and it doesn't need to be compiled. It's especially comfortable when you are making programs that don't require high performance and are not very complicated.

This post is from DigiKey Technology Zone

Comments

If I get a chance I'll try it too, just to see how it itches to play.  Details Published on 2023-11-30 10:31
 
 
 

6748

Posts

2

Resources
4
 
Posted by Baicai Chongchong on 2023-11-29 17:42 Yes, and it doesn’t need to be compiled. It’s especially comfortable when you are making programs that don’t require high performance and are not very complicated

If I get a chance I'll try it too, just to see how it itches to play.

This post is from DigiKey Technology Zone
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list