I want to connect a pressure sensor that use a RS485 communication to raspberry pi,
when I connected it to RS485 to UART converter to the raspberry
but when I ran the code the output is b'' with no numbers from the sensor
can anybody know how I can read from the sensor ?
'KITA' is the sensor I use.
import serial
import time
ser = serial.Serial('/dev/serial0', 9600, timeout=0.1)'
ser.write(b'$PF,200\r\n')
ser.write(b'$PO,20\r\n')
x = ser.read()
print (x)
Related
I am trying to send a large amount of data from my Raspberry Pi 4 to my computer. I configured the Raspberry Pi as USB OTG Serial Gadget and the data is sent through the usb-c port to my computer.
Please take a look at the following code running on the Raspberry Pi. One MB of data is sent.
import serial
ser = serial.Serial( port='/dev/ttyGS0', baudrate=115200)
packet = bytearray()
for i in range(0, 1000000):
packet.append(0x2f)
ser.write(packet)
This is the code I am running first on my computer.
import serial
import time
ser = serial.Serial(port='COM30', baudrate=115200)
sum = 0
while 1:
bytesToRead = ser.inWaiting()
if bytesToRead > 0:
serial_line = ser.read(bytesToRead)
sum += bytesToRead
print(sum)
time.sleep(0.01)
I would expect that the received data has always the same length as the sent data. But in this example the computer receives a data length of around 990.000 Bytes in most cases. Even if I run the code without the sleep function on my computer, there are sometimes missing bytes.
How can I make sure that the data is sent and received without data loss?
First, if you have enabled logins on the serial port, you need to disable them first otherwise the port will be inaccessible.
Second, stop getty#ttyGS0.service and disable it.
And then everything will work fine.
I want to interface gsm A6 module to raspberry pi by software uart. I am looking for a python library which will convert any gpio pin to TX and RX pin. I was trying pigpio library. there I got the serial read but whats about serial write? is it possible to implement serial write also? or is there any other library?
import sys
import time
import difflib
import pigpio
RX=18
try:
pi = pigpio.pi()
pi.set_mode(RX, pigpio.INPUT)
pi.bb_serial_read_open(RX, 9600, 8)
while 1:
(count, data) = pi.bb_serial_read(RX)
if count:
print data
time.sleep(1)
except:
pi.bb_serial_read_close(RX)
pi.stop()
I want a software uart transmite function.
The Raspberry Pi has a Broadcom BCM 2835 chip allowing it to interface with SPI devices on its GPIO pins. I encountered a problem adressing LEDs in a 8x8 Matrix via SPI.
I want to adress single LEDs on the matrix, but I haven't figured out, which bytes adresses which LED(s).
SPIdev seems to be the right library for this purpose und I stumbled upon this snippet of code:
import spidev
import time
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 7629
# Split an integer input into a two byte array to send via SPI
def write_pot(input):
msb = input >> 8
lsb = input & 0xFF
spi.xfer([msb, lsb])
# Repeatedly switch a MCP4151 digital pot off then on
while True:
write_pot(0x1FF)
time.sleep(0.5)
write_pot(0x00)
time.sleep(0.5)
Does anyone know which values adresses (a) specific LED(s)?
In C/C++ adressing works very well via the wiringpi-library, a useful documentation can be found here:
http://wiki.52pi.com/index.php/RPI-RGB-LED-Matrix_SKU:EP-0075
I'm trying to detect the UART port names for a BananaPi M3 device running a Raspbian so I can do a simple test to send and receive some data on it. I connected the RX and TX pins of the UART connector with a simple jumper but I cannot detect the actual name of the ports. The pins are described here but I don't find exactly their names.
The tests I made so far without success:
ser = serial.Serial('/dev/ttyS1', 115200, timeout = 1)
num = ser.write("test\n")
ser2 = serial.Serial('/dev/ttyS2', 115200, timeout = 1)
data = ser2.read(100)
So, how exactly the UART port names can be detected.
Thank you
I FT232 module connected to the Raspberry Pi (with USB cable). I want to receive 8bytes (1 byte). On Windows, Terminal draws me correctly beats (eg. 00001011). In the following python script:
#!/usr/bin/python
import serial
import binascii
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
while True:
str1 = ser.read(1)
if str1 == '':
print ''
else:
print bin(int(binascii.hexlify(str1),16))
returns only 2 bits at the end:
0b11111100 ,
0b11111101 ,
0b11111110 ,
0b11111111
What am I doing wrong that draws me just 2bits at the end?
Below please find screen how to receive data on Windows:
http://mateok.ovh/windows.jpg
And on Raspberry Pi:
http://mateok.ovh/linux.jpg
I would like to get on the Raspberry Pi received data were the same.
Edit:
I was able to find a solution! It turned out that the reason is ... that the device had been connected before starting the Raspberry Pi! If they Disconnect and reconnect only when the Raspberry Pi starts - values are returned well! Maybe someone knows the cause of this? And how can I fix it? I do not want every time you re-connect the converter ..