Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1251

Python • Ultrasonic Sensor USB Serial Python

$
0
0
Hello all I am new to the Raspberry Pi forum I'm not too sure where this topic might belong since it encompasses a lot of different stuff but I have decided to try my luck here. I have an Ultrasonic Sensor (AJ-SR04M) connected USB TTL HW597. My hope is to get the sensor to read distance. I have the sensor set on Mode 5 per these instructions: https://manuals.plus/arduino/aj-sr04m-d ... manual.pdf

In addition, I have also asked this on the Arduino forum which has a little bit more progress but we are kind of at a stand still.
https://forum.arduino.cc/t/ultrasonic-s ... 1313503/12

Please let me know if y'all have any questions and I will answer it to the best of my ability. Thank You all for y'all's consideration.

Here is my code so far

```
# print bytes in ASCII

import serial
import sys
import msvcrt
import time
from time import sleep

serialPort = serial.Serial(
port="COM12", baudrate=9600, bytesize=8, timeout=1, stopbits=serial.STOPBITS_ONE
)
serialPort.rtscts = False
serialPort.xonxoff = False
serialPort.dsrdtr = False
sys.stdout.write("Python jsn_sr04t ultrasonic transducer\n")
i=0
command = b'\xF1' # character in hex
serialPort.write(command) # read Device information

while 1:
while serialPort.in_waiting > 0:
char = serialPort.read()
#sys.stdout.write("\nreceived ")
if ord(char) < 128:
sys.stdout.write(str(char,'ASCII'))
```
IMG_1519 Small.jpeg

Statistics: Posted by SDeleon21 — Wed Oct 23, 2024 9:41 pm



Viewing all articles
Browse latest Browse all 1251

Trending Articles