Problem sending data from GPS module to GSM module with Wire

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Xemnas442
 
Posts: 5
Joined: Mon Apr 07, 2014 4:28 am

Problem sending data from GPS module to GSM module with Wire

Post by Xemnas442 »

Hi,
I'm working on a project, a smart bin, that will have to get GPS data with the Adafruit Ultimate GPS Logger Shield then send that by sms with GSM shield. I got issue when both module were on the same Arduino Uno, then i tryied to use Wire library as somebody proposed in this post.
I used the example "parsing" which is in the library forder, and i modified it to get only latitude and longitude and get 2 int instead of a float, or could not send it by I2C link.

Code: Select all

// Code de test pour les modules GPS d'Adafruit utilisant le driver MTK3329/MTK3339
//
// Ce code montre comment ecouter le module GPS in an interrupt
// which allows the program to have more 'freedom' - just parse
// when a new NMEA sentence is available! Then access data when
// desired.
//
// Tested and works great with the Adafruit Ultimate GPS module
// using MTK33x9 chipset
//    ------> http://www.adafruit.com/products/746
// Pick one up today at the Adafruit electronics shop 
// and help support open source hardware & software! -ada

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <Wire.h>

// If you're using a GPS module:
// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// If using software serial (sketch example default):
//   Connect the GPS TX (transmit) pin to Digital 3
//   Connect the GPS RX (receive) pin to Digital 2
// If using hardware serial (e.g. Arduino Mega):
//   Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
//   Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3

// If you're using the Adafruit GPS shield, change 
// SoftwareSerial mySerial(3, 2); -> SoftwareSerial mySerial(8, 7);
// and make sure the switch is set to SoftSerial

// If using software serial, keep these lines enabled
// (you can change the pin numbers to match your wiring):
SoftwareSerial mySerial(8, 7);

Adafruit_GPS GPS(&mySerial);
// If using hardware serial (e.g. Arduino Mega), comment
// out the above six lines and enable this line instead:
//Adafruit_GPS GPS(&Serial1);


// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences. 
#define GPSECHO  false

int gpsLatEnt=0, gpsLatDec=0, gpsLonEnt=0, gpsLonDec;
float gpsLat=0, gpsLon=0;

// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy

void setup()  
{
    
  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  Serial.begin(115200);
  Serial.println("Adafruit GPS library basic test!");

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  
  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // Request updates on antenna status, comment out to keep quiet
  GPS.sendCommand(PGCMD_ANTENNA);

  // the nice thing about this code is you can have a timer0 interrupt go off
  // every 1 millisecond, and read data from the GPS for you. that makes the
  // loop code a heck of a lot easier!
  useInterrupt(true);

  delay(1000);
  // Ask for firmware version
  mySerial.println(PMTK_Q_RELEASE);
}


// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
#ifdef UDR0
  if (GPSECHO)
    if (c) UDR0 = c;  
    // writing direct to UDR0 is much much faster than Serial.print 
    // but only one character can be written at a time. 
#endif
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

uint32_t timer = millis();
void loop()                     // run over and over again
{
  // in case you are not using the interrupt above, you'll
  // need to 'hand query' the GPS, not suggested :(
  if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
    // if you want to debug, this is a good time to do it!
    if (GPSECHO)
      if (c) Serial.print(c);
  }
  
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
  
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) { 
    timer = millis(); // reset the timer
    
    Serial.print("\nTime: ");
    Serial.print(GPS.hour, DEC); Serial.print(':');
    Serial.print(GPS.minute, DEC); Serial.print(':');
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    Serial.println(GPS.milliseconds);
    Serial.print("Date: ");
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.println(GPS.year, DEC);
    Serial.print("Fix: "); Serial.print((int)GPS.fix);
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality); 
    if (GPS.fix) {
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 8); Serial.print(GPS.lat);
      gpsLat = GPS.latitude / 100 ;
      gpsLatEnt = int(gpsLat);
      gpsLatDec = (gpsLat - gpsLatEnt) * 1000000;
      Serial.print(", "); 
      Serial.print(GPS.longitude, 8); Serial.println(GPS.lon);
      gpsLon = GPS.longitude / 100 ;
      gpsLonEnt = int(gpsLon);
      gpsLonDec = (gpsLon - gpsLonEnt) * 1000000;
      
      Serial.print("Speed (knots): "); Serial.println(GPS.speed);
      Serial.print("Angle: "); Serial.println(GPS.angle);
      Serial.print("Altitude: "); Serial.println(GPS.altitude);
      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
    }
  }
      Wire.beginTransmission(4);
      Wire.write(gpsLatEnt);
      Wire.write(gpsLatDec);
      Wire.write(GPS.lat);
      Wire.write(gpsLonEnt);
      Wire.write(gpsLonDec);
      Wire.write(GPS.lon);
      Wire.endTransmission();
}
And there's the slave part:

Code: Select all

#include <Wire.h> //Librairie Wire

#include <GSM.h> //Librairie GSM
#define PIN "1234" //Code PIN

// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;

