go_away

Author Topic: Need help adding GPS to arduino XBee Transmitter and reciever  (Read 1663 times)

0 Members and 1 Guest are viewing this topic.

Offline WesleyTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Need help adding GPS to arduino XBee Transmitter and reciever
« on: November 11, 2011, 05:10:41 AM »
Hi I'm trying to add a GPS in the code of the RX but i get problems and errors with software serial. De sketches i have written work on arduino mega2560 for the TX ( xbee programmed as router/end device AT (BD38400) , the RX sketch is for a arduino Uno ( Xbee programmed as coordinator AT(BD38400).
« Last Edit: November 17, 2011, 06:30:02 PM by Wesley »

Offline WesleyTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Need help adding GPS to arduino XBee Transmitter and reciever
« Reply #1 on: November 11, 2011, 05:11:42 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;
  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;
};

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(2000);
 
}

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;
 

 
 
 

}
  //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-50;
  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;
}
« Last Edit: November 11, 2011, 05:19:05 AM by Wesley »

Offline WesleyTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Need help adding GPS to arduino XBee Transmitter and reciever
« Reply #2 on: November 11, 2011, 05:22:17 AM »
//RX
#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;
 
};

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-1032);
  txdata.gyro1 = (analogRead(2)*4-1032);
 
 
  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));
    myservo3.write(map(rxdata.servoval3, 0, 1023, 0, 179));
    myservo4.write(map(yfiltered, -80, 80, 0, 179)+20);}
   
    //delay
   
  }
 
  //delay for good measure
  delay(10);
    nieuwetijd=millis();
  cycletijd=nieuwetijd-oudetijd;
}

Offline WesleyTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Need help adding GPS to arduino XBee Transmitter and reciever
« Reply #3 on: November 11, 2011, 05:25:12 AM »
If anyone has an idea how my GPS via an additional serial port can be read on the RX,I would be grateful.

 


Get Your Ad Here

data_list