General Raspberry Pi

Integrating A02YYUW and RaspberryPI

userHead PeterK 2022-08-08 15:32:13 1374 Views1 Replies

Integrating A02YYUW and RaspberryPI

 

Setup

-   Have an running RaspberryPI 4 with either a DSI or SSH for access available

-   Have a A02YYUW sensor

 

Configuring RaspberryPI

The sensor needs to be attached to the UART bus. If you don’t know what UART is, this is a good link with a primer on how the UART works.

 

https://www.electronicwings.com/raspberry-pi/raspberry-pi-uart-communication-using-python-and-c

 

By default, the primary UART is assigned to the Linux console. If you wish to use the primary UART for other purposes, you must reconfigure Raspberry Pi OS.

 

cd /boot

Add the following two lines to config.txt

enable_uart=1

dtoverlay=disable-bt

 

Reboot the RaspberryPI.

 

Check if the UART is setup correctly.

ls -l /dev | more

 

You should see two lines passing by

lrwxrwxrwx  1 root root           7 aug  7 22:17 serial0 -> ttyAMA0

lrwxrwxrwx  1 root root           5 aug  7 22:17 serial1 -> ttyS0

 

This means that the output of serial0 is forwarded to ttyAMA0.

 

Connecting RaspberryPI and A02YYUW sensor

The sensor has 4 wires: power, ground, transmission and receive

 

I’ve used the following setup:

-   Sensor red wire = power => RasberryPI pin 4

-   Sensor blue wire = TX => RaspberryPI pin 8 = GPIO14 = UART_TXD0

-   Sensor green wire = RX => RaspberryPI pin 10 = GPIO15 = UART_RXD0

-   Sensor black wire = ground = Raspberry pin 14

 

 

 

Download the A02YYUW sensor library from

https://github.com/DFRobot/DFRobot_RaspberryPi_A02YYUW

 

/home/pi

sudo git clone https://github.com/DFRobot/DFRobot_RaspberryPi_A02YYUW

 

You should see a new directory

pi@raspberrypi:~ $ ls -l

totaal 40

drwxr-xr-x 2 pi   pi   4096 mrt  4  2021 Bookshelf

drwxr-xr-x 2 pi   pi   4096 mrt  5  2021 Desktop

drwxr-xr-x 6 root root 4096 aug  7 22:44 DFRobot_RaspberryPi_A02YYUW

drwxr-xr-x 2 pi   pi   4096 mrt  5  2021 Documents

drwxr-xr-x 2 pi   pi   4096 mrt  5  2021 Downloads

drwxr-xr-x 2 pi   pi   4096 mrt  5  2021 Music

drwxr-xr-x 2 pi   pi   4096 mrt  5  2021 Pictures

drwxr-xr-x 2 pi   pi   4096 mrt  5  2021 Public

drwxr-xr-x 2 pi   pi   4096 mrt  5  2021 Templates

drwxr-xr-x 2 pi   pi   4096 mrt  5  2021 Videos

 

cd into the DFRobot directory

The directory consist of:

pi@raspberrypi:~/DFRobot_RaspberryPi_A02YYUW $ ls -l

totaal 36

-rw-r--r-- 1 pi   pi   1287 aug  7 22:04 demo.py

-rw-r--r-- 1 root root 2465 aug  7 21:08 DFRobot_RaspberryPi_A02YYUW.py

drwxr-xr-x 2 root root 4096 aug  7 21:08 examples

-rw-r--r-- 1 root root  285 aug  7 21:08 library.properties

-rw-r--r-- 1 root root 1053 aug  7 21:08 LICENSE

-rw-r--r-- 1 root root 2269 aug  7 21:08 README_CN.md

-rw-r--r-- 1 root root 2227 aug  7 21:08 readme.md

drwxr-xr-x 3 root root 4096 aug  7 21:08 resources

 

To check if the setup works

cd examples

 

python3 demo_get_distance.py

 

If you have connected the wires correctly you should see the following output:

 

pi@raspberrypi:~/DFRobot_RaspberryPi_A02YYUW/examples $ python3 demo_get_distance.py

Distance 1641 mm

Distance 1645 mm

Distance 1645 mm

Distance 1641 mm

Distance 1645 mm

Distance 1653 mm

 

Note: that if you move the sensor, the distance doesn’t change. I don't know why that is.

However, if you restart the script, the values are correct. So for static (non-moving) measurements like a waterlevel in a tank this is ok.

 

 

2022-11-11 18:12:58

Is there a way i can use 2 A02YYUW with 1 raspberry pi? 

userHeadPic Fedez