Author Topic: Mote with GPS  (Read 19444 times)

bryonwausau

  • NewMember
  • *
  • Posts: 8
Mote with GPS
« on: December 24, 2013, 04:17:07 AM »
I am working on adding gps module to a mote then having it being able to transmit its info to a second mote.
Then the second mote will be able to tell where the first one is and guide you to the second one using leds to guide you to the direction you need to walk.

Current problem is I am using the arduino files from adafruit but can't get the ECHO program to work for me.
If anyone has time I would love some help with what I am doing wrong.

I am using the base gps ECHO example from adafruit.
I have wired the gps to the pins 3 and 4.

I have attached the test code.
I am using the moteino-usb chip.
I am also using "Ultimate GPS" from adafruit.


LazyGlen

  • NewMember
  • *
  • Posts: 48
Re: Mote with GPS
« Reply #1 on: December 24, 2013, 11:23:29 AM »
When you say it isn't working, what does that mean? Give us something to go on.

Which half "isn't working" Transmitter or Receiver?
Isn't working; pick one:
  • Smoke came out
  • Won't compile code
  • Can't program Moteino
  • LED blinks but nothing on serial port
  • Serial port displays gibberish
  • Serial port displays text other than what you expected

You included a Gateway sketch, so I'm assuming it is the receiver.

I ran a compare of your sketch versus one I downloaded from Github, and found basically no differences, yours is set up for 915MHz and RFM69HW radios, while mine is 433MHz and RFM69's. Plus a 4 extra blank lines and an "end of main loop" comment. Have you made any changes to it?

Did you run the default sketches and get your computer to see the default transmits so we know your serial port is working? The importance of this can not be overstated. Knowing that the correct serial port is selected, the baud rate is right and that you have a functional base system removes a lot of unknowns.

Is it displaying anything? Is it displaying ... dramatic pause...  unprintable characters? Little square boxes and special ASCII art like things?

Ask me how I know. Go on, ask!

Because I had those weird characters on my screen 2 days ago. The default Node and Gateway sketch's transmit, receive and then display CHAR's, not a string, not integers or floats. (My assignment while waiting in airports today is to read up and remember exactly how CHAR's and Strings differ.) So despite the fact that I know that the data being transmitted is an integer and 4 floats, the Gateway sketch thinks they are CHAR's and displays them as such. (As an aside, yelling at the Moteinos, computer, and Arduino IDE will not make them change their behavior.) Look into the Struct_Send and Struct_Receive examples for transmitting data of other types.

Assuming that you are smarter than I am and already figured the above out, have you got the transmitter hooked up with an FTDI adapter and sprinkled the code with Serial.print statements?

Once you identify exactly what the actual problem that you are experiencing is, you will get better help.

LG

bryonwausau

  • NewMember
  • *
  • Posts: 8
Re: Mote with GPS
« Reply #2 on: December 24, 2013, 02:47:37 PM »
Sorry new to posting to forums. I will add more notes. :)

bryonwausau

  • NewMember
  • *
  • Posts: 8
Re: Mote with GPS
« Reply #3 on: December 25, 2013, 12:51:24 PM »
Ok more info:
I am using this program pushed to the motino

// this sketch will allow you to bypass the Atmega chip
// and connect the GPS sensor directly to the USB/Serial
// chip converter.

// Connect VIN to +5V
// Connect GND to Ground
// Connect GPS RX (data into GPS) to Digital 0
// Connect GPS TX (data out from GPS) to Digital 1

void setup() {}
void loop() {}

when I run it and I look at the serial monitor output I get this:
$GPRMC,173508.219,A,4457.0243,N,08937.0888,W,0.20,0.00,251213,,,A*70
$GPVTG,0.00,T,,M,0.20,N,0.36,K,A*3A
$GPGGA,173510.000,4457.0238,N,08937.0888,W,1,3,27.54,184.5,M,-34.5,M,,*59
$GPGSA,A,2,29,21,05,,,,,,,,,,99.99,27.54,99.99*3A
$GPRMC,173510.000,A,4457.0238,N,08937.0888,W,0.03,0.00,251213,,,A*7E
$GPVTG,0.00,T,,M,0.03,N,0.06,K,A*38
$GPGGA,173511.000,4457.0237,N,08937.0888,W,1,3,27.52,184.5,M,-34.5,M,,*51
$GPGSA,A,2,29,21,05,,,,,,,,,,99.99,27.52,99.99*3C

