386 views|0 replies

8

Posts

1

Resources
The OP
 

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

 This post was last edited by epix on 2023-12-10 23:21
Ambient Light Sensor:
This is an analog sensor. It is connected to the GPIO2 interface of the core board through Grove, and uses the built-in ADC to read the voltage.
When reading from ADC, you can read the value in u16 format, or you can directly get the specific voltage value. Just call the method directly.
This ambient light sensor uses SENBA's LS06-S sensor, which is connected in series with a 68k resistor, and the intermediate output is sent to LM358. Since the output is not linear with the light intensity, the specific illumination value is not calculated here, and only qualitative analysis is done.
Place a mobile phone next to it as a brightness reference.
The read data is displayed on the screen.
code show as below
adc = ADC(Pin(2), atten=ADC.ATTN_11DB)

while True:
    light_adc = adc.read_u16()
    light_uv = adc.read_uv()
    oled.fill(0)
    oled.text(f'light_adc: {light_adc}', 0, 0)
    oled.text(f'light_mv: {light_uv / 1000}', 0, 10)
    oled.show()
    sleep(1)

The running effect is as follows. You can see that at the beginning, the brightness is high, and the numbers displayed on the phone and the display are large. When you block the light with your hand, the numbers displayed on the phone and the display become very small. After you remove your hand, the larger values are restored. The green circuit board below is only for fixing
light

Temperature and humidity sensor:
This is a digital sensor that transmits data via the I2C protocol. The chip used is AHT20, which can communicate directly via the I2C protocol according to the specifications. Due to its wide use, there is already a library written, so just call ahtx0.py here. First, you need to make sure this file has been written to the core board.
Place a thermometer and humidity meter next to it for reference.
Likewise, the read data is displayed on the display. The reading speed is limited to once every 2 seconds to prevent the reading itself from heating up.
code show as below
import ahtx0

aht20 = ahtx0.AHT20(i2c)
while True:
    t = aht20.temperature
    h = aht20.relative_humidity
    oled.fill(0)
    oled.text(f'T: {t}', 0, 0)
    oled.text(f'H: {h}', 0, 10)
    oled.show()
    sleep(2)

The operation results are as follows. It can be seen that at the beginning, the temperature and humidity are close to the temperature and humidity meter, and the reading is relatively accurate. After blocking the sensor with a finger, the humidity and temperature both rise significantly and rapidly due to the temperature and sweat of the human body.
temperature

This post is from DigiKey Technology Zone
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Domestic MCU replacement: a pitfall

  As a fan of Butterfly, I feel sorry for the shortage and price increase of STM32. But whether you are making product ...

i.MX6ULL Embedded Linux Development 5- Root File System Improvement

In the previous article, we used BusyBox to build a basic root file system for an embedded Linux system . The basic func ...

Relationship between PN conduction voltage drop and current and temperature

*) , the E junction is affected by temperature, and the change in on-state voltage drop is related to Is and Ic The cond ...

How to write 1 to the latch of the P0 port of the 51 microcontroller?

I saw a document saying: Why should the P0~P3 ports of the microcontroller be set to 1 when inputting? If you write 1 t ...

【Top Micro Intelligent Display Module】IV: Serial port interaction and application of curve, drawing board and animation controls

This post was last edited by Digital Leaf on 2021-11-21 12:00 In the previous article, SGTools was used to generate a s ...

RA2L1 MCU download program JLink Info: T-bit of XPSR is 0 but should be 1.

When I started to light up the lamp, I found that I couldn't download the program and got an error. I ruled out hardware ...

MOS tube selection problem

I want to use a SOT23 MOS tube to drive a 24V/180MA solenoid valve. The maximum power dissipation here is 2.5W, but 24*0 ...

Help device information and application EC11E1534408

Forum friends, does anyone have information about the Japanese rotary encoder EC11E1534408? Or are there any recommended ...

[Qinheng wireless charging chip CH246 & CH241 - 1]: Measure the inductance of the two coils

This post was last edited by MianQi on 2023-1-21 17:49 First correct the cross lines mentioned in the previous post: 67 ...

Any understanding of ADC sampling time of ST microcontroller

The maximum clock frequency of the built-in ADC of ST's F4 series MCU is 36MHZ. The total conversion time for a single A ...

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