HELP with A02YYUW Waterproof Ultrasonic Sensor

userHead l.laspada 2021-07-29 04:18:56 607 Views0 Replies

I am looking for help with the A02YYUW Waterproof Ultrasonic Sensor that I just received. I am using a Raspberry Pi 4 with Buster installed. I am trying to get some measure, for that I have followed the instruction from the wiki ( ... 1#target_3)

I have enabled UART following this procedure:
Code: Select all
   Start raspi-config: sudo raspi-config.
    Select option 3 - Interface Options.
    Select option P6 - Serial Port.
    At the prompt Would you like a login shell to be accessible over serial? answer 'No'
    At the prompt Would you like the serial port hardware to be enabled? answer 'Yes'
    Exit raspi-config and reboot the Pi for changes to take effect.
Then, I have created a test .py file with the following content:
Code: Select all
# -*- coding:utf-8 -*-

  # Connect board with raspberryPi.
  # Run this demo.
  # Connect A02 to UART
  # get the distance value
  # Copyright   [DFRobot](, 2016
  # Copyright   GNU Lesser General Public License
  # version  V1.0
  # date  2019-8-31

import time

from DFRobot_RaspberryPi_A02YYUW import DFRobot_A02_Distance as Board

board = Board()

def print_distance(dis):
  if board.last_operate_status == board.STA_OK:
    print("Distance %d mm" %dis)
  elif board.last_operate_status == board.STA_ERR_CHECKSUM:
  elif board.last_operate_status == board.STA_ERR_SERIAL:
    print("Serial open failed!")
  elif board.last_operate_status == board.STA_ERR_CHECK_OUT_LIMIT:
    print("Above the upper limit: %d" %dis)
  elif board.last_operate_status == board.STA_ERR_CHECK_LOW_LIMIT:
    print("Below the lower limit: %d" %dis)
  elif board.last_operate_status == board.STA_ERR_DATA:
    print("No data!")

if __name__ == "__main__":
  dis_min = 0   #Minimum ranging threshold: 0mm
  dis_max = 4500 #Highest ranging threshold: 4500mm
  board.set_dis_range(dis_min, dis_max)
  while True:
    distance = board.getDistance()
    time.sleep(0.3) #Delay time < 0.6s
Now, when I run this file I get the following output:
Code: Select all
Traceback (most recent call last):
  File "", line 21, in <module>
    from DFRobot_RaspberryPi_A02YYUW import DFRobot_A02_Distance as Board
ImportError: No module named DFRobot_RaspberryPi_A02YYUW
Can someone please help me to resolve this problem?

Many thanks,