========================================================
Yea this makes me happy.
now I am wired like this.

D1 pin goes to the TX pin on the GPS
D0 pin goes to the RX pin on the GPS
=====================================================
so I run a test program from adafruit website :
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
//
// This code just echos whatever is coming from the GPS unit to the
// serial monitor, handy for debugging!
//
// 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

//This code is intended for use with Arduino Leonardo and other ATmega32U4-based Arduinos

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

// 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 8
//   Connect the GPS RX (receive) pin to Digital 7
// If using hardware serial:
//   Connect the GPS TX (transmit) pin to Arduino RX1 (Digital 0)
//   Connect the GPS RX (receive) pin to matching TX1 (Digital 1)

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

// If using hardware serial, comment
// out the above two lines and enable these two lines instead:
//HardwareSerial mySerial = Serial1;

#define PMTK_SET_NMEA_UPDATE_1HZ  "$PMTK220,1000*1F"
#define PMTK_SET_NMEA_UPDATE_5HZ  "$PMTK220,200*2C"
#define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F"

// turn on only the second sentence (GPRMC)
#define PMTK_SET_NMEA_OUTPUT_RMCONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
// turn on GPRMC and GGA
#define PMTK_SET_NMEA_OUTPUT_RMCGGA "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
// turn on ALL THE DATA
#define PMTK_SET_NMEA_OUTPUT_ALLDATA "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
// turn off output
#define PMTK_SET_NMEA_OUTPUT_OFF "$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"

#define PMTK_Q_RELEASE "$PMTK605*31"

void setup() {
  while (!Serial); // wait for leo to be ready

  Serial.begin(57600); // this baud rate doesn't actually matter!
  mySerial.begin(9600);
  delay(2000);
  Serial.println("Get version!");
  mySerial.println(PMTK_Q_RELEASE);
 
  // you can send various commands to get it started
  //mySerial.println(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  mySerial.println(PMTK_SET_NMEA_OUTPUT_ALLDATA);

  mySerial.println(PMTK_SET_NMEA_UPDATE_1HZ);
 }


void loop() {
  if (Serial.available()) {
   char c = Serial.read();
   Serial.write(c);
   mySerial.write(c);
  }
  if (mySerial.available()) {
    char c = mySerial.read();
    Serial.write(c);
  }
}

