Some basic rs485 help.

I've tried several wiring configurations and example sketches, but I'm not able to get anything useful when it comes to rs485.

The latest example I followed is this guide
https://arduino-info.wikispaces.com/SoftwareSerialRS485Example
with two Megas and these rs485 boards...
http://www.ebay.com/itm/5PCS-MAX485-RS-485-Module-TTL-to-RS-485-module-for-Arduino-Raspberry-pi-N122-/401251155592?hash=item5d6c6ebe88:g:oR8AAOSwHnFVl81j

There is some debate about whether the A and B need to crossover. I think they would have to.

After following the example and trying the serial monitor at 4800 and 9600, the "master" mega shows up with
YourDuino.com SoftwareSerial remote loop example
Use Serial Monitor, type in upper window, ENTER

but then when I type in the window, I get gobblygook in the master serial monitor.

Over on the slave side, I get
SerialRemote

but nothing shows up on either serial monitor if I type over there.

For clarification, here's my code.
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 SSerialTxControl 3   //RS485 Direction control

#define RS485Transmit    HIGH
#define RS485Receive     LOW

#define Pin13LED         13

/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX

/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;

void setup()   /****** SETUP: RUNS ONCE ******/
{
  // Start the built-in serial port, probably to Serial 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(SSerialTxControl, OUTPUT);    
  
  digitalWrite(SSerialTxControl, RS485Receive);  // 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())
  {
    byteReceived = Serial.read();
    
    digitalWrite(SSerialTxControl, RS485Transmit);  // Enable RS485 Transmit   
    RS485Serial.write(byteReceived);          // Send byte to Remote Arduino
    
    digitalWrite(Pin13LED, LOW);  // Show activity    
    delay(10);
    digitalWrite(SSerialTxControl, RS485Receive);  // Disable RS485 Transmit       
  }
  
  if (RS485Serial.available())  //Look for data from other Arduino
   {
    digitalWrite(Pin13LED, HIGH);  // Show activity
    byteReceived = RS485Serial.read();    // Read received byte
    Serial.write(byteReceived);        // Show on Serial Monitor
    delay(10);
    digitalWrite(Pin13LED, LOW);  // Show activity   
   }  

}//--(end main loop )---

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 SSerialTxControl 3   //RS485 Direction control
#define RS485Transmit    HIGH
#define RS485Receive     LOW

#define Pin13LED         13

/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX

/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;

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(SSerialTxControl, OUTPUT);  
  
  digitalWrite(SSerialTxControl, RS485Receive);  // Init Transceiver
  
  // Start the software serial port, to another device
  RS485Serial.begin(4800);   // set the data rate 
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  //Copy input data to output  
  if (RS485Serial.available()) 
  {
    byteSend = RS485Serial.read();   // Read the byte 
    
    digitalWrite(Pin13LED, HIGH);  // Show activity
    delay(10);              
    digitalWrite(Pin13LED, LOW);   
    
    digitalWrite(SSerialTxControl, RS485Transmit);  // Enable RS485 Transmit    
    RS485Serial.write(byteSend); // Send the byte back
    delay(10);   
    digitalWrite(SSerialTxControl, RS485Receive);  // Disable RS485 Transmit      
//    delay(100);
  }// End If RS485SerialAvailable
  
}//--(end main loop )---

Does anyone have a point in the right direction on this?

I have made zero progress on figuring out what's wrong with this sketch/setup.

What happens if you connect the Arduinos without the 485s in the cct.

Ignore this suggestion.
.

Show us your wiring.

.

Larry, I appreciate your help. Here's what I have.

2 Megas.

Both wired
vcc to 5v
gnd to gnd
R0 to Digital 10
Re/De Jumpered together to Digital 3
DI to Digital 11
I've tried
A to A
A to B

If you have a camera, take a picture of the wiring and attach it here.

.

Thanks for your continued help, Larry. I didn't use the most photogenic colors on my wiring so I tried to describe what's going on in the picture.

Hmm. It didn't like that picture. I guess that's why there is a preview button. After my 5 minute penalty, I'm trying again.

I don't see a GND going to the bottom Mega.

Annotate each wire.

.

I also struggled a lot to get them to work.

A goes to A
B goes to B

If you swap them you just get a different output, but you will get an output.

