Arduino to Arduino Direct Communication

Hi all,

I'm new to the Forum. I've been having some trouble setting up a direct communication link between two Arduino Duemilanoves. I downloaded the Virtual Wire library because it gives examples of such communication. In my project, I already have one RF transmitter and receiver implemented between the main Arduino and a third Arduino. I have a deadline, so I cannot order any new parts, such as the Mega. I tried directly connecting the power, ground, and corresponding pins into the Arduinos, but the LED 13 will not respond on the receiving Arduino. The light does flash on the transmitting Arduino however. The only reason I need a third Arduino is the pin space.

Here is the "client" example code

// client.pde
//
// Simple example of how to use VirtualWire to send and receive messages
// with a DR3100 module.
// Send a message to another arduino running the 'server' example, which
// should send a reply, which we will check
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: client.pde,v 1.1 2008/04/20 09:24:17 mikem Exp $

#include <VirtualWire.h>

void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");

// Initialise the IO and ISR
// vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
vw_set_tx_pin(1); //sets pin to 1
}

void loop()
{
const char *msg = "hello";
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
Serial.println("Sent");
digitalWrite(13, false);

// Wait at most 200ms for a reply
if (vw_wait_rx_max(200))
{
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;

// Message with a good checksum received, dump it.
Serial.print("Got: ");

for (i = 0; i < buflen; i++)
{
Serial.print(buf*, HEX);*

  • Serial.print(" ");*
  • }*
  • Serial.println("");*
  • }*
  • }*
  • else*
  • Serial.println("Timout");*

}
and the "Server" example Code:
// server.pde
//
// Simple example of how to use VirtualWire to send and receive messages
// with a DR3100 module.
// Wait for a message from another arduino running the 'client' example,
// and send a reply.
// You can use this as the basis of a remote control/remote sensing system
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: server.pde,v 1.1 2008/04/20 09:24:17 mikem Exp $
#include <VirtualWire.h>
void setup()
{

  • Serial.begin(9600); // Debugging only*

  • Serial.println("setup");*

  • // Initialise the IO and ISR*

  • // vw_set_ptt_inverted(true); // Required for DR3100*

  • vw_setup(2000); // Bits per sec*

  • vw_rx_start(); // Start the receiver PLL running*

  • vw_set_rx_pin(2); //sets pin to 0*
    }
    void loop()
    {
    _ const char *msg = "hello";_

  • uint8_t buf[VW_MAX_MESSAGE_LEN];*

  • uint8_t buflen = VW_MAX_MESSAGE_LEN;*

  • // Wait for a message*

  • vw_wait_rx();*

  • if (vw_get_message(buf, &buflen)) // Non-blocking*

  • {*

  • int i;*
    _ const char *msg = "goodbye";_

  • digitalWrite(13, true); // Flash a light to show received good message*

  • // Message with a good checksum received, dump it.*

  • Serial.print("Got: ");*

  • for (i = 0; i < buflen; i++)*

  • {*
    _ Serial.print(buf*, HEX);_
    _
    Serial.print(" ");_
    _
    }_
    _
    Serial.println("");_
    _
    // Send a reply*_
    vw_send((uint8_t )msg, strlen(msg));
    _
    digitalWrite(13, false);_
    _
    }_
    _
    }*_
    I'm pretty new at this, so it may be simple circuit errors. If yall could help me with the above programs, or if you know a better way to connect two Arduinos in a hurry please let me know!
    Thanks

Do the connection between the 'added IO' arduino and the 'main' to be wireless? If not, just connect Tx from 1 to Rx on the other, and Rx to Tx, then do serial messages back & forth.

Any reason you changed from the default pins 11 & 12 for VirtualWire?

No, no particular reason. If I did leave them the default pins, Which pins would I attach between the Added IO Arduino and the Main Arduino?

RX/Tx & Tx/Rx: D0 to D1, D1 to D0.

Thank you! the program is working now. Is there a simpler program out there for this than the VIrtualWire example? I need to receive about ten different signals from the Main Arduino to allow the added IO Arduino to do the right thing. Is it possible to connect these without the VirtualWire Library? I'm sorry if this is trivial, I'm not very well-versed in the language.

Simpler? Not that works as well for RF with the inexpensive RF modules.

What are the 10 signals? Like button presses & things?

The only thing I am hooking up to the extra Arduino is a VoiceBox that will "speak" the color that a sensor on the main Arduino reads. I just need it to read different signals for each color the Arduino is sensing. Basically, I will wens a different signal for each color I sense.

Each color gets its own signal line? Or that will be sent over the serial link?

Over a serial link. I was planing on setting up "if" statements depending on what Serial Communication I send for a corresponding color. For example,

if(IO Arduino reads "pink") {
say("pink")
}