//configuration des variables
const char number[11] = "Numero"; //Numéro de Téléphone 
boolean smsSent=false, intState=false, notConnected=true;
int testLedBug=9, intInput=8;
int gpsLatEnt=0, gpsLatDec=0, gpsLonEnt=0, gpsLonDec;
char gpsLonPC=0, gpsLatPC=0;

void setup()
{
  //Initialisation de la communication Wire
  Wire.begin(4);
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);
  
  //Initialisation Pattes Entrée et Sortie
  pinMode(testLedBug, OUTPUT);
  pinMode(intInput, INPUT);
  
  //Démarrage module GSM
  //Test: Non connecté --> DEL allumée ; sinon programme continue
  while(notConnected)
  {
    if(gsmAccess.begin(PIN)==GSM_READY)
    {
      notConnected = false;
      digitalWrite(testLedBug, 0);
    }
    else
    {
      digitalWrite(testLedBug, 1);
      delay(1000);
    }
  }
}
  
void loop()
{
  intState = digitalRead(intInput); //Récupération état interrupteur

  if(intState == true) //si l'interrupteur est fermé
  {
    if(smsSent == false) //si le sms n'a pas encore été envoyé
    {
      sms.beginSMS(number);
      sms.print("La poubelle est pleine");
      sms.endSMS();
      smsSent = true;
    }
  } 
  delay(1000);
}

//fonction réception des données
void receiveEvent(int donatesGPS)
{
  gpsLatEnt = Wire.read();
  Serial.print(gpsLatEnt);
  Serial.print(".");
  gpsLatDec = Wire.read();
  Serial.print(gpsLatDec);
  while(1 < Wire.available())
  {
    gpsLatPC = Wire.read();
    Serial.println(gpsLatPC);
  }
  gpsLonEnt = Wire.read();
  Serial.print(gpsLonEnt);
  Serial.print(".");
  gpsLonDec = Wire.read();
  Serial.print(gpsLonDec);
  while(1 < Wire.available())
  {
    gpsLonPC = Wire.read();
    Serial.println(gpsLonPC);
  }
}
The issue is a can't get anything in the serial monitor and also, i got a (i think) short-circuit once because of the I2C link. I don't why but both groups of Arduino Cards with their own shield get issues when they are connected with I2C link, and that's scaring me, i don't want to damage my cards :/
Hope for your help, Xemnas :)

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: Problem sending data from GPS module to GSM module with

Post by Franklin97355 »

The issue is a can't get anything in the serial monitor
Start with minimal code to get the gps talking to the serial monitor first before you try or worry about anything else. Then take it one small step at a time.

Xemnas442
 
Posts: 5
Joined: Mon Apr 07, 2014 4:28 am

Re: Problem sending data from GPS module to GSM module with

Post by Xemnas442 »

franklin97355 wrote:
The issue is a can't get anything in the serial monitor
Start with minimal code to get the gps talking to the serial monitor first before you try or worry about anything else. Then take it one small step at a time.
I already did that :/ but it didn't worked too :(

Xemnas442
 
Posts: 5
Joined: Mon Apr 07, 2014 4:28 am

Re: Problem sending data from GPS module to GSM module with

Post by Xemnas442 »

An answer pls? :(

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Problem sending data from GPS module to GSM module with

Post by adafruit_support_mike »

Post a photo of your hardware and connections and we'll see what we can find.

Xemnas442
 
Posts: 5
Joined: Mon Apr 07, 2014 4:28 am

Re: Problem sending data from GPS module to GSM module with

Post by Xemnas442 »

adafruit_support_mike wrote:Post a photo of your hardware and connections and we'll see what we can find.
Can't really do it where i am, but i can explain with scematics. :/
I have too groups:
- 1 Arduino Uno with a GSM sheild (Arduino) above
- 1 Arduino Uno with Adafruit Ultimate GPS Logger Shield
There's the I2C connection:
MasterImageSlave
I have to say also that both "groups" are connected to the same PC, and someone in another forum gave me the idea to use a 10k pull-up resistor, but i don't think it's a really great idea.
And maybe in the slave group, it's just the serial interface that doen't work, and i could get the data for the sms.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Problem sending data from GPS module to GSM module with

Post by adafruit_support_mike »

The master/slave and I2C connections don't have any direct effect on the GPS module. Take that Arduino back to a bare-minimum sketch and try connecting it in the "direct computer wiring" method shown in the tutorial: https://learn.adafruit.com/adafruit-ult ... ter-wiring

See if that gives you any output in the Serial monitor.

Xemnas442
 
Posts: 5
Joined: Mon Apr 07, 2014 4:28 am

Re: Problem sending data from GPS module to GSM module with

Post by Xemnas442 »

I expected only today :/ The problem is i don't have this module, only the Ultimate GPS Logger Shield. Does it works the same way?

User avatar
tatanka
 
Posts: 62
Joined: Tue Jul 03, 2012 9:06 am

Re: Problem sending data from GPS module to GSM module with

Post by tatanka »

There are some minor differences as explained in the tutorial. AFTER loading the sketch, THEN flip the switch near D0 from soft serial to direct connect, then you should see Serial Monitor output. Remember, load the sketch first, THEN flip the switch.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”