Wireless communication?


I’m trying to control a robot with a remote that uses a joystick and a gyro scope. I’m having a hard time getting readable values. I took the idea from the arduino cookbook where they send the pin values with a comma to separate them and then use serialparseint to separate them but my values are not coming out on the serial monitor. I am just wondering if there is a simple way to send multiple values at once. I am doing this from my phone but can post my code if needs be. Thank you.

Sender (Using Arduino Uno and an Xbee Shield)

#include <SPI.h> // Included for SFE_LSM9DS0 library
#include <Wire.h>
//#include <SoftwareSerial.h>
#include <SFE_LSM9DS0.h>
#define LSM9DS0_XM  0x1D // Would be 0x1E if SDO_XM is LOW
#define LSM9DS0_G   0x6B // Would be 0x6A if SDO_G is LOW
#define PRINT_SPEED 50

const int VERT = 0; // analog
const int HORIZ = 1; // analog
const int SEL = 7; // digital
int pwr = 13;//power led
float x;//x gyroscope
float y;//y gyroscope
float z;//z gyroscope
float pitch, roll;//calculate the pitch and the roll
int p, r;//convert the pitch and roll to integers

//SoftwareSerial Xbee(2,3);

void setup() {

uint16_t status = dof.begin();



void loop() {

int vertical, horizontal, select;  
//Take accelerometor readings
x = dof.calcAccel(dof.ax);
y = dof.calcAccel(dof.ay);
z = dof.calcAccel(dof.az);
//Calculate the pitch and the roll  
pitch = atan2(x, sqrt(y * y) + (z * z));
roll = atan2(y, sqrt(x * x) + (z * z));
pitch *= 180.0 / PI;
roll *= 180.0 / PI;
//Map the pitch and the roll
pitch = map(pitch,-90,90,0,180);//Makes it so I am not sending a negative number
roll = map(roll,-90,90,0,180);//Ditto
p = round(pitch);//turns the float into an integer
r= round(roll);//turns the float into an integer
vertical = analogRead(VERT); // will be 0-1023
horizontal = analogRead(HORIZ); // will be 0-1023
select = digitalRead(SEL); // will be HIGH (1) if not pressed, and LOW (0) if pressed
vertical = map(vertical,0,1023,0,255);//Makes it so the data can be sent by ASCII
horizontal = map(horizontal,0,1023,0,255);//Ditto




Reciever Code Arduino Mega

//#include <SoftwareSerial.h>

//SoftwareSerial xbee(2,3);
int value[5];//an array set up to bring in the values
int index = 0;
void setup() {

void loop() {
while (Serial.available()>0){
  //char c = xbee.read();
  char c = Serial.read();//Read the data
  Serial.println(c);//Print out data to show the xbees are communicating
for (index = 0; index < 5; index++){
 value[index] = Serial.parseInt();//Skip the comma and take the next numeric value 
for (int i = 0; i < index; i++)
index = 0; //Reset the process


I don't know how you expect us to help you if you don't post your code and a schematic .
Draw a schematic and post a photo of it , along with your code and a terminal capture file of your serial
output. I assume you have debug serial prints in your code. If you are not familiar with terminal capture feature , download this program and after you connect and get some output on the screen, click "File/save to buffer" and enter a filename for the capture file.

Rather than using parseInt() you might consider the examples in serial input basics which receive all of the data first, and without blocking. There is also a parse example.

And post your code ....


Here is a printout of the serial monitor that I get from the Mega
11 92 135 123 182
92 11 182 92 135
123 18235 123 182 92
135 12892 135 123 181
26987 182 92 135 12892

I have both xbee shields switched to UART. The xbee.read/write code was from sparkfuns tutorial but I don't receive anything on the serial monitor with that code.


Thanks for the link I will be looking more into that today.

Look at EasyTransfer Arduino Library « The Mind of Bill Porter

Can't make it any simpler.

A way to receive data to control servos. You can search for joystick to see previous post for transmission ideas where the joystick analog input is mapped to servo command values. I suggest you get a wired connection working first, then switch to wireless.

//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo 

void setup() {

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control 
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
          Serial.print("writing Microseconds: ");
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
          Serial.print("writing Angle: ");
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
         readString=""; //clears variable for new input
    else {     
      readString += c; //makes the string readString