General Raspberry Pi

A01NYUB with Mycodo on a Raspberry pi 2B

userHead Panos.Takis 2023-01-10 01:45:56 150 Views1 Replies



1) I am trying to connect a A01NYUB ultrasonic distance sensor, to a raspberry pi running mycodo, so I can monitor and control the water tank level. 


As I have no previous experience with electronics and coding and having no idea where to ask I thought I should give it a try here.


If this is not the place, please let me know where should I look/ask.


2) Is there a way to connect (combine) more than 1 UART sensors on a raspberry pi in one pair of pins? I thought of using a UART to usb converter to overcome this issue but I will still need drivers and coding.



2023-01-12 21:46:09



For the moment I found a way to get measurements from the sensor. I used the BASH Command input

First you need to make some changes.


Go to directory

“/home/username/DFRobot_RaspberryPi_A02YYUW/examples/” (replace username with username you chose when installing Raspbian)


Make a safe copy of the original file “”






Sudo nano


Delete all and Paste the following



# -*- coding:utf-8 -*-




  @brief Get ranging data.

  @n Connect board with raspberryPi.

  @n --------------------------------------------

  @n sensor pin |         raspberry pi          |

  @n     VCC    |            5V/3V3             |

  @n     GND    |             GND               |

  @n     RX     |          (BCM)14 TX           |

  @n     TX     |          (BCM)15 RX           |

  @n --------------------------------------------


  @Copyright   Copyright (c) 2010 DFRobot Co.Ltd (

  @license     The MIT License (MIT)

  @author [Arya]([email protected])

  @version  V1.0

  @date  2019-8-31




import sys

import os

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("%d" %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__":

  #Minimum ranging threshold: 0mm

  dis_min = 0

  #Highest ranging threshold: 4500mm 

  dis_max = 4500

  board.set_dis_range(dis_min, dis_max)

  distance = board.getDistance()



Save and exit

These changes return one single value so mycodo can use store and display it.


Create a bash file in home directory for example. I named it

Open it and Pastethe following:



python3 /home/username/DFRobot_RaspberryPi_A02YYUW/examples/


replace username with username you chose when installing Raspbian

save and close


from a termina run


chmod +x /home/username/


replace username with username you chose when installing Raspbian



And last step

on mycodo go to  Setup/Input

Choose from the dropdown menu “Linux Bash Command: Return Value [Mycodo]”


In the window that opens

In Options section in the Command box paste




In Custom options in the box User enter username you chose when installing Raspbian

And next to it in Current working directory type




replace username with username you chose when installing Raspbian


click save ad then click close


Activate the input you just added





userHeadPic Panos.Takis