r/CodingHelp • u/[deleted] • Aug 19 '20
[Python] I'm trying to communicate from RasPi to Arduino via Rs485. I'm using an Usb to Rs485 converter on the RasPi side, and Max485 chip on Arduino side. Neither one picks up a message from the other.
I need to connect a RasPi to my existing RS485 network so I can access all of it via internet. I know both devices can send information, but it is not being received by the other
I have a RasPi 4B, with a USB to Rs485 adapter. This particular adapter has two leds that light up when you are receiving information (RXD) and transmitting information (TXD). They are incredibly useful, and because of them I know that information is being sent out of the RasPi.
The Arduino is an Arduino Mega, and is connected to a MAX485 Transceiver. I have used these chips extensively in an Arduino to Arduino network, and they function wonderfully.
Wiring has been checked repeatedly:
USB Adapter: A to MAX485 A, B to MAX485 B, GND to Arduino GND
MAX485: VCC to Arduino 5v, GND to Arduino GND, RO to Arduino RX3, DI to Arduino TX3, DE/RE to Arduino pin 3.
In the code below, I am not trying to send information back and forth. I just want to know if I received anything on the Arduino.
Python Code:
#!/usr/bin/env python3
import serial
rs = serial.Serial(
port="/dev/ttyUSB0",
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0,
rtscts = True
)
if (rs.isOpen() == True):
rs.close()
rs.open()
rs.reset_input_buffer()
outstr = "5"
rs.write(outstr.encode(encoding = 'ascii'))Arduino Code:
void setup() {
Serial3.begin(9600);
Serial.begin(9600);
pinMode(3, OUTPUT); //Set enable pin as Output
pinMode(3, LOW); //Allows MAX485 to recieve
Serial.println("Engaged.");
}
void loop() {
while(Serial3.available()){
Serial.println("We got somethin"); //Lets me know if I somehow got something
if(Serial3.available()){
byte data = Serial3.read();
Serial.println(data);
}
}
}I have multiples of each MAX485 chip and USB to RS485 adapters, and have tried using them in case something was broken inside the devices. No change.
Thoughts?