Saudações,
caros, a pouco comprei um módulo de gps "skylab skm53" e um módulo para cartão SD "LC STUDIO".
e agora vem os problemas... como fazer para salvar os dados do gps no cartão???
Achei dois exemplos que funcionam muito bem individualmente.
Um deles é o exemplo do próprio software do arduino (Exemplo > SD > ReadWrite) e o outro para o gps, segue abaixo...
Alguém pode me ajudar a desenvolver esse código? Não conheço muito de programação.
Muito obrigado a todos.
Abraços.
#---------- código para o GPS.
#include <string.h>
#include <ctype.h>
int ledPin = 13; // LED test pin
int rxPin = 0; // RX PIN
int txPin = 1; // TX TX
int byteGPS=-1;
char linea[300] = "";
char comandoGPR[7] = "$GPRMC";
int cont=0;
int bien=0;
int conta=0;
int indices[13];
void setup() {
pinMode(ledPin, OUTPUT); // Initialize LED pin
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(9600);
for (int i=0;i<300;i++){ // Initialize a buffer for received data
linea[i]=' ';
}
}
void loop() {
digitalWrite(ledPin, HIGH);
byteGPS=Serial.read(); // Read a byte of the serial port
if (byteGPS == -1) { // See if the port is empty yet
} else {
linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer
conta++;
Serial.print(byteGPS, BYTE);
if (byteGPS==13){ // If the received byte is = to 13, end of transmission
digitalWrite(ledPin, LOW);
cont=0;
bien=0;
for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR
if (linea[i]==comandoGPR[i-1]){
bien++;
}
}
if(bien==6){ // If yes, continue and process the data
for (int i=0;i<300;i++){
if (linea[i]==','){ // check for the position of the "," separator
indices[cont]=i;
cont++;
}
if (linea[i]=='*'){ // ... and the "*"
indices[12]=i;
cont++;
}
}
Serial.println(""); // ... and write to the serial port
Serial.println("");
Serial.println("$---------------");
for (int i=0;i<12;i++){
switch(i){
case 0 :Serial.print("Time in UTC (HhMmSs): ");break;
case 1 :Serial.print("Status (A=OK,V=KO): ");break;
case 2 :Serial.print("Latitude: ");break;
case 3 :Serial.print("Direction (N/S): ");break;
case 4 :Serial.print("Longitude: ");break;
case 5 :Serial.print("Direction (E/W): ");break;
case 6 :Serial.print("Velocity in knots: ");break;
case 7 :Serial.print("Heading in degrees: ");break;
case 8 :Serial.print("Date UTC (DdMmAa): ");break;
case 9 :Serial.print("Magnetic degrees: ");break;
case 10 :Serial.print("(E/W): ");break;
case 11 :Serial.print("Mode: ");break;
case 12 :Serial.print("Checksum: ");break;
}
for (int j=indices[i];j<(indices[i+1]-1);j++){
Serial.print(linea[j+1]);
}
Serial.println("");
}
Serial.println("$---------------");
delay(1000);
}
conta=0; // Reset the buffer
for (int i=0;i<300;i++){ //
linea[i]=' ';
}
}
}
}
#------- leitura e escrita no cartão
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
updated 2 Dec 2010
by Tom Igoe
This example code is in the public domain.
*/
#include <SD.h>
File myFile;
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop()
{
// nothing happens after setup
}
Tags:
Opa.. segue exemplo que estou usando, falta agora só colocar o LCD!!
#include <SD.h>
#include <SoftwareSerial.h>
const int chipSelect = 4;
SoftwareSerial mySerialGps(2, 3);
#define BUFFSIZ 90
char buffer[BUFFSIZ];
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
mySerialGps.begin(4800);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}
void loop()
{
readline();
if (strncmp(buffer, "$GPRMC",6) == 0 || strncmp(buffer, "$GPGSA",6) == 0 || strncmp(buffer, "$GPGSV",6) == 0) {
//abrir o arquivo. Observe que apenas um arquivo pode ser aberto de cada vez
//então você tem que fechar isso antes de abrir outro
File dataFile = SD.open("gps.log", FILE_WRITE);
//se o arquivo está disponível, escreva para ele:
if (dataFile) {
dataFile.println(buffer);
dataFile.close();
// imprimir para a porta serial também:
Serial.println(buffer);
}
//se o arquivo não estiver aberto, aparecerá um erro:
else {
Serial.println(buffer);
//Serial.println("error opening gps.log");
}
}
//delay(1000);
}
void readline(void) {
char c;
char buffidx = 0;
while (1) {
c = mySerialGps.read();
if (c == -1) continue;
if (c == '\n') continue;
if ((buffidx == BUFFSIZ-1) || (c == '\r')) {
buffer[buffidx] = 0;
return;
}
buffer[buffidx++]= c;
}
}
Acabei de gravar, vou testar e retorno já já...
Vcs são rápidos mesmo..rsrs
Pois é Marcio, mudei as portas do gps 0 e 1 e do cartão SD para 10.
Mas na saida serial só aparece a mensagem "Initializing SD card...card initialized.".
E não grava nada no cartão...oque pode ser?
Abraços.
Então, eu consegui fazer funcionar usando as portas 2 e 3 para o GPS via SoftwareSerial e o SD usei o esquema anexo! Peguei no forum do arduino (http://www.arduino.cc/forum/ -> internacional -> portugues)
opa...olha a saida...
$GPGSV,1,1,01,29,,,35*75
$GPGSA,M,1,,,,,,,,,,,,,,,*12
$GPGSV,1,1,01,29,,,36*76
na porta 2 e 3... mas falta algo não?
muito obrigado
é isso mesmo, o GPS está em uma área que possa receber dados? deixa para o lado de fora um tempo, ja ja começa a aparecer mais informação..fiz um teste legal, dei uma volta de carro salvando dados no cartão, depois abri o google Earth e importei os dados (salvar como .log) ele mostra o trajeto que fiz com o carro...
opa...Tá ai Marcio...
$GPGSV,3,1,$GPGGA,004150.000,2335.4380,S,04637.5708,W,1,3,11.09,77.2,M,-3.5,M,,*44
$GPGSA,A,2,14,30,29,,,,,,,,,,11.13,11.09,1.00*04
$GPGSV,3,1,1$GPGGA,004151.000,2335.4379,S,04637.5714,W,1,3,11.08,77.4,M,-3.5,M,,*49
$GPGSA,A,2,14,30,29,,,,,,,,,,11.12,11.08,1.00*04
Realmente demora um pouco, com outro exemplo tinha sido mais rápido para pegar o sinal.
Se bem que hoje está nublado pacas..rs.
Agora preciso aprender oque cada linha e cada item significa...claro, fora longitude e latitude...
De onde você é Marcio? Me ajudou e muito.
Obrigado
Um abraço.
opa.. e ai.. testei o gps com esses dois programas, fica facil de entender como funciona..
SiRFDemo, ND-100S....
sou de poços de caldas, mg e vc?
Estou procurando os programas para testar.
Valeu a dica...Sou de SP,capital.
Prazer em conhecer amigo.
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por