That seems reasonable.
Can send over 0 every 100mS or so, if the color changes then send 1 to 15 instead.
On the receive side, use switch:case statements:

if (Serial.available() > 0)
{ // have a  message coming in

  colorbyte = Serial.read();

switch (colorbyte){
case 0:
// do nothing, just a keep alive message
break;
case 1:
// code to say color1
break;
case 2:
// code to say color2
break;
//etc.
}  // end of switch
}  // end of if statement

What's the plan for creating audio?

I have a VoiceBox shield with SpeakJet on it. It's been working fairly well; it just sounds really robotic.

Well, you could get creative: add an SD card, use your PC to capture spoken voices, then read those out and play them back thru a D/A converter and op amp with low pass filtering (RC circuit) to take out any switching noise, end up with higher quality output depending on the # of bits of sampling and the sampling rate.
There are a lot of serial D/A converters you could do that with.

I don't have time to implement that before my deadline on Wednesday, but that is an excellent idea! I will definitely include it in the improvements we could have made to our project.

Could you help me with another problem? My color sensor is on the fritz. I wrote this program for the TCS320DB color sensor from parallax as there were no other examples available. I'm sure it is wired correctly, and I have tried to take out the S0 and S1 outputs. It only works every now and then. Lately it has only been reading the "GREENduration", and even then there is no variation in the frequency. This is the code.

[/*optimal distance for calibration is 2.5 in*/
int Out = 13;                 //C Input "the Read"?
int S0= 8;                 //A Output
int S1 = 9;                //B Output
int S2= 10;                  //E Output
int S3 = 12;                 //F Output
int LED = 11;                 //D Output-turns on LEDS

unsigned long REDduration;
unsigned long GREENduration;
unsigned long BLUEduration;
unsigned long CLEARduration;


void setup () {
 pinMode(LED,OUTPUT);
 pinMode(Out,INPUT);
 pinMode(S0,OUTPUT);
 pinMode(S1,OUTPUT);
 pinMode(S2,OUTPUT);
 pinMode(S3,OUTPUT);
 digitalWrite(LED, HIGH);
 Serial.begin(9600);
}

void loop () {
  digitalWrite(S0,HIGH);
  digitalWrite(S1,HIGH);
  color ();
  Serial.print("R");
  Serial.println(REDduration);
  Serial.print("G");
  Serial.println(GREENduration);
  Serial.print("B");
  Serial.println(BLUEduration);
  Serial.print("C");
  Serial.println(CLEARduration);
}

void color () {
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
 REDduration= pulseIn(Out,HIGH);
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
 BLUEduration= pulseIn(Out,HIGH);
digitalWrite(S2,HIGH);
digitalWrite(S3,LOW);
 CLEARduration= pulseIn(Out,HIGH);
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
 GREENduration= pulseIn(Out,HIGH);

}]

The specs on the color sensor can be found at:
http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/TCS3200_doc.pdf

Have you tried slowing the output down, with S0 or S1 Low instead?
pulseIn only works down to 10uS (100KHz), the data sheet says the output waveform can be much higher frequency than that.

Yes, I tried that. Thank you. They are giving out consistent readings now :slight_smile:

Cool.

I tried all combinations of S0 and S1 HIGH LOW sequences, but nothing worked. Some sequences only gave me two out of the four durations, but each trial only gave me garbage readings.

ok, so now I am just trying to send serial data from the main arduino to the extra arduino. I have tx to rx and rx to tx connections appropriately wired and I have I/O pin 3 connected on both controllers. I troubleshooted connecting the grounds together to give the boards a reference voltage, but still no luck. Below are my programs. Both microcontrollers are Duemilanoves.

Main Arduino Program

[#include <SoftwareSerial.h>

SoftwareSerial message = SoftwareSerial(4,3);//rx,tx

 
int colorbyte = 1;
void setup() {
  pinMode(1,OUTPUT);
  pinMode(3,OUTPUT);
  Serial.begin(9600);
  message.begin(9600);
}

void loop() {
  Serial.print(colorbyte);
  message.print(colorbyte);
  delay(1000);
}]


This is the receiver code
[code][#include <SoftwareSerial.h>


SoftwareSerial message = SoftwareSerial(3,4);//rx tx

int colorbyte = 0;

void setup(){
  pinMode(0,INPUT);
  pinMode(3,INPUT);
  Serial.begin(9600);
  message.begin(9600);
 
 }


void loop() {


{ // have a  message coming in
//if (message.available() > 0) {
  colorbyte = message.read();
  Serial.println(colorbyte);
  delay(1000);]


My serial monitor is converting it into analog, but I can't figure out what it's reading. It initially says 255, but then after that it displays a steady stream of "49".

If you know anything to help or have any advice please let me know!

[/code]

You can't have serial.begin going and use pins 0,1 for software serial, the hardware UART then fights with software serial for pin usage.