Arduino to Arduino Serial Communication

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Arduino to Arduino Serial Communication

Postby Aluman000 » Thu Nov 15, 2012 7: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
#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
#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 3:27 pm

Re: Arduino to Arduino Serial Communication

Postby adafruit_support_bill » Thu Nov 15, 2012 7:48 am

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

Re: Arduino to Arduino Serial Communication

Postby tldr » Thu Nov 15, 2012 8: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
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: 355
Joined: Thu Aug 30, 2012 12:34 am

Re: Arduino to Arduino Serial Communication

Postby tastewar » Thu Nov 15, 2012 9:09 am

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

Re: Arduino to Arduino Serial Communication

Postby Aluman000 » Thu Nov 15, 2012 1: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 3:27 pm

Re: Arduino to Arduino Serial Communication

Postby adafruit_support_bill » Thu Nov 15, 2012 3: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: 16072
Joined: Sat Feb 07, 2009 9:11 am

Re: Arduino to Arduino Serial Communication

Postby tastewar » Thu Nov 15, 2012 3: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: 204
Joined: Thu Mar 17, 2011 9:16 am

Re: Arduino to Arduino Serial Communication

Postby Aluman000 » Thu Nov 15, 2012 5: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 3:27 pm

Re: Arduino to Arduino Serial Communication

Postby AKSoapy29 » Thu Nov 15, 2012 6: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: 24
Joined: Sat Jan 07, 2012 5:56 pm
Location: http://aksoapy29.comoj.com

Re: Arduino to Arduino Serial Communication

Postby adafruit_support_bill » Fri Nov 16, 2012 5: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: 16072
Joined: Sat Feb 07, 2009 9:11 am

Re: Arduino to Arduino Serial Communication

Postby Aluman000 » Fri Nov 16, 2012 6: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 3:27 pm

Re: Arduino to Arduino Serial Communication

Postby Zener » Sun Nov 18, 2012 10:18 pm

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

Re: Arduino to Arduino Serial Communication

Postby mobilegps » Wed Nov 21, 2012 3:49 am

Hey mate,

Can you try lower baud rate like 9600 ?

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

Re: Arduino to Arduino Serial Communication

Postby Aluman000 » Sat Dec 01, 2012 12:26 pm

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

RECEIVING
Code: Select all
#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
#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 3:27 pm


Return to General Project help

Who is online

Users browsing this forum: briedy, mibignistinly and 9 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [108]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[31]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[34]
LCDs & Displays[48]
Components & Parts[70]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[111]
 
Wireless[14]
Cables[62]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]
cron