========================================
I get this output:
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÉŠbbbbbbbŠrªîbŠr’ºb‚rÊšR‚Âj¤Ò*ªS(KLS§¦'   sL–P–š457.0168,N,0øþÿÿÿ


question is where did things go wrong???
Humm do I have the wrong pin numbers?

LazyGlen

  • NewMember
  • *
  • Posts: 48
Re: Mote with GPS
« Reply #4 on: December 25, 2013, 02:33:44 PM »
It sounds like you are going about this right. Starting at the beginning and work up to where you want your final project to be.

I have not used the AdaFruit GPS logger, but in reading the code that you posted one thing stood out.

Code: [Select]
//This code is intended for use with Arduino Leonardo and other ATmega32U4-based Arduinos

In your first post you state that you are using and Moteino USB, which uses the ATMega328 processor. The code you are trying to run is written for ATmega32U4. I don't know much about the differences, but based on the fact that there is a different sketch published, it probably wont work on the wrong processor.

This is not to say you have purchased the wrong hardware!

There are several different sketches published by AdaFruit, I think that the one you are looking for at this stage of your project is the echo sketch. Pay careful attention to the comments in the code. There are different baud rates depending on what hardware you are talking to. It looks like the GPS is running at 9600 to the Arduino Moteino, but the serial monitor is talking at 115200 to the Arduino Moteino in order to display everything. This is a bit confusing since this normally does not happen. Think of it like this - The GPS is speaking one language, the Moteino is translating it and speaking a different language to you on the serial monitor.

According to the comments in the code, even with the faster baud rate between Moteino and serial monitor, you can overwhelm things if you ask for too much information. The GPS can update 10 times per second (10Hz), but the serial monitor can't give you Lat AND Long AND elevation AND speed AND current time AND whatever else you ask for at that rate.

You may get more joy and help from the AdaFruit forums on the GPS portion of this. Make sure that you fully understand what you are seeing using 1 Moteino over the serial FTDI adapter before you go nuts trying to transmit the data over the RFM69HW links to other Mote's.

I'm sure other people will be around to offer advice, and maybe someone else has used the Ultimate GPS with a Moetino and solved all these problems already.

LG

Merry Christmas!

bryonwausau

  • NewMember
  • *
  • Posts: 8
Yea got gps figured out
« Reply #5 on: December 25, 2013, 09:01:03 PM »
So here is the code that I used:
============================================

#include <SoftwareSerial.h>

#define rxPin 1
#define txPin 0
#define ledPin 6

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
byte pinState = 0;

void setup()  {
  // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello World - SoftwareSerial");
}

void loop() {
  // listen for new serial coming in:
  char someChar = mySerial.read();
  // print out the character:
  mySerial.print(someChar);
  // toggle an LED just so you see the thing's alive. 
  // this LED will go on with every OTHER character received:
  toggle(ledPin);
}

void toggle(int pinNum) {
  // set the LED pin using the pinState variable:
  digitalWrite(pinNum, pinState);
  // if pinState = 0, set it to 1, and vice versa:
  pinState = !pinState;
}

==========================================================
This gives me the output of :

$GPVTG,0.00,T,,M,0.00,þ¥&¦Cá$GPGGA,015659.092,,,,,0,0,,,M,,M,,*4D
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,015659.092,V,,,,,0.00,0.00,100180,,,N*40
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,015700.092,,,,,0,0,,,M,,M,,*40
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,015700.092,V,,,,,0.00,0.00,100180,,,N*4D
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,015701.092,,,,,0,0,,,M,,M,,*41
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,02,23,,,29,25,,,30*75
$GPRMC,015701.092,V,,,,,0.00,0.00,100180,,,N*4C
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,015702.091,,,,,0,0,,,M,,M,,*41
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,015702.091,V,,,,,0.00,0.00,261213,,,N*41
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,015703.091,,,,,0,0,,,M,,M,,*40
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,015703.091,V,,,,,0.00,0.00,261213,,,N*40
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,015704.091,,,,,0,0,,,M,,M,,*47
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,015704.091,V,,,,,0.00,0.00,261213,,,N*47
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,015705.091,,,,,0,0,,,M,,M,,*46
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,015705.091,V,,,,,0.00,0.00,261213,,,N*46
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,015706.091,,,,,0,0,,,M,,M,,*45
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,02,23,,,30,25,,,29*75
$GPRMC,015706.091,V,,,,,0.00,0.00,261213,,,N*45
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,015707.091,,,,,0,0,,,M,,M,,*44
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,015707.091,V,,,,,0.00,0.00,261213,,,N*44
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,015708.091,,,,,0,0,,,M,,M,,*4B
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,015708.091,V,,,,,0.00,0.00,261213,,,N*4B
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,015709.091,,,,,0,0,,,M,,M,,*4A
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,015709.091,V,,,,,0.00,0.00,261213,,,N*4A
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,015710.091,,,,,0,0,,,M,,M,,*42
$GPGSA,A,1,,,,,,,,,,,,,,,*1E

so the motine will handle talking with the gps units.


bryonwausau

  • NewMember
  • *
  • Posts: 8
Now transmitting the gps to another arduino
« Reply #6 on: December 25, 2013, 09:02:01 PM »
Now I need to add the working code so that it will transmit the info radio to another unit.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Mote with GPS
« Reply #7 on: December 26, 2013, 07:15:07 AM »
Why would you use SoftwareSerial with D0 and D1?
Those are already hardware serial pins.

bryonwausau

  • NewMember
  • *
  • Posts: 8
Re: Mote with GPS
« Reply #8 on: January 03, 2014, 03:24:24 AM »
Please explain what you mean...
If there is a better why to use the tx rx pins please explain, I still feel in the fog about this.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Mote with GPS
« Reply #9 on: January 03, 2014, 07:47:47 AM »
SoftwareSerial is a library which allows you to use any two digital pins as a serial port (TX & RX). There is a hardware serial port already on D0 and D1, so its really a waste to use SoftwareSerial on those same two pins. A hardware serial is always better than a software emulated serial port.

LazyGlen

  • NewMember
  • *
  • Posts: 48
Re: Mote with GPS
« Reply #10 on: January 03, 2014, 08:31:56 AM »
I'm guessing this is an artifact of the OP's starting from scratch. LadyAda's example code puts the GPS on the hardware serial port to allow early debug of the GPS without worrying about the code loaded on the processor. Moving to the next step of programming, example code usually does not assume hardware serial is available or being used, so us beginning coders use the example code, modifying it only as necessary. Since the GPS is already wired to pin 0 & 1 from the above debugging step, it's easy to leave it there and just keep trucking.

But that is a guess.

bryonwausau

  • NewMember
  • *
  • Posts: 8
Re: Mote with GPS
« Reply #11 on: January 09, 2014, 11:53:04 PM »
This has become so frustrating because I can get it to work in echo mode so I know the chip is wired correctly, but I can't get to reading more than the first line of the protocol from gps and then nothing else.

I have tried to do a straight read hardware serial line and then display the char that I get but then all I get the is number 1 repeating over and over..

The examples are very frustrating since I can't make it adapt to the mote..

This is the closest I get but all I get is the first three lines of protocol from the gps and then all stops. nothing more.

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 9;




void setup() {
  // initialize serial:
  Serial.begin(9600);
  // setup led for use
  pinMode(led,OUTPUT);
  // reserve 200 bytes for the inputString:
  inputString.reserve(300);
}

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString);
    // clear the string:
    inputString = "";
    Serial.println("Reseting everything!");
    blinker();
    stringComplete = false;
  }
  else {
  serialEvent();
  }
}

/*
  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
 */
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\r' || inChar == '\n') {
      stringComplete = true;
      blinker();
      Serial.println("Got an end of line marker!");
     
    }
  }
}
void blinker(){
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(500);
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(500);
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(500);
}

LazyGlen

  • NewMember
  • *
  • Posts: 48
Re: Mote with GPS
« Reply #12 on: January 10, 2014, 08:27:22 AM »
For starters, where did the code you are using come from? Please provide a link.

The blinker routine occupies the processor for a full 3 seconds every time it is called,and does nothing but blink an LED. I can see this being useful after initial power up while you wait for a satelite lock, but not elsewhere. There are comments in the code that state
Quote
This routine is run between each time loop() runs, so using delay inside loop can delay response.  Multiple bytes of data may be available.
But the way the code is written, every time loop runs it has a 3 second delay.

In this section of code:
Code: [Select]
void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString);
    // clear the string:
    inputString = "";
    Serial.println("Reseting everything!");
    blinker();
    stringComplete = false;
  }
  else {
  serialEvent();
  }
You check to see if the string is complete, and if it is, print it out, clear the string, print a resetting statement, then you send the processor to blink the LED for 3 seconds and when you return, set stringComplete to false.

In the 3 seconds the processor was blinking, the GPS may have sent lots of data to the hardware serial port. Possibly enough to overrun buffers.

Likewise in the serialEvent code
 
Code: [Select]
if (inChar == '\r' || inChar == '\n') {
      stringComplete = true;
      blinker();
      Serial.println("Got an end of line marker!");
 

You append new chars to the input string until you get a newline, set stringComplete true, then wait 3 seconds, then print a note and exit the function.

I'm not an expert coder by any means, but this seems strange to me.

Lg

bryonwausau

  • NewMember
  • *
  • Posts: 8
Re: Mote with GPS
« Reply #13 on: January 22, 2014, 03:06:18 AM »
ok got it to finally work.. I have an issue now ..
I am trying to take the nmea output and replace the payload variable so I can use the "Node" code example from lowpowerlab...  but I get an error

the line reads "payload = GPS.lastNMEA();"

Error: incompatible types in assignment of 'char*' to 'char [50]' 

I googled it and it looks like I need to use a string copy but I don't understand what that means...

Any help would be greatly appreciated.

baxterdavid

  • NewMember
  • *
  • Posts: 10
Re: Mote with GPS
« Reply #14 on: March 19, 2014, 05:54:22 AM »
How are base GPS, are they easy to use them ?