Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #include <TinyGPS.h>
- #include <SPI.h> //to SD library
- #include <SD.h> //to SD library
- #include <LiquidCrystal.h> //to Display library
- #include <Wire.h> //to BMP180 library
- #include <Adafruit_BMP085.h> //to BMP180 library
- #define delayBounce 80
- #define pinBotao 7 //Define o Botão A na porta 7. Botão de troca de menu
- #define pinLED1 13 //Led que indica a posiçao de troca e alerta
- #define pinLED2 A8
- #define buzzer 8
- #define chipSelect 10 //Posicion of pin cs from shield SD
- Adafruit_BMP085 bmp180;
- SoftwareSerial serial1(A3, A2); // RX, TX
- LiquidCrystal lcd(9, 6, 5, 4, 3, 2);
- TinyGPS gps1;
- int ANO;
- byte MES, DIA, HORA, MIN;
- double Lat, Lon;
- bool Botao; // Botao
- bool estadoAntBotao;
- bool estadoBotao;
- short contador = 1;
- bool imprime;
- float temperatura, pressao;
- unsigned long delay1 = 0; //Contador para o intervalo de tempo
- unsigned long delay2 = 0; //Contador para o intervalo de tempo
- unsigned long delay3 = 0; //Contador para o intervalo de tempo
- void setup() {
- pinMode(pinLED1, OUTPUT);
- pinMode(pinBotao, INPUT_PULLUP);
- serial1.begin(9600);
- Serial.begin(230400);
- lcd.begin(16, 2);
- bmp180.begin();
- Serial.println("Aguardando satélites...");
- //------------ TESTE DO CARTÃO -----------------
- if (!SD.begin(chipSelect)) {
- Serial.println("Problema no cartao");
- return;
- }
- Serial.println("Cartão inicializado");
- /*for (int n=0; n<3; n++){
- digitalWrite(buzzer, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(100); // wait for a second
- digitalWrite(buzzer, LOW); // turn the LED off by making the voltage LOW
- delay(500);
- }
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Tracker Meteo V2");
- lcd.setCursor(5, 1);
- lcd.print("Maza");
- delay(1500);
- lcd.setCursor(0, 0);
- lcd.print(" Buscando ");
- lcd.setCursor(0, 1);
- lcd.print(" Satelites ");
- Serial.println("Buscando Satelites");
- delay(1500);
- lcd.clear();
- */
- }
- void loop() {
- String dataString = "";
- bool recebido = false;
- while (serial1.available()) {
- char cIn = serial1.read();
- recebido = gps1.encode(cIn);
- }
- if (recebido) {
- Serial.println("----------------------------------------");
- //Latitude e Longitude
- long latitude, longitude;
- gps1.get_position(&latitude, &longitude);
- if (latitude != TinyGPS::GPS_INVALID_F_ANGLE) {
- Serial.print("Latitude dentro do if recebido: ");
- Lat = float(latitude) / 100000, 6;
- Serial.println(Lat);
- dataString += String(float(latitude) / 100000, 6) + ", ";
- }
- if (longitude != TinyGPS::GPS_INVALID_F_ANGLE) {
- Serial.print("Longitude dentro do if recebido: ");
- Lon = float(longitude) / 100000, 6;
- Serial.println(Lon);
- }
- //Dia e Hora
- int ano;
- byte mes, dia, hora, minuto, segundo, centesimo;
- gps1.crack_datetime(&ano, &mes, &dia, &hora, &minuto, &segundo, ¢esimo);
- DIA = dia;
- MES = mes;
- ANO = ano;
- HORA = hora;
- MIN = minuto;
- Serial.print("Data (GMT) dentro do if: ");
- Serial.print(dia);
- Serial.print("/");
- Serial.print(mes);
- Serial.print("/");
- Serial.println(ano);
- Serial.print("Horario (GMT) dentro do if: ");
- Serial.print(hora);
- Serial.print(":");
- Serial.print(minuto);
- Serial.print(":");
- Serial.print(segundo);
- Serial.print(":");
- Serial.println(centesimo);
- imprime = true;
- temperatura = bmp180.readTemperature();
- pressao = bmp180.readPressure();
- }
- if (imprime){
- Serial.println("____________________________________________");
- Serial.print("Latitude fora do if recebido: ");
- Serial.println(Lat, 6);
- Serial.print("Longitude fora do if recebido: ");
- Serial.println(Lon, 6);
- Serial.print("Data (GMT) FORA do if: ");
- Serial.print(DIA);
- Serial.print("/");
- Serial.print(MES);
- Serial.print("/");
- Serial.println(ANO);
- Serial.println(contador);
- Serial.print("Temperatura: ");
- Serial.println(temperatura);
- Serial.print("Pressão: ");
- Serial.println(pressao);
- //Serial.println(contador);
- dataString += String(Lat, 6) + ", ";
- dataString += String(Lon, 6) + ", ";
- dataString += String(DIA) + "/";
- dataString += String(MES) + "/";
- dataString += String(ANO) + ", ";
- dataString += String(HORA) + ":";
- dataString += String(MIN) + ", ";
- dataString += String(temperatura) + ", ";
- dataString += String(pressao);
- lcd.clear();
- if (contador == 1){
- lcd.setCursor(0, 0);
- lcd.print("Lat:");
- lcd.setCursor(5, 0);
- lcd.print(Lat, 6);
- lcd.setCursor(0, 1);
- lcd.print("Lon:");
- lcd.setCursor(5, 1);
- lcd.print(Lon, 6);
- }
- if(contador==2){
- lcd.setCursor(0, 0);
- lcd.print("HORA GMT:");
- lcd.setCursor(11, 0);
- lcd.print(HORA);
- lcd.setCursor(13, 0);
- lcd.print(":");
- lcd.setCursor(14, 0);
- lcd.print(MIN);
- lcd.setCursor(0, 1);
- lcd.print("DATA GMT:");
- lcd.setCursor(11, 1);
- lcd.print(DIA);
- lcd.setCursor(13, 1);
- lcd.print("/");
- lcd.setCursor(14, 1);
- lcd.print(MES);
- }
- if(contador==3){
- lcd.setCursor(0, 0);
- lcd.print("Temp:");
- lcd.setCursor(9, 0);
- lcd.print(temperatura, 2);
- lcd.setCursor(0, 1);
- lcd.print("Pressao:");
- lcd.setCursor(9, 1);
- lcd.print(pressao, 2);
- }
- imprime = 0;
- }
- //------------------------------------------------------------------------
- if ((millis() - delay2) >= delayBounce) {
- estadoBotao = digitalRead(pinBotao);
- if (!estadoBotao && estadoAntBotao){
- lcd.clear();
- if(contador<3){
- contador++;
- }else{
- contador=1;
- }
- }
- delay2 = millis();
- }
- estadoAntBotao = estadoBotao;
- //------------------------------------------------------------------------------
- if ((millis() - delay1) > 1000) {
- Serial.println("Passou a mills");
- File dataFile = SD.open("datalog.txt", FILE_WRITE);
- // if the file is available, write to it:
- if (dataFile) {
- dataFile.println("dataString");
- dataFile.close();
- Serial.print("Gravou dado no cartão: ");
- Serial.println("dataString");
- }else {
- //Sinal sonoro/visual em caso de problema na gravação. (Led Vermelho. Liga e mantem ligado se isso ocorrer)
- Serial.println("Não gravou no cartão");
- //digitalWrite(pinLED1, HIGH);
- }
- //dataString = "";
- delay1 = millis();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement