Bonjour,
je voudrais enregistrer les informations du GPS (heure et date ) ainsi que le signal qu'on m'envoie sur une carte SD.
Le programme si dessous permet d'afficher sur le moniteur série l'heure et la date :
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO true
// 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!");
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
GPS.sendCommand(PGCMD_ANTENNA);
useInterrupt(true);
delay(1000);
// Ask for firmware version
mySerial.println(PMTK_Q_RELEASE);
}
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;
#endif
}
void useInterrupt(boolean v) {
if (v) {
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
uint32_t timer = millis();
void loop() // run over and over again
{
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
}
if (GPS.newNMEAreceived()) {
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
}
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);
}
Cependant des que j'enregistre le signal qu'on m'envoie sur la carte sd à l'aide de ce programme :
#include <Adafruit_GPS.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include <SPI.h>
SoftwareSerial BTSerial(2, 3 ); // RX | TX
byte rec;
File logfile;
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO true
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
void setup()
{
Serial.begin(115200); // vitesse serial monitor
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
GPS.sendCommand(PGCMD_ANTENNA);
BTSerial.begin(38400);
char filename[15];
strcpy(filename, "GPSLOG.TXT");
SD.begin(10);
logfile = SD.open(filename, FILE_WRITE);
//BTSerial.begin(38400); // vitesse software serial
}
SIGNAL (TIMERO_COMPA_vect) {
char c = GPS.read();
#ifdef UDRO
if (GPSECHO)
if (c) UDRO = c;
#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
{
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
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
}
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);
delay(500);
if (BTSerial.available())
{
rec = BTSerial.read();
if (rec < 16) logfile.print("0");
logfile.print(rec, HEX);
if(!BTSerial.available())
{
logfile.print(",");
logfile.print("\n");
logfile.print(F("#"));
}
logfile.flush();
if (Serial.available())
{
BTSerial.write(Serial.read());
}
}
}
Les informations GPS deviennent NULL
"time:0.0.0"
"date:0.0.0"
iprogamer:
Bonjour,
je voudrais enregistrer les informations du GPS (heure et date ) ainsi que le signal qu'on m'envoie sur une carte SD.
Le programme si dessous permet d'afficher sur le moniteur série l'heure et la date :
Cependant des que j'enregistre le signal qu'on m'envoie sur la carte sd à l'aide de ce programme :
...
Les informations GPS deviennent NULL
"time:0.0.0"
"date:0.0.0"
bonjour
avec softwareserial, il ne peut y avoir qu'un seul "soft serie" à l'ecoute à un instant T
voir ce wiki et cette info
If using multiple software serial ports, only one can receive data at a time.
ce probleme à déjà été evoqué recemment (topic à retrouver)
d'accord merci.
le port série renvoie un 1 ou 0 quand il est "available" ?
iprogamer:
d'accord merci.
le port série renvoie un 1 ou 0 quand il est "available" ?
non , non ce n'est pas du tout la meme problematique
tu ne peux avoir qu'un seul port serie (soft) qui ecoute à un instant T
c'est à toi de choisir quel port tu souhaite ecouter avec l'instruction
.Listen()
la lib AltSoftSerial semble ne pas avoir cette limitation (jamais testée perso)
d'accord et j'alterne entre les "listen"
merci
j'en conclue donc que si j'écoute un port l'autre n'est pas écouté,
pas besoin d'arrêter l'écoute d'un port pour passer à l'autre cela est automatique dès l'écoute de l'autre ?
iprogamer:
d'accord et j'alterne entre les "listen"
merci
j'en conclue donc que si j'écoute un port l'autre n'est pas écouté,
pas besoin d'arrêter l'écoute d'un port pour passer à l'autre cela est automatique dès l'écoute de l'autre ?
oui , c'est un peu comme si tu avait un inverseur
NB : tout ce qui arrive sur le port "non écouté" est perdu
cela ne fonctionne pas pourtant j'écoute chaque port un par un
#include <Adafruit_GPS.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include <SPI.h>
SoftwareSerial BTSerial(2, 3 ); // RX | TX
byte rec;
File logfile;
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO true
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
void setup()
{
Serial.begin(115200); // vitesse serial monitor
BTSerial.begin(38400);
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
GPS.sendCommand(PGCMD_ANTENNA);
char filename[15];
strcpy(filename, "GPSLOG.TXT");
SD.begin(10);
logfile = SD.open(filename, FILE_WRITE);
}
SIGNAL (TIMERO_COMPA_vect) {
char c = GPS.read();
#ifdef UDRO
if (GPSECHO)
if (c) UDRO = c;
#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
{
mySerial.listen();
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
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
}
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);
delay(100);
BTSerial.listen();
if (BTSerial.available())
{
rec = BTSerial.read();
if (rec < 16) logfile.print("0");
logfile.print(rec, HEX);
if(!BTSerial.available())
{
logfile.print(",");
logfile.print("\n");
logfile.print(F("#"));
}
logfile.flush();
if (Serial.available())
{
BTSerial.write(Serial.read());
}
}
}
iprogamer:
cela ne fonctionne pas pourtant j'écoute chaque port un par un
bonjour
repondre çà c'est vague 
qu'est ce qu tu constate exactement ?
l'affichage sur le moniteur (time:0.0.0)
Et mon signal n'est pas écrit sur la carte SD
Cependant quand je mets en commentaire la fin du programme aillant pour but d'écrire le signal sur la SD,
l'affichage du moniteur devient bon.
BTSerial.listen();
if (BTSerial.available())
{
rec = BTSerial.read();
if (rec < 16) logfile.print("0");
logfile.print(rec, HEX);
if(!BTSerial.available())
{
logfile.print(",");
logfile.print("\n");
logfile.print(F("#"));
}
logfile.flush();
if (Serial.available())
{
BTSerial.write(Serial.read());
}
}
Et inversement si le GPS est en commentaire, l'écriture sur la carte SD fonctionne
mySerial.listen();
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
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
}
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);
delay(500);
tu es en listen en permanence, donc ca le fait pas
l'écriture se fait bien sur la carte SD
seul l'heure n'affiche pas les bon résultats
Il me faut une condition comme pour le signal mais je trouves pas
#include <Adafruit_GPS.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include <SPI.h>
SoftwareSerial BTSerial(2, 3 ); // RX | TX
byte rec;
File logfile;
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO true
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
void setup()
{
Serial.begin(115200); // vitesse serial monitor
BTSerial.begin(38400);
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
GPS.sendCommand(PGCMD_ANTENNA);
char filename[15];
strcpy(filename, "GPSLOG.TXT");
SD.begin(10);
logfile = SD.open(filename, FILE_WRITE);
}
SIGNAL (TIMERO_COMPA_vect) {
char c = GPS.read();
#ifdef UDRO
if (GPSECHO)
if (c) UDRO = c;
#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();
int i=0;
void loop() // run over and over again
{
if (i==2)
{
delay(300);
mySerial.listen();
}
if (mySerial.isListening())
{
i= 1;
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
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
}
logfile.print("\nTime: ");
logfile.print(GPS.hour, DEC); logfile.print(':');
logfile.print(GPS.minute, DEC); logfile.print(':');
logfile.print(GPS.seconds, DEC); logfile.print('.');
logfile.println(GPS.milliseconds);
}
if(i==1)
{
BTSerial.listen();
}
delay(300);
if(BTSerial.isListening())
{
i = 2;
while (BTSerial.available())
{
rec = BTSerial.read();
if (rec < 16) logfile.print("0");
logfile.print(rec, HEX);
if(!BTSerial.available())
{
logfile.print(",");
logfile.print("\n");
logfile.print(F("#"));
}
logfile.flush();
if (Serial.available())
{
BTSerial.write(Serial.read());
}
}
}
}