• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Wyświetlanie danych z GPS na wyświetlaczu
#1
Cześć,

Jeżeli piszę w złym dziale, to proszę o wyrozumiałość.
Mam problem jak w temacie.
Napisałem dwa proste programy na Arduino. Osobno działają bez zarzutów, ale kiedy chce połączyć to w całość, to niestety nie działa. Jestem początkujący, jeżeli chodzi o Arduino i nie wiem co źle robie.
Potrzebuję wyświetlić na ekranie (biblioteka TVout) dane z modułu GPS.
Poniżej rysowanie prostej linie w pętli na ekranie, które działa.
Kod:
#include <TVout.h>
#include <fontALL.h>

#define W 136
#define H 96

TVout tv;
int y;

void setup()  {
 tv.begin(PAL, W, H);
 initOverlay();
 tv.select_font(font6x8);
}

// Initialize ATMega registers for video overlay capability.
// Must be called after tv.begin().
void initOverlay() {
 TCCR1A = 0;
 // Enable timer1.  ICES0 is set to 0 for falling edge detection on input capture pin.
 TCCR1B = _BV(CS10);

 // Enable input capture interrupt
 TIMSK1 |= _BV(ICIE1);

 // Enable external interrupt INT0 on pin 2 with falling edge.
 EIMSK = _BV(INT0);
 EICRA = _BV(ISC01);
}

// Required to reset the scan line when the vertical sync occurs
ISR(INT0_vect) {
 display.scanLine = 0;
}


void loop() {

 for (y=0; y<90; y++){
 tv.draw_line(0, y, 130, y, 1);
 delay(500);
 tv.clear_screen();
 //tv.delay(500);
 }
 }
Chciałbym wyświetlić na ekranie również dane z modułu GPS NEO-6M. W momencie kiedy ładuje sam kod dotyczący GPS to w monitorze portu USB widzę odczyty z modułu. 
Kod:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
/*
  This sample code demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
  It requires the use of SoftwareSerial, and assumes that you have a
  4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup()
{
 Serial.begin(115200);
 ss.begin(GPSBaud);

}

void loop()
{

 Serial.print("Stelity: ");
 printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
 Serial.print("\n");
 Serial.print("Data i godzina: ");
 printDateTime(gps.date, gps.time);
 Serial.print("\n");
 Serial.print("Predkosc: ");
 printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
 Serial.print("\n");
 
 smartDelay(1000);

 if (millis() > 5000 && gps.charsProcessed() < 10)
   Serial.println(F("No GPS data received: check wiring"));
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
 unsigned long start = millis();
 do
 {
   while (ss.available())
     gps.encode(ss.read());
 } while (millis() - start < ms);
}

static void printFloat(float val, bool valid, int len, int prec)
{
 if (!valid)
 {
   while (len-- > 1)
     Serial.print('*');
   Serial.print(' ');
 }
 else
 {
   Serial.print(val, prec);
   int vi = abs((int)val);
   int flen = prec + (val < 0.0 ? 2 : 1); // . and -
   flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
   for (int i=flen; i<len; ++i)
     Serial.print(' ');
 }
 smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
 char sz[32] = "*****************";
 if (valid)
   sprintf(sz, "%ld", val);
 sz[len] = 0;
 for (int i=strlen(sz); i<len; ++i)
   sz[i] = ' ';
 if (len > 0)
   sz[len-1] = ' ';
 Serial.print(sz);
 smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
 if (!d.isValid())
 {
   Serial.print(F("********** "));
 }
 else
 {
   char sz[32];
   sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
   Serial.print(sz);
 }
 
 if (!t.isValid())
 {
   Serial.print(F("******** "));
 }
 else
 {
   char sz[32];
   sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
   Serial.print(sz);
 }

 printInt(d.age(), d.isValid(), 5);
 smartDelay(0);
}

static void printStr(const char *str, int len)
{
 int slen = strlen(str);
 for (int i=0; i<len; ++i)
   Serial.print(i<slen ? str[i] : ' ');
 smartDelay(0);
}

W momnecie kiedy łączy wszystko w całość, nie mam ani odczytów w monitorze, ani rysowanej lini na ekranie. 
Do wyświetlania posłużyłem się shieldem "VideoExperimenter"
Całość:
Kod:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <TVout.h>
#include <fontALL.h>

#define W 136
#define H 96


TVout tv;
int y;
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup()
{
 tv.begin(PAL, W, H);
 initOverlay();
 tv.select_font(font6x8);
 Serial.begin(115200);
 ss.begin(GPSBaud);

}
// Initialize ATMega registers for video overlay capability.
// Must be called after tv.begin().
void initOverlay() {
 TCCR1A = 0;
 // Enable timer1.  ICES0 is set to 0 for falling edge detection on input capture pin.
 TCCR1B = _BV(CS10);

 // Enable input capture interrupt
 TIMSK1 |= _BV(ICIE1);

 // Enable external interrupt INT0 on pin 2 with falling edge.
 EIMSK = _BV(INT0);
 EICRA = _BV(ISC01);
}
void loop()
{

 Serial.print("Stelity: ");
 printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
 Serial.print("\n");
 Serial.print("Data i godzina: ");
 printDateTime(gps.date, gps.time);
 Serial.print("\n");
 Serial.print("Predkosc: ");
 printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
 Serial.print("\n");
 
 smartDelay(1000);
 
   for (y=0; y<90; y++){
 tv.draw_line(0, y, 130, y, 1);
 delay(500);
 tv.clear_screen();
 //tv.delay(500);
 }

 if (millis() > 5000 && gps.charsProcessed() < 10)
   Serial.println(F("No GPS data received: check wiring"));
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
 unsigned long start = millis();
 do
 {
   while (ss.available())
     gps.encode(ss.read());
 } while (millis() - start < ms);
}

static void printFloat(float val, bool valid, int len, int prec)
{
 if (!valid)
 {
   while (len-- > 1)
     Serial.print('*');
   Serial.print(' ');
 }
 else
 {
   Serial.print(val, prec);
   int vi = abs((int)val);
   int flen = prec + (val < 0.0 ? 2 : 1); // . and -
   flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
   for (int i=flen; i<len; ++i)
     Serial.print(' ');
 }
 smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
 char sz[32] = "*****************";
 if (valid)
   sprintf(sz, "%ld", val);
 sz[len] = 0;
 for (int i=strlen(sz); i<len; ++i)
   sz[i] = ' ';
 if (len > 0)
   sz[len-1] = ' ';
 Serial.print(sz);
 smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
 if (!d.isValid())
 {
   Serial.print(F("********** "));
 }
 else
 {
   char sz[32];
   sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
   Serial.print(sz);
 }
 
 if (!t.isValid())
 {
   Serial.print(F("******** "));
 }
 else
 {
   char sz[32];
   sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
   Serial.print(sz);
 }

 printInt(d.age(), d.isValid(), 5);
 smartDelay(0);
}

static void printStr(const char *str, int len)
{
 int slen = strlen(str);
 for (int i=0; i<len; ++i)
   Serial.print(i<slen ? str[i] : ' ');
 smartDelay(0);
}
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości