2060 views|2 replies

8

Posts

0

Resources
The OP
 

Seven lines of code to implement an ultrasonic rangefinder (Oled screen display) [Copy link]

1. Introduction

The library function of shineblink core development board (Core for short) supports US-015 ultrasonic ranging sensor, so you only need to call two APIs to realize the ultrasonic ranging function.

PS: Core can realize Wifi/Ble/NB/Lora/ThreadMesh/RFID/Eth/Usb/RS485/RS232 communication, as well as more than 30 sensors/more than 10 hardware peripherals/more than 10 MCU built-in functions with only five or six lines of code, and these functions can run simultaneously in up to 5 random combinations.

2. Materials

  1. A shineblink core development board

  2. Ultrasonic ranging sensor module one

  3. 0.96 inch oled display

  4. One TYPE00-0000003F circuit board. Please download the schematic diagram and PCB source file of the circuit board from the following network disk address (AD project):

    https://yunpan.360.cn/surl_yP9fgP7LVGa

3. Complete code

LIB_0_96_OledConfig("IIC1")
LIB_US015Config()

--Start the big cycle
while(GC(1) == true)
do
  --Delay 200 milliseconds
  LIB_DelayMs(200)
 
  flag, distance = LIB_US015GetDistance()
  if flag == 1 then
    --Show measured distance
  LIB_0_96_OledPuts("2","1",string.format("distance:%04dmm", distance))
  end
end

4. Production process & result display

The development method of Core is very simple and elegant. Use Notepad (or any other editor) to open the main.lua file on the TF card of the Core development board, and then copy the above code into the main.lua file. Since Core has a built-in Lua compiler, you don't need to do any processing, and Core can start working according to the above code.

The following figure shows the effect of the code running after assembly and welding are completed:

V. Conclusion

The above code updates the output value of the ultrasonic ranging sensor every 0.2 seconds. For more technical information about Core, you can visit shineblink.com.

This post is from MCU

Latest reply

This is highly encapsulated code? It’s so short?? Amazing.   Details Published on 2020-11-16 18:35
 

1942

Posts

2

Resources
2
 

This is highly encapsulated code? It’s so short?? Amazing.

This post is from MCU
 
 

8

Posts

0

Resources
3
 
w494143467 posted on 2020-11-16 18:35 Is this a highly encapsulated code? It's so short? ? Awesome.

Well, it does encapsulate many complex functions in a very simple way.

This post is from MCU
 
 
 

Guess Your Favourite
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