General Raspberry Pi

A01NYUB with Mycodo on a Raspberry pi 2B

userHead Panos.Takis 2023-01-10 01:45:56 415 Views2 Replies

Hello! 

 

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.

 

Thanks!

2023-11-24 01:45:41

The solution I got for 2) is a “Gravity: I2C to Dual UART Module”.  https://www.dfrobot.com/product-2001.html

 

Thanx for the help

userHeadPic Panos.Takis
2023-01-12 21:46:09

WALKAROUND

 

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 “demo_get_distance.py”

 

Cp demo_get_distance.py demo_get_distance.py.bkp

 

then

 

Sudo nano demo_get_distance.py

 

Delete all and Paste the following

 

 

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

 

'''!

  @file demo_get_distance.py

  @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 --------------------------------------------

  @n

  @Copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)

  @license     The MIT License (MIT)

  @author [Arya]([email protected])

  @version  V1.0

  @date  2019-8-31

  @url https://github.com/DFRobot/DFRobot_RaspberryPi_A02YYUW

'''

 

import sys

import os

import time

 

sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

 

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:

    print("ERROR")

  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()

  print_distance(distance)

 

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 A01NYUB.sh

Open it and Pastethe following:

 

#!/bin/bash

python3 /home/username/DFRobot_RaspberryPi_A02YYUW/examples/demo_get_distance.py

 

replace username with username you chose when installing Raspbian

save and close

 

from a termina run

 

chmod +x /home/username/A01NYUB.sh

 

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

 

./A01NYUB.sh

 

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

And next to it in Current working directory type

 

/home/username/

 

replace username with username you chose when installing Raspbian

 

click save ad then click close

 

Activate the input you just added

 

Done

 

 

userHeadPic Panos.Takis