Hello Stack Exchange community,
I am currently working on a project involving two Arduino Nano boards connected via RS485 communication using MAX485 chips. I have set up the connections between the Arduinos as per the figure provided. Additionally, I have included the master and slave code for reference.
Arduino UNO =>RS485 Module 5V =>VCC; GND =>GND; pin 0 (RX) => RO; pin 8 => RE & DE; pin 1 (TX)=> DI;
Code:
Master Code:
arduino
int Enable_pin = 8;
void setup()
{
Serial.begin(9600);
pinMode(Enable_pin, OUTPUT);
digitalWrite(Enable_pin, HIGH);
}
void loop()
{
for(uint8_t i =0;i<=99;i++)
{Serial.println(i);
delay(1000);}
}
Slave Code:
arduino
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
int Enable_pin = 8;
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire, -1);
void setup()
{
Serial.begin(9600);
pinMode(Enable_pin, OUTPUT);
digitalWrite(Enable_pin, LOW); // (LOW to receive value from Master)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(100);
display.clearDisplay();
display.display();
display.setTextColor(WHITE);
}
void loop()
{
while (Serial.available())
{
display.clearDisplay();
uint8_t PWM_master = Serial.read(); //Receive INT value from Master throught RS-485
display.setCursor(50, 30);
display.setTextSize(4);
display.print(PWM_master);
display.display();
delay(100);
}
The expected output of the system is continuous numbers from 0 to 99 displayed on an OLED screen. However, I am encountering an issue where I am receiving garbage values intermittently on the OLED display. Specifically, the garbage values are either '10' or '13'. This is puzzling as my RS485 module wires are short, and the environment is not noisy. Additionally, I am powering the setup using a laptop's USB output.
I am seeking assistance in understanding why these consistent garbage values (10 or 13) are appearing in the output. Could it be related to the code, hardware connections, or power supply? Any insights or suggestions to resolve this issue would be greatly appreciated.
Thank you in advance for your help!