You connected the middle pins for the seconds Arduino to #2 but in your code you set it to #3. Or is that just an error in the drawing?

You need to connect the ground from the second module to the second Arduino. Not to the first.

You could also start by just connecting the Mega's without the modules.

Connect pin 10 from ARduino #1 to pin 11 on Arduino #2.
Connect pin 11 from ARduino #1 to pin 10 on Arduino #2.

Then you would know if the code is working or not.

I will give the direct connection thing a shot. I didn't know that was an option. And you're right, my drawing was off. Here's a new one with a little bit more simplified wiring and better color choices. Same results though.

Lenny....Connecting the two arduinos directly, 10 to 11 and 11 to 10 (in either direction), doesn't do anything.

I guess there's something else going on. I didn't write this code. It's the one everyone refers to when giving examples of RS485.

Where do I need to start looking in terms of diagnostics?

There should be a GND between the two Arduinos.

.

Ahh. I missed that. I'm at work at the moment, but I will give that a shot. I've powered both rs485 units from one arduino and I've powered each one from its own arduino, but never did ground to ground.

So physically take a wire and put it from ground on one arduino to ground on the other? I'll give that a whirl!

I added a ground but it didn't make any difference. Same behavior. I'm beyond confused.

I thought I might have had a bad arduino or something, so I started from scratch. Two new ones out of the package. Hooked them up orignally with the 0/1 "Standard" crossover and they were able to talk to each other.

Rewired them both back to the rs485. If I type into the master, I get gobblygook in the serial window of the master. Nothing goes to slave. If I type in the slave serial window, nothing happens again.

Note that the code says something about serial speed being 4800 but if I set it to that, the
YourDuino.com SoftwareSerial remote loop example
Use Serial Monitor, type in upper window, ENTER

that was clear turns to gobblygook.

Please advise.

For good measure I switched out both rs485 modules for new ones. Same result.

A and B are the polarity, it is a differential signal e.g. the one signal has two wires with opposite polarity (do not cross them since that will end the world).

Test it with a LED and a resistor on the RO pin of one of the transceivers. Tie that transceiver nRE (n = not) pin low (0V) to enable the receiver, also tie its DE pin low to disable its transmitter. On the other transceiver without the LED connect the nRE pin high to disable the receiver (actually this can be a don't care, or even for another LED). Tie the DE pin high to enable the transmitter, and now you can toggle the transmitter input DI high and low to see if the LED receives it.

Once you see that working then it is time to play with software and the Arduino.

LarryD:
There should be a GND between the two Arduinos.

I don't think a common ground is needed to make it to work. See for example this:

http://forum.arduino.cc/index.php?topic=155177.msg1163350#msg1163350

Mudmin use this code for testing. Remove the Max485.

Connect pin 4 from Arduino #1 to pin 5 on Arduino #2.

Connect pin 5 from Arduino #1 to pin 4 on Arduino #2.

Master code:

#include <SoftwareSerial.h>

SoftwareSerial swSer(5, 4); //RO, DI

int incomingbyte1 = 0;

int MAX = 0;

void setup() {
  pinMode(MAX, OUTPUT); 
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(MAX, LOW);
  Serial.begin(9600);
  swSer.begin(9600);

  Serial.println("\nSoftware serial test started");


}

void loop() {
  digitalWrite(MAX, LOW);
  if (swSer.available() > 0) {
    incomingbyte1 = swSer.read();
   
    Serial.println(incomingbyte1, DEC);


  


}
}

Slave code:

#include <SoftwareSerial.h>
SoftwareSerial swSer(5, 4); //RO, DI  (RX, TX)
int MAX = 0;


void setup() {
  pinMode(MAX, OUTPUT);
  digitalWrite(MAX, HIGH);
  Serial.begin(115200);
  swSer.begin(9600);
  
}

void loop() {
  digitalWrite(MAX, HIGH);
  swSer.print('A');
  delay(1000);

}

If you get this to work, then you can add the module and test it with this code. Make sure to change the line "
int MAX = 0;" to match with the port you connected RE/DE to.

I get nothing between the two of them

One of them says "Software serial test started"

The slave says nothing. I feel like this is arduino 101 and I have no idea why it's not working. I did this one with two more brand new megas.