Max485 Communication Issues

Hello,

I have an extremely simple setup to communicate between two arduino megas using some max485's and the SoftwareSerial library (Necessary because in the program this is used in, I use multiple communication lines and use the hardware serial for debugging). I've had the exact same setup work in the past, but for some reason it no longer works. I have read similar threads and none had info that helped which I had not already tried.

The arduino on the receiving end immediately freezes when the code is uploaded, and the only thing that makes it to the serial monitor is "restarted". If I spam upload, maybe 1 out of 10 times it does actually receive the message, but will sometimes double or triple it and display "#: lollollol" for example. I have tried replacing the wires and even wiggling them around while its working incase that is the issue with no change. If I run the receiver before the transmitter, it does not become stuck, but displays "#" in the serial monitor with no signal getting through. This is the only consistent behavior I have found. I have also tried swapping roles of the arduinos with no change.

Wiring diagram, except with a common ground, RO pins go to pin 10 on the arduinos, and DI pins to go pin 11 on the arduinos. The only pins used are 5v, GND, 10 and 11:
image

Receiving arduino code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);

String signal;
int i = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  mySerial.begin(9600);
  Serial.println("restarted");
}

void loop() {
  // put your main code here, to run repeatedly:
  signal = mySerial.readStringUntil('\n');
  signal.trim();
  i++;
  Serial.print(i);
  Serial.println(": " + signal);
}

Sending arduino code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  mySerial.begin(9600);
  Serial.println("restarted");
}

void loop() {
  // put your main code here, to run repeatedly:
  mySerial.println("lol");
  Serial.println("lol");
}

on the picture are other pins

you force to read a string without to check if anything there

Aside from the wiring inconsistencies already mentioned, your transmitter is likely transmitting way too frequently and swamping the receiver.

I would also suggest avoiding the use of the String class in the receiver. Use ordinary null terminated c strings instead.

You have the wires going to the right pins? 10 to 11 and 10 to 11? Consider making an accurate drawing.

Hi,
Connect the gnd of both ends together.

Tom... :grinning: :+1: :coffee: :australia:

not necessary in this case

1 Like

Why?

Tom.. :grinning: :+1: :coffee: :australia:

1 Like

wires are not long and GND is not used for data transfer in comparison to U(S)ART

Thank you for the suggestions everyone. It turns out very specific pins have to be what travel over long distances. I had to switch RX and TX with A and B.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.