Arduino to Arduino Serial Communication
Moderators: adafruit_support_bill, adafruit

Arduino to Arduino Serial Communication

by Aluman000 on Thu Nov 15, 2012 8:36 am

Ok,

This seems so simple but I just can't get it to work.
I've tried buffers and subtracting '0' and looking for '/n' and about 100 other ways to get serial communication to work.
I've tried to use .print, .println, and .write.  Nothing seems to work.
I simply am stuck.
So Please, any help.

Ok, I have 2 Uno R3s connected from pin2 to pin3.
All I want to do is send a number from one to the other.
here's my code on the sending station:
Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>

SoftwareSerial DirectConnect(2,3);

int i;

void setup()
{
  Serial.begin(57600);
  DirectConnect.begin(57600);  
} // Setup

void loop()
{
  
    
  for ( i = 1; i <= 100; i++)
  {
    
   DirectConnect.print(i);
   Serial.println(i);
   delay(50);
  
  }
  
} // Loop


and here's my code for the receiving station:
Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>

SoftwareSerial DirectConnect(2,3);

int RecVar;
void setup()
{
  Serial.begin(57600);
  DirectConnect.begin(57600);  
} // Setup

void loop()
{
  delay(50);
    
  if(DirectConnect.available())
  {
    
    RecVar = DirectConnect.read();
   Serial.println(RecVar);
  
  }
  
} // Loop


This is vastly simplified from the functions I really want to do, but I just can't get this to go.
Aluman000
 
Posts: 27
Joined: Sun Apr 10, 2011 4:27 pm

Re: Arduino to Arduino Serial Communication

by adafruit_support_bill on Thu Nov 15, 2012 8:48 am

What do you see on the Serial monitor for the receiving side?
User avatar
adafruit_support_bill
 
Posts: 31749
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino to Arduino Serial Communication

by tldr on Thu Nov 15, 2012 9:23 am

first of all, make sure you've got the boards wired in a null modem configuration with the wires between the boards. tx on one to rx on the other and vice versa. alternatively configure one board with

Code: Select all | TOGGLE FULL SIZE
SoftwareSerial DirectConnect(3,2);
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: Arduino to Arduino Serial Communication

by tastewar on Thu Nov 15, 2012 10:09 am

Do you have the grounds of both boards tied together?
tastewar
 
Posts: 352
Joined: Thu Mar 17, 2011 10:16 am

Re: Arduino to Arduino Serial Communication

by Aluman000 on Thu Nov 15, 2012 2:43 pm

Here's what my Serial Monitor Returns.
54
183
134
133
54
145
134
133
54
183
134
133
54
145
134
133
54
151
134
133
54
177
134
133
54
183
134
133
54


Though i don't have a ground between them.
How do I hook that up? Just ground to ground or is there some other pin + a command or something?

Thanks Everyone.
Aluman000
 
Posts: 27
Joined: Sun Apr 10, 2011 4:27 pm

Re: Arduino to Arduino Serial Communication

by adafruit_support_bill on Thu Nov 15, 2012 4:06 pm

You can connect the grounds with just a jumper from GND on one to GND on the other.
The numbers printing out are the numeric values of the characters you are reading in. Since you have RecVar defined as an 'int' it is printing it a a number.
User avatar
adafruit_support_bill
 
Posts: 31749
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino to Arduino Serial Communication

by tastewar on Thu Nov 15, 2012 4:55 pm

You might try .write rather than .print on your DirectConnect. On the receive side, when printing to the serial monitor, you might do Serial.println(RecVar,DEC). Also, you might try using an unsigned char rather than an int.
tastewar
 
Posts: 352
Joined: Thu Mar 17, 2011 10:16 am

Re: Arduino to Arduino Serial Communication

by Aluman000 on Thu Nov 15, 2012 6:52 pm

Ok, no luck really.

First my full setup.
I have a Sending Station:
Uno R3
Powered by wall plug adapter
1 wire connecting the 3 pin to the 2 pin on the Receiving Station
1 Wire connecting the GND to the GND on the Receiving Station

I have a Receiving Station:
Uno R3
Powered via USB to computer
Connections as described above

