Hi,
i try to do that example https://arduino-info.wikispaces.com/SoftwareSerialRS485Example
but i am getting garbage from the master serial... attached there is an image,
Does anyone know why ?
thanks
Lazaros
Hi,
i try to do that example https://arduino-info.wikispaces.com/SoftwareSerialRS485Example
but i am getting garbage from the master serial... attached there is an image,
Does anyone know why ?
thanks
Lazaros
DE (data enable) and RE (receive enable) jumpered together and to pin 3
The photo is not clear as it barely shows a small jumper wire loop between DE and RE pins at the adapter far edge.
I've used these same parts and sketch and it works fine.
so you did not use DE & RE ? or did you use different approach without jumper them toogether?
I use both DE and RE jumpered together at the adapter and a single wire to Arduino pin 3.
I was pointing out that you might not have seen the small jumper at the end of the adapter and left RE floating.
No i did jumper them together,
Here is the code that partial working
Master
/* YourDuino SoftwareSerialExample1
- Connect to another Arduino running "YD_SoftwareSerialExampleRS485_1Remote"
- Connect this unit Pins 10, 11, Gnd
- Pin 3 used for RS485 direction control
- To other unit Pins 11,10, Gnd (Cross over)
- Open Serial Monitor, type in top window.
- Should see same characters echoed back from remote Arduino
Questions: terry@yourduino.com
*/
/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX 10 //Serial Receive pin
#define SSerialTX 11 //Serial Transmit pin
#define Pin3LED 7 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*-----( Declare Variables )-----*/
int syteReceived;
int syteSend;
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to erial Monitor
Serial.begin(9600);
Serial.println("YourDuino.com SoftwareSerial remote loop example");
Serial.println("Use Serial Monitor, type in upper window, ENTER");
pinMode(Pin13LED, OUTPUT);
pinMode(Pin3LED, OUTPUT);
digitalWrite(Pin3LED, LOW); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(4800); // set the data rate
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
digitalWrite(Pin13LED, HIGH); // Show activity
if (Serial.available())
{
syteReceived = Serial.read();
digitalWrite(Pin3LED, HIGH); // Enable RS485 Transmit
RS485Serial.write(syteReceived); // Send byte to Remote Arduino
digitalWrite(Pin13LED, LOW); // Show activity
delay(10);
digitalWrite(Pin3LED, LOW); // Disable RS485 Transmit
}
if (RS485Serial.available()) //Look for data from other Arduino
{
digitalWrite(Pin13LED, HIGH); // Show activity
syteReceived = RS485Serial.read(); // Read received byte
Serial.write(syteReceived); // Show on Serial Monitor
delay(10);
digitalWrite(Pin13LED, LOW); // Show activity
}
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
//NONE
//*********( THE END )***********
slave
/* YourDuino SoftwareSerialExample1Remote
- Used with YD_SoftwareSerialExampleRS485_1 on another Arduino
- Remote: Receive data, loop it back...
- Connect this unit Pins 10, 11, Gnd
- To other unit Pins 11,10, Gnd (Cross over)
- Pin 3 used for RS485 direction control
- Pin 13 LED blinks when data is received
Questions: terry@yourduino.com
*/
/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX 10 //Serial Receive pin
#define SSerialTX 11 //Serial Transmit pin
#define Pin3LED 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*-----( Declare Variables )-----*/
int syteReceived;
int syteSend;
String d;
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(9600);
Serial.println("SerialRemote"); // Can be ignored
pinMode(Pin13LED, OUTPUT);
pinMode(Pin3LED, OUTPUT);
digitalWrite(Pin3LED, LOW); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(4800); // set the data rate
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
while (RS485Serial.available())
{
delay(3);
d = RS485Serial.readString();
if (d.indexOf("xcx") >= 0)
{
Serial.println("MOTOR is ON ");
digitalWrite(Pin13LED, HIGH);
digitalWrite(Pin3LED, HIGH); // Enable RS485 Transmit
RS485Serial.write("xxxvsd"); // Send the byte back
delay(10);
digitalWrite(Pin3LED, LOW); // Disable RS485 Transmit
// delay(100);
}// End If RS485SerialAvailable
}//--(end main loop )---
}
now i am sending the "xcx" to the master via serial and the pin13 gets high on the slave...
the problem is that the serial at the master makes some symbols as ! ! $ %^% ^#$%
why it does not write the "xxxvsd" correctly???
thanks
Lazaros
Hi.
i did a small example to find out what happening,
i am sending the analog 0 info from Master To slave, master sends 300 and slave shows 50 ! ! !
Master code
/* YourDuino SoftwareSerialExample1
- Connect to another Arduino running "YD_SoftwareSerialExampleRS485_1Remote"
- Connect this unit Pins 10, 11, Gnd
- Pin 3 used for RS485 direction control
- To other unit Pins 11,10, Gnd (Cross over)
- Open Serial Monitor, type in top window.
- Should see same characters echoed back from remote Arduino
Questions: terry@yourduino.com
*/
/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
#define SSerialRX 10 //Serial Receive pin
#define SSerialTX 11 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
void setup()
{
Serial.begin(9600);
Serial.println("YourDuino.com SoftwareSerial remote loop example");
Serial.println("Use Serial Monitor, type in upper window, ENTER");
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive);
RS485Serial.begin(4800);
}
void loop()
{
if (analogRead(0) > 10)
{
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
RS485Serial.write(analogRead(0)); // Send byte to Remote Arduino
delay(100);
Serial.print(analogRead(0));
Serial.println();
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
}
delay(4000);
}
slave code
#include <SoftwareSerial.h>
#define SSerialRX 10 //Serial Receive pin
#define SSerialTX 11 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
int bReceived;
void setup()
{
Serial.begin(9600);
Serial.println("SerialRemote");
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive);
RS485Serial.begin(4800);
}
void loop()
{
if (RS485Serial.available())
{
bReceived = RS485Serial.read(); // Read the byte
Serial.print(bReceived);
digitalWrite(Pin13LED, HIGH); // Show activity
delay(3000);
digitalWrite(Pin13LED, LOW);
}
}
images attached ! ! !
Please help
Thanks
I recall having problems when running the RS458 serial at 4800 baud, garbage characters. Set both boards to 9600 for the RS485 and test by sending one character only. I also found the printed character is it's ASCII code and not the original char.
Here is the code to show both the character and it's ASCII value at the receiving end.
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//Copy input data to output
if( RS485Serial.available() ) // RS485 data available
{
byteSend = RS485Serial.read(); // Read the byte
Serial.print( "Receive/Echo " ); Serial.println( (char)byteSend ); // Show char on monitor
Serial.print( "ASCII " ); Serial.println( byteSend ); // Show byte on monitor
digitalWrite( LED_PIN, HIGH ); // Show activity
delay( 100);
digitalWrite( LED_PIN, LOW );
digitalWrite( SSerialTxControl, RS485Transmit ); // Enable RS485 Transmit
delay( 1 ); // Give MAX485 chip time to switch modes
RS485Serial.write( byteSend ); // Send the byte back
delay( 100 );
digitalWrite( SSerialTxControl, RS485Receive ); // Disable RS485 Transmit
//// delay(100);
} // End If RS485SerialAvailable
} //--(end main loop )---
still did not work,
i add number 1 and get these
‡ÿBBB
in the slave monitor
SerialRemote
Receive/Echo B
ASCII 66
Receive/Echo ð
ASCII 240
Try other baud values on both boards from 1200 to 38400. Your serial monitor can run at 115200.
at 2400 works better
the only issue is that i am sending t he word hello and prints only the hel ! ! also if press 123456 it prints always the first 3 digits
any idea why?
thanks
The example accepts only one character at a time. Go back to the original sketch but ignore the comment about the pin 10/11 crossover. Pin 10 always goes to RO and pin 11 always goes to DI.
Hello,
Just trying to help you out. I had a similar issue when I was connecting my Mega 2560s with RS485s. Make sure you connect RS485's A and B common to a breadboard and not to connect it directly with another arduino's RS485.
When I was trying to communicate two Megas with RS485 connecting directly to each other, is when I had garbage values in the serial monitor.