GPS Project Wiring Help...

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
jimhaley
 
Posts: 44
Joined: Fri Feb 14, 2014 8:05 am

Re: GPS Project Wiring Help...

Post by jimhaley »

Umm... I'm not sure. When I reset the Micro it fills the screen with Time, Date, Fix & Quality (4 Times) so it looks like it's making it through the loop at least four times??? The GPS hasn't had time to get a fix, so time & date is about all it has to print...?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: GPS Project Wiring Help...

Post by adafruit_support_rick »

jimhaley wrote:When I reset the Micro it fills the screen with Time, Date, Fix & Quality (4 Times) so it looks like it's making it through the loop at least four times???
OK, so the code for filling the screen with that stuff is in loop(), not in setup()?

Post you code and I'll see if I can spot why it's hanging.

jimhaley
 
Posts: 44
Joined: Fri Feb 14, 2014 8:05 am

Re: GPS Project Wiring Help...

Post by jimhaley »

Here she is: I changed something and it walks writes it data every 2 sec and after four times goes off bottom of screen (do I need a set cursor command???

Code: Select all

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9340.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
//addition from JIMSgraphictest//
#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif

// These are the pins used for the UNO
// for Due/Mega/Leonardo use the hardware SPI pins (which are different)
#define _sclk 13
#define _miso 12
#define _mosi 11
#define _cs 10
#define _dc 9
#define _rst 8 
//addition from JIMSgraphictest//

// Using software SPI is really not suggested, its incredibly slow
//Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);
// Use hardware SPI
Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);
// 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(3, 2);

//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

// 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(9600);
  Serial.println("Adafruit 2.2\" SPI TFT Test!"); 
 
  tft.begin();
  tft.setTextSize(3);
   tft.setTextColor(ILI9340_RED);
  // 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) tft.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
   // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 1000) { 
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 1000) { 
    timer = millis(); // reset the timer
    tft.setCursor();
    tft.print("\nTime:");
    tft.print(GPS.hour, DEC); Serial.print(':');
    tft.print(GPS.minute, DEC); Serial.print(':');
    tft.print(GPS.seconds, DEC); Serial.print('.');
    tft.print("Date:");
    tft.print(GPS.day, DEC); Serial.print('/');
    tft.print(GPS.month, DEC); Serial.print("/20");
    tft.println(GPS.year, DEC);
    tft.print("Fix: "); Serial.print((int)GPS.fix);
    tft.print(" Qu# b: "); Serial.println((int)GPS.fixquality);
    if (GPS.fix) {
    tft.print("Lat:    ");
    tft.print(GPS.latitude, 4); Serial.println(GPS.lat);
    tft.print("Lon:   "); 
    tft.print(GPS.longitude, 4); Serial.println(GPS.lon);
    tft.print("SOG: "); Serial.println(GPS.speed);
    tft.print("COG: "); Serial.println(GPS.angle);
    tft.print("SATs: "); Serial.println((int)GPS.satellites);}
      delay (2000);
  }
 

}

         unsigned long start, t;
         int    x1, y1, x2, y2,
                w = tft.width(),
                h = tft.height();

  tft.fillScreen(ILI9340_BLACK);

  x1 = y1 = 0;
  y2    = h - 1;
  start = micros();

  x2    = w - 1;

  t     = micros() - start; // fillScreen doesn't count against timing

  tft.fillScreen(ILI9340_BLACK);

  x1    = w - 1;
  y1    = 0;
  y2    = h - 1;
  start = micros();

  x2    = 0;

  t    += micros() - start;

  tft.fillScreen(ILI9340_BLACK);

  x1    = 0;
  y1    = h - 1;
  y2    = 0;
  start = micros();

  x2    = w - 1;

  t    += micros() - start;

  tft.fillScreen(ILI9340_BLACK);

  x1    = w - 1;
  y1    = h - 1;
  y2    = 0;
  start = micros();

  x2    = 0;


}

unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  unsigned long start;
  int           x, y, w = tft.width(), h = tft.height();

  tft.fillScreen(ILI9340_BLACK);
  start = micros();
  for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);

  return micros() - start;
}
Last edited by adafruit_support_rick on Fri Mar 14, 2014 6:49 pm, edited 1 time in total.
Reason: use code tags when posting code

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: GPS Project Wiring Help...

Post by adafruit_support_rick »

Oh! You're expecting it to scroll up? It won't do that.
Yes, you want to use setCursor to reposition the cursor each time through the loop.

Please use the code button when posting code.

jimhaley
 
Posts: 44
Joined: Fri Feb 14, 2014 8:05 am

Re: GPS Project Wiring Help...

Post by jimhaley »

Okay, sorry...what's the syntax for resetting cursor for tft and where does it go in the sketch?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: GPS Project Wiring Help...

Post by adafruit_support_rick »

You've already got it in there

Code: Select all

    if (millis() - timer > 1000) { 
      timer = millis(); // reset the timer
      tft.setCursor();
      tft.print("\nTime:");
But you need to give it a couple of arguments:

Code: Select all

    if (millis() - timer > 1000) { 
      timer = millis(); // reset the timer
      tft.setCursor(0, 0);      //return cursor to upper left corner
      tft.print("\nTime:");

jimhaley
 
Posts: 44
Joined: Fri Feb 14, 2014 8:05 am

Re: GPS Project Wiring Help...

Post by jimhaley »

Thanks pal...I worked you pretty good this week...if you were in LA I'd offer to buy you a beverage...

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: GPS Project Wiring Help...

Post by adafruit_support_rick »

No problem :D

jimhaley
 
Posts: 44
Joined: Fri Feb 14, 2014 8:05 am

Re: GPS Project Wiring Help...

Post by jimhaley »

Some fine tuning...it's working fine, but i'm using "tft.fillScreen(ILI9340_BLACK);" to "turn off the backlight" It slows the whole thing down every loop. There must be a more efficient way to effectively "turn off the backlight"????

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: GPS Project Wiring Help...

Post by adafruit_support_rick »

I don't think there's a separate backlight command. But you're calling fillScreen black four times in loop(). I really don't understand that part of your code. Why are you calling it four times?

jimhaley
 
Posts: 44
Joined: Fri Feb 14, 2014 8:05 am

Re: GPS Project Wiring Help...

Post by jimhaley »

I think that was an artifact from cutting and pasting example code. I've changed it to only "tft.fillScreen(ILI9340_BLACK);" once per loop, but that takes nearly a whole second and looks like pulling a black window shade down over a light gray screen. So, even once per loop is problematic...there must be a way to make the screen black and stay black to give max text contrast and just re-paint the text with updated data...? I tried to move that command line to set up so it didn't have to "fillscreen" every loop, but I lack the coding savy to make that work...I ran into some coding error that, for me was a brick wall...???

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: GPS Project Wiring Help...

Post by adafruit_support_rick »

Instead of filling the entire screen, just fill a rectangle big enough to cover the text you want to erase.

jimhaley
 
Posts: 44
Joined: Fri Feb 14, 2014 8:05 am

Re: GPS Project Wiring Help...

Post by jimhaley »

Guess I didn't explain well...I'm not erasing text, just providing max contrast for text, which is pretty much the full screen. I tried just turning off the backlight, but ended up turning off the text as well???

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: GPS Project Wiring Help...

Post by adafruit_support_rick »

You only need to draw the background once then. Do it in setup() instead of loop.

jimhaley
 
Posts: 44
Joined: Fri Feb 14, 2014 8:05 am

Re: GPS Project Wiring Help...

Post by jimhaley »

Just when I thought I was home free, I thought I was close enough to hardwire the project an fine tune the sketch, but after soldering every together nothing works and when I try to re-upload the sketch I get this error: avrdude: stk500_getsync(): not in sync: resp=0x54....could this be a heat (soldering) casualty to the Micro???

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

Return to “General Project help”