Simple Two Arduino Communication

Hi,
I am trying to make two arduinos talk to each other as easily as possible. What I want to do is have one arduino control another arduino (which is controlling an RC car's DC motors).

Ideally I would like to have each one (or at least the one from where the signals are sent) running Firmata.
My hope is that I could, for instance, set pin 6 high on the arduino I am controlling (by attaching the pin to 5v) and have pin 6 go high on the other arduino, so they are mirroring each other. Any suggestions?

Wireless is ideal here, the cheaper the better.
Thanks

The simplest means would be to wire UnitA's TX to UnitB's RX, and UnitA's RX to UnitB's TX.

Cheap ideal wireless (RF? Infrared?), over what distance?

If you want cheap RC communications between two arduinos, here is what I did. You can get radio transmitter and receiver sets for about $7, cheaper than two tin cans and a string.

I used the virtualwire example to send the word "hello". I just exchanged "hello" with the value of a pot, transmit it to the Arduino with the receiver, you have an RC control.

If your interested, I have an example transmitter, and receiver sketch I can post.

Dave

EasyTransfer acts to synchronize a data structure between two devices and would be perfect for RC. It will work if you're using serial transceivers (Xbee, Bluetooth, APC220, etc.) or can also be used on top of VirtualWire for the cheap 433MHz thingies.

Cheapest for what you want is probably 433MHz RF tranmitteres & receivers. Can be had cheaply on popular auction sites (from $2 for a tx/rx pair including postage).

IR would be cheap also with less range and mainly suiteable for indoors.

If you need longer range, things like Zigbee/xBee come into play at much higher cost.

The latest BLE modules would do a good job but I believe they can be expensive, but offer the possibility to control from newer smartphones..

Thank you but will these solutions work if the two boards are running firmata? I a, planning to send signals on the boards and they'd each be running firmata. (That way I can just set pin. 5 as an input, apply 5v to it and have pin5 on the other board be set hi. The range doesn't need to be much, it just can't be wired. Any suggestions here?

Sorry, I have no experience with firmata, but you may find it very easy to do it without Firmata on Arduino, using examples available online.

xBee (Zigbee) radio devices have this type of functionality built in without requiring an Arduino or other MCU.

I can teach an Arduino to fly and airplane, but I haven't been able to get Firmata to work. From what I read, Firmata uses serial connection between a PC and the Arduino, my first guess would be it wouldn't work, but I also don't have any experience with it.

Dave

GunnerCAF:
If you want cheap RC communications between two arduinos, here is what I did. You can get radio transmitter and receiver sets for about $7, cheaper than two tin cans and a string.
Radio Control Planes, Drones, Cars, FPV, Quadcopters and more - Hobbyking

I used the virtualwire example to send the word "hello". I just exchanged "hello" with the value of a pot, transmit it to the Arduino with the receiver, you have an RC control.

If your interested, I have an example transmitter, and receiver sketch I can post.

Dave

Hi Dave
I would be very interested in seeing the sketches if you don't mind!!

Wes

Hi Dave
I would be very interested in seeing the sketches if you don't mind!!

Wes

Wes,

Here are the transmitter and receiver sketches. In this example, two pots are connected to the transmitter, the receiver has two LEDs. The pots will dim the leds though the radio link.

Note: I used a MEGA on the receiver. If you use an Uno, you will need to change the output pins to PWM pins on the Uno.

// transmitter.pde
//
// Simple example of how to use VirtualWire to transmit messages
// Implements a simplex (one-way) transmitter with an TX-C1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
//
// Mod: Two Sensor input (pot on A0 & A1) sent to control PWS on reciever
// Circuit: Transmitter input on pin 12, LED on pin 13 (w/330 ohm resistor),
// pot 1 center output pin to pin A0, pot 2 center output pin to pin A1.
// Mod by: Dave Gundlach, June 2013

#include <VirtualWire.h>
int sensor1Data;          // Data varable for pot 1
int sensor2Data;          // Data varable for pot 2
char sensor1Char[4];      // Charactor array for pot 1
char sensor2Char[4];      // Charactor array for pot 2
char sensor12Char[7];     // Combined array for pot 1 & 2

void setup()
{
    Serial.begin(9600);	        // Debugging only
    Serial.println("setup");
    pinMode(13, OUTPUT);        // LED output
    pinMode(A0, INPUT);         // Sensor input (pot 1)
    pinMode(A1, INPUT);         // Sensor input (pot 2)
    // Initialise the IO and ISR
    vw_set_ptt_inverted(true);  // Required for DR3100
    vw_setup(2000);	        // Bits per sec
}

void loop()
{
    sensor1Data= analogRead(A0);        // read sensor (pot 1)
    sensor2Data= analogRead(A1);        // read sensor (pot 2)
    // Note: Needed values from 0-255, added 100 to values so there are
    // always 3 charactors
    sensor1Data = map(sensor1Data, 0, 1023, 100, 355);  // map sensor output
    sensor2Data = map(sensor2Data, 0, 1023, 100, 355);  // map sensor output
    itoa(sensor1Data, sensor1Char, 10);  // convert sensor data to char
    itoa(sensor2Data, sensor2Char, 10);  // convert sensor data to char
    for (int i=0; i<3; i++)
    {
      sensor12Char[i] = sensor1Char[i];  // put sensor 1 caractors in
    }
    for (int i=0; i<3; i++)
    {
      sensor12Char[i+3] = sensor2Char[i]; // put sensor 2 caractors in
    }
    sensor12Char[6] = '\0';
    Serial.println(sensor12Char);        // debug check
    
    digitalWrite(13, HIGH);               // Flash an LED to show transmitting
    vw_send((uint8_t *)sensor12Char, strlen(sensor12Char));
    vw_wait_tx();                         // Wait until the whole message is gone
    digitalWrite(13, LOW);                // turn off LED
    delay(150);                           // small delay for smooth control
}
// receiver.pde
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
//
// MOD: Two Sensor input from transmitter to control PWS on Mega pins 2 & 3
// Circuit: Reciever output to Pin 11, LEDs (w/330 ohm resistors) on PWM pins 2 & 3 
// Mod by Dave Gundlach, June 2013

#include <VirtualWire.h>
long timerLED;            // timer for LED on
int sensor1Data;          // Data variable for pot 1
int sensor2Data;          // Data variable for pot 2
char sensor1Char[4];      // Charactor array for pot 1
char sensor2Char[4];      // Charactor array for pot 2
void setup()
{
    Serial.begin(9600);	        // Debugging only
    Serial.println("setup");  
    pinMode(13, OUTPUT);        // Recieve LED
    pinMode(2, OUTPUT);         // PWM output from pot 1
    pinMode(3, OUTPUT);         // PWM output from pot 2

    // 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
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    if (millis() >= timerLED){            // check if LED timer has expired
        digitalWrite(13, LOW);            // turn LED off
      }
    if (vw_get_message(buf, &buflen))     // Non-blocking
    {
	int i;

        digitalWrite(13, HIGH);              // Flash a light to show received good message
        timerLED = millis()+100;             // set LED timer
	// Message with a good checksum received, dump it.
	Serial.print("Got: ");              // Debug message
	
	for (i = 0; i < 3; i++)              // convert buffer into char
	{
            sensor1Char[i] = char(buf[i]);   // pot 1 value
        }
        // Transmitter added 100 so each value will will always have 3 charactors
        sensor1Data = atoi(sensor1Char)-100;  // convert to integer and subtract 100 
        for (i = 0; i < 3; i++)
        {
            sensor2Char[i] = char(buf[i+3]);  // pot 2 value
  	}
        sensor2Data = atoi(sensor2Char)-100;  // convert to integer and subract 100
        analogWrite(2, sensor1Data);          // PWM LED for pot 1 value (mega)
        analogWrite(3, sensor2Data);          // PWM LED for pot 2 value (mega)
	Serial.print(sensor1Data);           // Debug 
	Serial.print(" ");
        Serial.print(sensor2Data);
	Serial.println("");
        //digitalWrite(13, LOW);
        
        for (i=0; i<4; i++)                    
        {
          sensor1Char[i] = 0;    // clear array
          sensor2Char[i] = 0;    // clear array
        }

    }
}

Dave

GunnerCAF:

Hi Dave
I would be very interested in seeing the sketches if you don't mind!!

Wes

Wes,

Here are the transmitter and receiver sketches. In this example, two pots are connected to the transmitter, the receiver has two LEDs. The pots will dim the leds though the radio link.

Note: I used a MEGA on the receiver. If you use an Uno, you will need to change the output pins to PWM pins on the Uno.

Dave

Thanks Dave !! Those are really neat sketches .. will be most useful !