Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TITULO: Geolocalización con módulo GPS GY-NEO6MV2 y LCD 1602
- AUTOR:
- MARIANO DEL CAMPO GARCÍA (@2016) --> INGENIERO TÉCNICO INDUSTRIAL ESPECIALIDAD ELECTRÓNICA
- - FACEBOOK: https://www.facebook.com/mariano.delcampogarcia
- - TWITTER: https://twitter.com/MarianoCampoGa
- - CORREO: [email protected]
- DESCRIPCIÓN DEL PROGRAMA
- Con este programa vamos a comunicar un Display LCD 16x2 con Arduino mediante comunicación I2C,
- para mosrar las coordenadas de latitud y longitud, el valor de la altidud y la hora internacional
- en formato 24h, que nos entrega el módulo GPS GY-NEO6MV2 que hemos conectado a nuestro Arduino a
- través de comunicación serie (TX/RX).
- ESQUEMA DE CONEXION
- +-----+
- +----[PWR]-------------------| USB |--+
- | +-----+ |
- | GND/RST2 [ ][ ] |
- | MOSI2/SCK2 [ ][ ] A5/SCL[ ] | SCL del módulo I2C conectado al LCD 1602
- | 5V/MISO2 [ ][ ] A4/SDA[ ] | SDA del módulo I2C conectado al LCD 1602
- | AREF[ ] |
- | GND[ ] |
- | [ ]N/C SCK/13[ ] |
- | [ ]IOREF MISO/12[ ] |
- | [ ]RST MOSI/11[ ]~|
- | [ ]3V3 +---+ 10[ ]~|
- | [ ]5v -| A |- 9[ ]~|
- | [ ]GND -| R |- 8[ ] |
- | [ ]GND -| D |- |
- | [ ]Vin -| U |- 7[ ] |
- | -| I |- 6[ ]~|
- | [ ]A0 -| N |- 5[ ]~|
- | [ ]A1 -| O |- 4[ ] | TX del módulo GPS GY-NEO6MV2
- | [ ]A2 +---+ INT1/3[ ]~| RX del módulo GPS GY-NEO6MV2 a través de R=4,7K Ohms
- | [ ]A3 INT0/2[ ] |
- | [ ]A4/SDA RST SCK MISO TX>1[ ] |
- | [ ]A5/SCL [ ] [ ] [ ] RX<0[ ] |
- | [ ] [ ] [ ] |
- | UNO_R3 GND MOSI 5V ____________/
- \_______________________/
- NOTAS:
- - La alimentación y la masa del módulo LCM 1602 I2C V1 van directamente conectadas a VCC (+5V) y GND
- respectivamente.
- - Conexiones del módulo GPS GY-NEO6MV2:
- - VCC --> +3,3V de Arduino.
- - GND --> GND de Arduino.
- - RX --> a GND a través de una R=10K Ohms.
- */
- // Incluimos las librerías
- #include <SoftwareSerial.h>
- #include <LiquidCrystal_I2C.h>
- #include <Wire.h>
- #include <TinyGPS.h>
- // Declaración de los objetos
- TinyGPS gps;
- SoftwareSerial ss(4, 3); // Rx = 4 y Tx = 3
- // Terminales de conexión del LCD
- // addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- // Variables internas del programa
- static void smartdelay(unsigned long ms);
- static void print_float(float val, float invalid, int len, int prec);
- static void print_int(unsigned long val, unsigned long invalid, int len);
- static void print_date(TinyGPS &gps);
- static void print_str(const char *str, int len);
- float flat, flon;
- void setup()
- {
- lcd.begin(16,2); // Inicializamos el LCD para 16x2
- lcd.backlight(); // Encendemos la retroiluminación del LCD
- inicio_LCD(); // LLamamos a la función que inicia el LCD
- ss.begin(9600); // Comienza la comunicación serie con el GPS
- }
- void loop()
- {
- // Obtenemos las coordenadas de latitud y la longitud en grados
- gps.f_get_position(&flat, &flon);
- // Presentamos la latitud
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("<<< LATITUD >>>");
- lcd.setCursor(0, 1);
- print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6);
- smartdelay(4000); // Retardo de 4 segundos
- // Presentamos la longitud
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("<<< LONGITUD >>>");
- lcd.setCursor(0, 1);
- print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
- smartdelay(4000); // Retardo de 4 segundos
- // Presentamos la hora
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("<<< HORA >>>");
- lcd.setCursor(0, 1);
- print_date(gps);
- smartdelay(4000); // Retardo de 4 segundos
- // Presentamos la altitud
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("<<< ALTITUD >>>");
- lcd.setCursor(0, 1);
- print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 7, 2);
- smartdelay(4000); // Retardo de 4 segundos
- }
- // Función del retardo
- static void smartdelay(unsigned long ms)
- {
- unsigned long start = millis();
- do
- {
- while (ss.available())
- gps.encode(ss.read());
- } while (millis() - start < ms);
- }
- // Función para imprimir valores con coma flotante (float)
- static void print_float(float val, float invalid, int len, int prec)
- {
- if (val == invalid)
- {
- while (len-- > 1)
- lcd.print('*');
- lcd.print(' ');
- }
- else
- {
- lcd.print(val, prec);
- int vi = abs((int)val);
- int flen = prec + (val < 0.0 ? 2 : 1);
- flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
- for (int i=flen; i<len; ++i)
- lcd.print(' ');
- }
- smartdelay(0);
- }
- // Función para imprimir la hora
- static void print_date(TinyGPS &gps)
- {
- int year;
- byte month, day, hour, minute, second, hundredths;
- unsigned long age;
- gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
- if (age == TinyGPS::GPS_INVALID_AGE)
- lcd.print("****************");
- else
- {
- char sz[32];
- sprintf(sz, "%02d:%02d:%02d ",hour, minute, second);
- lcd.print(sz);
- }
- smartdelay(0);
- }
- // Función que inicializa el LCD 1602
- void inicio_LCD()
- {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Modulo GPS");
- lcd.setCursor(0, 1);
- lcd.print("& Display I2C... ");
- delay(3000);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Iniciando....");
- delay(4000);
- lcd.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment