Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: madsci1016 on October 12, 2011, 03:53:21 PM

Title: Help getting GPS working with Arduino radio link
Post by: madsci1016 on October 12, 2011, 03:53:21 PM
Question posted on my blog: ( I move them to SOR)

Quote
Hi Bill,
I’ve been working on a xbee RC transmitter and receiver. Its working very well with your library easy transfer. But now I am stuck trying to add a LS20031 GPS 10Hz on my receiver. I am trying to get all the information from de gps on the transmitters display . The gps is already working and is connected to the RX pin from de arduino reciever. Do you have any suggestions ?

Wesley,

To start, can you give us a better description on how you have your setup wired up? Are you using an Mega with multiple serial ports, or creating a software serial port for your GPS?
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on October 24, 2011, 03:58:25 AM
/
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on October 24, 2011, 04:04:34 AM
/
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on October 24, 2011, 04:12:54 AM
/
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on October 24, 2011, 04:34:34 AM
/
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on October 28, 2011, 08:43:56 AM
/
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on October 28, 2011, 08:45:08 AM

#include <EasyTransfer.h>
#include <LiquidCrystal.h>

  int trimvalthro=0, trimvalaile=0, trimvalelev=0, trimvalrudd=0, schermnummer;
  boolean trimbuttonthroomhoog, trimbuttonthroomlaag, trimbuttonthroomhoogPREVIOUS, trimbuttonthroomlaagPREVIOUS;
  boolean trimbuttonailelinks, trimbuttonailerechts, trimbuttonailelinksPREVIOUS, trimbuttonailerechtsPREVIOUS;
  boolean trimbuttonelevomhoog, trimbuttonelevomlaag, trimbuttonelevomhoogPREVIOUS, trimbuttonelevomlaagPREVIOUS;
  boolean trimbuttonruddlinks, trimbuttonruddrechts, trimbuttonruddlinksPREVIOUS, trimbuttonruddrechtsPREVIOUS;
long unsigned int oudetijd, nieuwetijd, cycletijd;

LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
EasyTransfer ETin, ETout;

struct RECEIVE_DATA_STRUCTURE{
 
  int temp,gyro,gyro1,cycletijdontvanger;
};

struct SEND_DATA_STRUCTURE{
 
 int temp,gyro,gyro1,cycletijdontvanger;
  int servoval, servoval1, servoval2, servoval3,servoval4;
 
};


RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;


void setup(){
  Serial.begin(38400);
 
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);
 
  pinMode(37, INPUT);
  pinMode(35, INPUT);
  pinMode(33, INPUT);
  pinMode(31, INPUT);
  pinMode(29, INPUT);
  pinMode(27, INPUT);
  pinMode(25, INPUT);
  pinMode(23, INPUT);
 
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Xbee Transmitter");
  delay(3000);
  lcd.clear();
}

void loop(){
 
 
 oudetijd=millis();
 
   // TRIM FUNCTION
 
  trimbuttonthroomhoog = digitalRead(33);
  if (trimbuttonthroomhoog==HIGH && trimbuttonthroomhoogPREVIOUS==LOW){
  ++ trimvalthro;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonthroomhoogPREVIOUS = digitalRead(33);
 
  trimbuttonthroomlaag = digitalRead(31);
  if (trimbuttonthroomlaag==HIGH && trimbuttonthroomlaagPREVIOUS==LOW){
  -- trimvalthro;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonthroomlaagPREVIOUS = digitalRead(31);
 
  trimbuttonailelinks = digitalRead(23);
  if (trimbuttonailelinks==HIGH && trimbuttonailelinksPREVIOUS==LOW){
  -- trimvalaile;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonailelinksPREVIOUS = digitalRead(23);
 
  trimbuttonailerechts = digitalRead(25);
  if (trimbuttonailerechts==HIGH && trimbuttonailerechtsPREVIOUS==LOW){
  ++ trimvalaile;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonailerechtsPREVIOUS = digitalRead(25);
 
  trimbuttonruddlinks = digitalRead(37);
  if (trimbuttonruddlinks==HIGH && trimbuttonruddlinksPREVIOUS==LOW){
  -- trimvalrudd;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonruddlinksPREVIOUS = digitalRead(37);
 
  trimbuttonruddrechts = digitalRead(35);
  if (trimbuttonruddrechts==HIGH && trimbuttonruddrechtsPREVIOUS==LOW){
  ++ trimvalrudd;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonruddrechtsPREVIOUS = digitalRead(35);
 
trimbuttonelevomhoog = digitalRead(27);
  if (trimbuttonelevomhoog==HIGH && trimbuttonelevomhoogPREVIOUS==LOW){
  ++ trimvalelev;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonelevomhoogPREVIOUS = digitalRead(27);
 
  trimbuttonelevomlaag = digitalRead(29);
  if (trimbuttonelevomlaag==HIGH && trimbuttonelevomlaagPREVIOUS==LOW){
  -- trimvalelev;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonelevomlaagPREVIOUS = digitalRead(29);
 
 

  //Display function can be changed with analogpot connected to arduino analog input 4!!!
 
  schermnummer= map(analogRead(4),0,1024,1,6);
    switch (schermnummer){
      case 1:{
  lcd.clear(); 
  lcd.setCursor(0, 0);
  lcd.print("CH1");
  lcd.setCursor(0, 8);
  lcd.print("CH2");
  lcd.setCursor(8, 0);
  lcd.print("CH3");
  lcd.setCursor(8, 1);
  lcd.print("CH4");
  int servoval = (map(analogRead(0),0,1024,0,90))+trimvalaile-44;//
  lcd.setCursor(3, 0);
  lcd.print(" ");
  lcd.print(servoval);
  lcd.setCursor(7, 0);
  lcd.print(" ");
  int servoval1 = (map(analogRead(1),0,1024,0,90))+trimvalthro-41;
  lcd.setCursor(3, 1);
  lcd.print(" ");
  lcd.print(servoval1);
  lcd.setCursor(7, 1);
  lcd.print(" ");
  int servoval2 = (map(analogRead(2),0,1024,0,90))+trimvalelev-44;
  lcd.setCursor(12, 0);
  lcd.print(" ");
  lcd.print(servoval2);
  lcd.setCursor(16, 0);
  lcd.print(" ");
  int servoval3 = (map(analogRead(3),0,1024,0,90))+trimvalrudd-45;
  lcd.setCursor(12, 1);
  lcd.print(" ");
  lcd.print(servoval3);
  lcd.setCursor(16, 1);
  lcd.print(" ");}
 break;

 case 2:{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Gyro");
  lcd.setCursor(0, 1);
  lcd.print(rxdata.gyro);
  lcd.setCursor(8, 1);
  lcd.print(rxdata.gyro1);}
 break;


case 3:{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Temperature");
  lcd.setCursor(0, 1);
  lcd.print(rxdata.temp);}
  break;
 

case 4:{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Cycletijd");
    lcd.setCursor(0, 1);
  lcd.print(cycletijd);}
 break;
 
case 5:{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("CycletijdRX");
    lcd.setCursor(0, 1);
  lcd.print(rxdata.cycletijdontvanger);}
 break;
 

}
  //then we will go ahead and send that data out
  ETout.sendData();
 
  txdata.servoval = (map(analogRead(0),300,824,0,1024))+trimvalaile+100;
  txdata.servoval1 = (map(analogRead(1),300,824,1024,0))+trimvalthro;
  txdata.servoval2 = (map(analogRead(2),300,824,1024,0))+trimvalelev;
  txdata.servoval3 = (map(analogRead(3),300,824,1024,0))+trimvalrudd;
  txdata.servoval4 = (map(analogRead(0),300,824,0,1024))+trimvalaile+100;
 
  for(int i=0; i<5; i++){
    //remember, you could use an if() here to check for new data, this time it's not needed.
    ETin.receiveData();
   
   
 

  }
 
  //delay for good measure
delayMicroseconds(7800);
  nieuwetijd=millis();
  cycletijd=nieuwetijd-oudetijd;
}
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on October 28, 2011, 08:46:19 AM
#include <Servo.h>
#include <EasyTransfer.h>
long unsigned int oudetijd, nieuwetijd, cycletijd;
EasyTransfer ETin, ETout;

Servo myservo, myservo1, myservo2, myservo3,myservo4;

struct RECEIVE_DATA_STRUCTURE{
 
  int temp,gyro,gyro1,cycletijdontvanger;
  int servoval, servoval1,servoval2,servoval3,servoval4;
 
};
struct SEND_DATA_STRUCTURE{
 
  int temp,gyro,gyro1,cycletijdontvanger;
};

RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;


void setup(){
  Serial.begin(38400);
 
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);
   
  myservo.attach(9);
  myservo1.attach(10);
  myservo2.attach(8);
  myservo3.attach(7);
  myservo4.attach(6);

}

void loop(){
  oudetijd=millis();
  if (Serial.available())
  {
      Serial.print(Serial.read(), BYTE);
  }
 
 //then we will go ahead and send that data out
  ETout.sendData();
  txdata.cycletijdontvanger = cycletijd;
  txdata.temp = (map(analogRead(0),0,1024,0,50));
  txdata.gyro = (analogRead(1));
  txdata.gyro1 = (analogRead(2));
 
  for(int i=0; i<5; i++){
    //remember, you could use an if() here to check for new data, this time it's not needed.
    ETin.receiveData();
   
   
   
    myservo.write(map(rxdata.servoval, 0, 1023, 0, 179));//
    myservo1.write(map(rxdata.servoval1, 0, 1023, 0, 179));//
    myservo2.write(map(rxdata.servoval2, 0, 1023, 0, 179));
    myservo3.write(map(rxdata.servoval3, 0, 1023, 0, 179));
    myservo4.write(map(rxdata.servoval4, 0, 1023, 0, 179));
   
   
    //delay
    delay(2);
  }
 
  //delay for good measure
  delay(2);
    nieuwetijd=millis();
  cycletijd=nieuwetijd-oudetijd;
}
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on October 28, 2011, 08:55:11 AM
Photo of TX
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on October 28, 2011, 08:56:14 AM
Photo
Title: Re: Help getting GPS working with Arduino radio link
Post by: madsci1016 on October 28, 2011, 09:39:39 AM
Wesley I haven't forgotten about you. I've put 110 hours on my last time card, if that gives you any idea of how busy I have been at work. I was hoping someone else might be able to help, but if not I'll try to look through your code this weekend.

-Bill Porter
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on October 28, 2011, 10:21:27 AM
Thanks Bill,  I almost finished the sketch with accelerometer in the receiver.
Only the gps white a second serial on the uno still giving me trouble and interrupts.

Greetings Wesley
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on November 02, 2011, 08:08:36 AM
Hi all,
 I have the sketch completed with accelerometer.
 A switch to digital input 45 ( high or low) gives you the choice to switch between accelerometer or analog input.
Please note, this is mainly the circuit and not a full autopilot!!!
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on November 02, 2011, 08:09:27 AM
//TX
#include <EasyTransfer.h>
#include <LiquidCrystal.h>

  int trimvalthro=0, trimvalaile=0, trimvalelev=0, trimvalrudd=0, schermnummer;
  boolean trimbuttonthroomhoog, trimbuttonthroomlaag, trimbuttonthroomhoogPREVIOUS, trimbuttonthroomlaagPREVIOUS;
  boolean trimbuttonailelinks, trimbuttonailerechts, trimbuttonailelinksPREVIOUS, trimbuttonailerechtsPREVIOUS;
  boolean trimbuttonelevomhoog, trimbuttonelevomlaag, trimbuttonelevomhoogPREVIOUS, trimbuttonelevomlaagPREVIOUS;
  boolean trimbuttonruddlinks, trimbuttonruddrechts, trimbuttonruddlinksPREVIOUS, trimbuttonruddrechtsPREVIOUS;
  boolean autopilotswitch;
long unsigned int oudetijd, nieuwetijd, cycletijd;

LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
EasyTransfer ETin, ETout;

struct RECEIVE_DATA_STRUCTURE{
 
  int temp,gyro,gyro1,cycletijdontvanger,x,y,z;
};

struct SEND_DATA_STRUCTURE{
 
 int temp,gyro,gyro1,cycletijdontvanger,autopilot;
  int servoval, servoval1, servoval2, servoval3,servoval4;
 
};


RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;


void setup(){
  Serial.begin(38400);
 
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);
 
   pinMode(45, INPUT);
  pinMode(37, INPUT);
  pinMode(35, INPUT);
  pinMode(33, INPUT);
  pinMode(31, INPUT);
  pinMode(29, INPUT);
  pinMode(27, INPUT);
  pinMode(25, INPUT);
  pinMode(23, INPUT);
 
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Xbee Transmitter");
  delay(3000);
  lcd.clear();
}

void loop(){
 
  autopilotswitch = digitalRead(45);
 oudetijd=millis();
 
   // TRIM FUNCTION
 
  trimbuttonthroomhoog = digitalRead(33);
  if (trimbuttonthroomhoog==HIGH && trimbuttonthroomhoogPREVIOUS==LOW){
  ++ trimvalthro;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonthroomhoogPREVIOUS = digitalRead(33);
 
  trimbuttonthroomlaag = digitalRead(31);
  if (trimbuttonthroomlaag==HIGH && trimbuttonthroomlaagPREVIOUS==LOW){
  -- trimvalthro;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonthroomlaagPREVIOUS = digitalRead(31);
 
  trimbuttonailelinks = digitalRead(23);
  if (trimbuttonailelinks==HIGH && trimbuttonailelinksPREVIOUS==LOW){
  -- trimvalaile;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonailelinksPREVIOUS = digitalRead(23);
 
  trimbuttonailerechts = digitalRead(25);
  if (trimbuttonailerechts==HIGH && trimbuttonailerechtsPREVIOUS==LOW){
  ++ trimvalaile;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonailerechtsPREVIOUS = digitalRead(25);
 
  trimbuttonruddlinks = digitalRead(37);
  if (trimbuttonruddlinks==HIGH && trimbuttonruddlinksPREVIOUS==LOW){
  -- trimvalrudd;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonruddlinksPREVIOUS = digitalRead(37);
 
  trimbuttonruddrechts = digitalRead(35);
  if (trimbuttonruddrechts==HIGH && trimbuttonruddrechtsPREVIOUS==LOW){
  ++ trimvalrudd;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonruddrechtsPREVIOUS = digitalRead(35);
 
trimbuttonelevomhoog = digitalRead(27);
  if (trimbuttonelevomhoog==HIGH && trimbuttonelevomhoogPREVIOUS==LOW){
  ++ trimvalelev;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonelevomhoogPREVIOUS = digitalRead(27);
 
  trimbuttonelevomlaag = digitalRead(29);
  if (trimbuttonelevomlaag==HIGH && trimbuttonelevomlaagPREVIOUS==LOW){
  -- trimvalelev;
  digitalWrite(13, HIGH); delay (10);} else { digitalWrite(13, LOW); }
  trimbuttonelevomlaagPREVIOUS = digitalRead(29);
 
 

  //Display function can be changed with analogpot connected to arduino analog input 4!!!
 
  schermnummer= map(analogRead(4),0,1024,1,9);
    switch (schermnummer){
      case 1:{
  lcd.clear(); 
  lcd.setCursor(0, 0);
  lcd.print("CH1");
  lcd.setCursor(0, 8);
  lcd.print("CH2");
  lcd.setCursor(8, 0);
  lcd.print("CH3");
  lcd.setCursor(8, 1);
  lcd.print("CH4");
  int servoval = (map(analogRead(0),0,1024,0,90))+trimvalaile-44;//
  lcd.setCursor(3, 0);
  lcd.print(" ");
  lcd.print(servoval);
  lcd.setCursor(7, 0);
  lcd.print(" ");
  int servoval1 = (map(analogRead(1),0,1024,0,90))+trimvalthro-41;
  lcd.setCursor(3, 1);
  lcd.print(" ");
  lcd.print(servoval1);
  lcd.setCursor(7, 1);
  lcd.print(" ");
  int servoval2 = (map(analogRead(2),0,1024,0,90))+trimvalelev-44;
  lcd.setCursor(12, 0);
  lcd.print(" ");
  lcd.print(servoval2);
  lcd.setCursor(16, 0);
  lcd.print(" ");
  int servoval3 = (map(analogRead(3),0,1024,0,90))+trimvalrudd-45;
  lcd.setCursor(12, 1);
  lcd.print(" ");
  lcd.print(servoval3);
  lcd.setCursor(16, 1);
  lcd.print(" ");}
 break;

 case 2:{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Gyro");
  lcd.setCursor(0, 1);
  lcd.print(rxdata.gyro);
  lcd.setCursor(8, 1);
  lcd.print(rxdata.gyro1);}
 break;


case 3:{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Temperature");
  lcd.setCursor(0, 1);
  lcd.print(rxdata.temp);}
  break;
 

case 4:{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Cycletijd");
    lcd.setCursor(0, 1);
  lcd.print(cycletijd);}
 break;
 
case 5:{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("CycletijdRX");
    lcd.setCursor(0, 1);
  lcd.print(rxdata.cycletijdontvanger);}
 break;
 
 case 6:{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("X    Y    Z");
  lcd.setCursor(0, 1);
  lcd.print(rxdata.x);
  lcd.setCursor(4, 1);
  lcd.print(rxdata.y);
  lcd.setCursor(8, 1);
  lcd.print(rxdata.z);}
 break;
 
 case 7:{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("AUTOPILOT");
  lcd.setCursor(0, 1);
  lcd.print(txdata.autopilot);}
 break;
 

}
  //then we will go ahead and send that data out
  ETout.sendData();
 
  txdata.servoval = (map(analogRead(0),300,824,0,1024))+trimvalaile+100;
  txdata.servoval1 = (map(analogRead(1),300,824,1024,0))+trimvalthro;
  txdata.servoval2 = (map(analogRead(2),300,824,1024,0))+trimvalelev;
  txdata.servoval3 = (map(analogRead(3),300,824,1024,0))+trimvalrudd;
  txdata.servoval4 = (map(analogRead(0),300,824,0,1024))+trimvalaile+200;
 
  if (autopilotswitch==HIGH){txdata.autopilot = 100;}
  if (autopilotswitch==LOW){txdata.autopilot = 0; }
 
  for(int i=0; i<5; i++){
    //remember, you could use an if() here to check for new data, this time it's not needed.
    ETin.receiveData();
   
   
 

  }
 
  //delay for good measure
delayMicroseconds(7800);
  nieuwetijd=millis();
  cycletijd=nieuwetijd-oudetijd;
}
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on November 02, 2011, 08:10:21 AM
//RX
#include <Servo.h>
#include <EasyTransfer.h>
#include <Wire.h>
#define DEVICE (0x53)
#define TO_READ (6)

void writeTo(int device, byte address, byte val) {
   Wire.beginTransmission(device);
   Wire.send(address);       
   Wire.send(val);       
   Wire.endTransmission();
}
 
void readFrom(int device, byte address, int num, byte buff[]) {
  Wire.beginTransmission(device);
  Wire.send(address);       
  Wire.endTransmission();
 
  Wire.beginTransmission(device);
  Wire.requestFrom(device, num);   
 
  int i = 0;
  while(Wire.available())   
  {
    buff = Wire.receive();
    i++;
  }
  Wire.endTransmission();
}
 byte buff[TO_READ] ;   

long unsigned int oudetijd, nieuwetijd, cycletijd;
EasyTransfer ETin, ETout;

Servo myservo, myservo1, myservo2, myservo3,myservo4;

struct RECEIVE_DATA_STRUCTURE{
 
  int temp,gyro,gyro1,cycletijdontvanger,autopilot;
  int servoval, servoval1,servoval2,servoval3,servoval4;
 
};
struct SEND_DATA_STRUCTURE{
 
  int temp,gyro,gyro1,cycletijdontvanger,x,y,z;
};

RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;


void setup(){
  Wire.begin();
  Serial.begin(38400);
 
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);
   
   pinMode(13,OUTPUT);
  myservo.attach(9);
  myservo1.attach(10);
  myservo2.attach(8);
  myservo3.attach(7);
  myservo4.attach(6);
 
  writeTo(DEVICE, 0x2D, 0);     
  writeTo(DEVICE, 0x2D, 16);
  writeTo(DEVICE, 0x2D, 8);

}

void loop(){
  oudetijd=millis();
  int regAddress = 0x32;   
  int x, y, z;
  readFrom(DEVICE, regAddress, TO_READ, buff);
  x = (((int)buff[1]) << 8) | buff[0];   
  y = (((int)buff[3])<< 8) | buff[2];
  z = (((int)buff[5]) << 8) | buff[4];
 
  if (Serial.available())
  {
      Serial.print(Serial.read(), BYTE);
  }
 
 //then we will go ahead and send that data out
  ETout.sendData();
  txdata.cycletijdontvanger = cycletijd;
  txdata.temp = (map(analogRead(0),0,1024,0,50));
  txdata.gyro = (analogRead(1)*4);
  txdata.gyro1 = (analogRead(2)*4);
  txdata.x = (map(x,-255,255,-500,500));
  txdata.y = (map(y,-255,255,-500,500));
  txdata.z = (map(z,-255,255,-500,500));
 
  for(int i=0; i<5; i++){
    //remember, you could use an if() here to check for new data, this time it's not needed.
    ETin.receiveData();
   
   
   if (rxdata.autopilot == 0){digitalWrite(13,LOW);
   
    myservo.write(map(rxdata.servoval, 0, 1023, 0, 179));//
    myservo1.write(map(rxdata.servoval1, 0, 1023, 0, 179));//
    myservo2.write(map(rxdata.servoval2, 0, 1023, 0, 179));
    myservo3.write(map(rxdata.servoval3, 0, 1023, 0, 179));
    myservo4.write(map(rxdata.servoval4, 0, 1023, 0, 179));}
   
   if (rxdata.autopilot == 100){digitalWrite(13,HIGH);
   myservo.write(map(y, -255, 255, 0, 179));//
     myservo1.write(map(rxdata.servoval1, 0, 1023, 0, 179));//
    myservo2.write(map(x, -255, 255, 0, 179)+20);
    myservo3.write(map(rxdata.servoval3, 0, 1023, 0, 179));
    myservo4.write(map(y, -255, 255, 0, 179)+20);}
   
    //delay
    delay(2);
  }
 
  //delay for good measure
  delay(2);
    nieuwetijd=millis();
  cycletijd=nieuwetijd-oudetijd;
}
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on November 03, 2011, 05:27:56 PM
//UPDATE for the RX for more stability in the Y axis accelerometer

#include <Servo.h>
#include <EasyTransfer.h>
#include <Wire.h>
#define DEVICE (0x53)
#define TO_READ (6)
float yfiltered;
void writeTo(int device, byte address, byte val) {
   Wire.beginTransmission(device);
   Wire.send(address);       
   Wire.send(val);       
   Wire.endTransmission();
}
 
void readFrom(int device, byte address, int num, byte buff[]) {
  Wire.beginTransmission(device);
  Wire.send(address);       
  Wire.endTransmission();
 
  Wire.beginTransmission(device);
  Wire.requestFrom(device, num);   
 
  int i = 0;
  while(Wire.available())   
  {
    buff = Wire.receive();
    i++;
  }
  Wire.endTransmission();
}
 byte buff[TO_READ] ;   

long unsigned int oudetijd, nieuwetijd, cycletijd;
EasyTransfer ETin, ETout;

Servo myservo, myservo1, myservo2, myservo3,myservo4;

struct RECEIVE_DATA_STRUCTURE{
 
  int temp,gyro,gyro1,cycletijdontvanger,autopilot;
  int servoval, servoval1,servoval2,servoval3,servoval4;
 
};
struct SEND_DATA_STRUCTURE{
 
  int temp,gyro,gyro1,cycletijdontvanger,x,y,z;
 
};

RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;


void setup(){
  Wire.begin();
  Serial.begin(38400);
 
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);
   
   pinMode(13,OUTPUT);
  myservo.attach(9);
  myservo1.attach(10);
  myservo2.attach(8);
  myservo3.attach(7);
  myservo4.attach(6);
 
  writeTo(DEVICE, 0x2D, 0);     
  writeTo(DEVICE, 0x2D, 16);
  writeTo(DEVICE, 0x2D, 8);

}

void loop(){
  oudetijd=millis();
  int regAddress = 0x32;   
  int x, y, z;
  readFrom(DEVICE, regAddress, TO_READ, buff);
  x = (((int)buff[1]) << 8) | buff[0]; 
  y = (((int)buff[3])<< 8) | buff[2];
  z = (((int)buff[5]) << 8) | buff[4];
  yfiltered = yfiltered * 0.80 + y * .20;


 
  if (Serial.available())
  {
      Serial.print(Serial.read(), BYTE);
  }
 
 //then we will go ahead and send that data out
  ETout.sendData();
  txdata.cycletijdontvanger = cycletijd;
  txdata.temp = (map(analogRead(0),0,1024,0,50));
  txdata.gyro = (analogRead(1)*4);
  txdata.gyro1 = (analogRead(2)*4);
  txdata.x = (map(x,-255,255,-500,500));
  txdata.y = (map(y,-255,255,-500,500));
  txdata.z = (map(z,-255,255,-500,500));
 
  for(int i=0; i<5; i++){
    //remember, you could use an if() here to check for new data, this time it's not needed.
    ETin.receiveData();
   
   
   if (rxdata.autopilot == 0){digitalWrite(13,LOW);
   
    myservo.write(map(rxdata.servoval, 0, 1023, 0, 179));//
    myservo1.write(map(rxdata.servoval1, 0, 1023, 0, 179));//
    myservo2.write(map(rxdata.servoval2, 0, 1023, 0, 179));
    myservo3.write(map(rxdata.servoval3, 0, 1023, 0, 179));
    myservo4.write(map(rxdata.servoval4, 0, 1023, 0, 179));}
   
   if (rxdata.autopilot == 100){digitalWrite(13,HIGH);
   myservo.write(map(yfiltered, -80, 80, 0, 179));//
     myservo1.write(map(rxdata.servoval1, 0, 1023, 0, 179));//
    myservo2.write(map(x, -255, 255, 0, 179)+20);
    myservo3.write(map(rxdata.servoval3, 0, 1023, 0, 179));
    myservo4.write(map(yfiltered, -80, 80, 0, 179)+20);}
   
    //delay
    delay(2);
  }
 
  //delay for good measure
  delay(2);
    nieuwetijd=millis();
  cycletijd=nieuwetijd-oudetijd;
}
Title: Re: Help getting GPS working with Arduino radio link
Post by: Soeren on November 04, 2011, 02:12:09 PM
Hi,

Is there a reason for posting code (repeatedly) in the electronics forum rather than the software forum?
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on November 04, 2011, 08:23:20 PM
Hi, I was hoping that somebody had a solution to my problem on this forum. But apparently nobody has an answer? :'(
I stop placing sketch
 And I will find the solution myself.
Title: Re: Help getting GPS working with Arduino radio link
Post by: Soeren on November 10, 2011, 02:11:31 PM
Hi,

Hi, I was hoping that somebody had a solution to my problem on this forum. But apparently nobody has an answer? :'(
I stop placing sketch
 And I will find the solution myself.
Or, you could try posting it in the software forum, where it would be appropriate.
Cutting back to the relevant bits of code your question is about may help as well - nothing more boring than endless lists of other peoples defunct code, so if you want people to care... Make it digestible and to the point.
Title: Re: Help getting GPS working with Arduino radio link
Post by: Wesley on November 11, 2011, 05:27:47 AM
Okay, I will follow your advice and moved my sketches to the software department.

Greetings Wesley