No other connections on either Station.

The new Serial Monitor output looks like this:
56
57
57
57
57
57
57
57
57
57
57
49
49
50
51
52
53
54
55
56
57
55
55
56
56
56
56
56
56
56
56
56
56
57
57
57
57
57
57
57
57
57
57
49
49
50
51
52
53
54
55
56
57
54
55
56
57
49
48
49
49
49
50
49
51
49
52
49
53
49
54
49
55
49
56
49
57
50
48
50
49
50
50
50
51
50
52
50
53
50
54
50
55
50


Different, but still doesn't look like 1-100 repeating.  
Even if it's giving the ascii equivalent of the char they don't repeat properly, I don't think.  
I would expect every 3rd value to be the 'end' value.
Aluman000
 
Posts: 27
Joined: Sun Apr 10, 2011 4:27 pm

Re: Arduino to Arduino Serial Communication

by AKSoapy29 on Thu Nov 15, 2012 7:01 pm

There is a library to handle Arduino to Arduino communications. It is called EasyTransfer by Bill Porter.

Here is the link: http://www.billporter.info/easytransfer-arduino-library/
User avatar
AKSoapy29
 
Posts: 30
Joined: Sat Jan 07, 2012 6:56 pm
Location: http://aksoapy29.comoj.com

Re: Arduino to Arduino Serial Communication

by adafruit_support_bill on Fri Nov 16, 2012 6:54 am

All those numbers are in the range of 48-57 which is the decimal value of the ASCII digits '0'-'9'. http://www.cdrummond.qc.ca/cegep/inform ... /ascii.htm
Not sure why there are no CR/LF (13/10) characters in there. Are you still using 'println()'?
User avatar
adafruit_support_bill
 
Posts: 31749
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino to Arduino Serial Communication

by Aluman000 on Fri Nov 16, 2012 7:19 am

I'll have to try the Bill Porter Library later.
I'm using his code to handle the PS2 Controller, and the code works great...
It's just a bugger to wire it up. Very finnicky.
Thought that might be the problem here, but this is so simple, I can't imagine how

Thanks everyone for all the help.
Aluman000
 
Posts: 27
Joined: Sun Apr 10, 2011 4:27 pm

Re: Arduino to Arduino Serial Communication

by Zener on Sun Nov 18, 2012 11:18 pm

Did you ever connect the grounds together? Very important. Don't bother doing anything else until that is done.
Zener
 
Posts: 2698
Joined: Sat Feb 21, 2009 2:38 am

Re: Arduino to Arduino Serial Communication

by mobilegps on Wed Nov 21, 2012 4:49 am

Hey mate,

Can you try lower baud rate like 9600 ?

Cheers
mobilegps
 
Posts: 3
Joined: Sun Nov 11, 2012 9:16 pm

Re: Arduino to Arduino Serial Communication

by Aluman000 on Sat Dec 01, 2012 1:26 pm

Thanks Everyone.
The grounds worked.
My final code for direct connect is:

RECEIVING
Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>

SoftwareSerial DirectConnect(2,3);

int RecVar;
int input;

void setup()
{
  Serial.begin(57600);
  DirectConnect.begin(57600); 
} // Setup

void loop()
{
//  delay(50);
   
  if(DirectConnect.available())
  {
   
    RecVar = DirectConnect.read();
    Serial.println(RecVar);
    if(isDigit(RecVar))
     {
       input = (input * 10) + (RecVar - 48);
     }
    else
    {
      Serial.println(input);
      input = 0;
    }
   
  }
 
} // Loop


SENDING
Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>

SoftwareSerial DirectConnect(2,3);

int i;

void setup()
{
  Serial.begin(57600);
  DirectConnect.begin(57600); 
} // Setup

void loop()
{
 
   
  for ( i = 1; i <= 100; i++)
  {
   
   DirectConnect.print(i);
   DirectConnect.print('T');//arbitrary non-numeric
   Serial.println(i);
   
   delay(500);
   
  }
 
} // Loop
Aluman000
 
Posts: 27
Joined: Sun Apr 10, 2011 4:27 pm