lunes, 9 de mayo de 2016

Arduino - Shield SD Card.

El Proyecto consiste en guardar en una tarjeta SD los datos generados por el GPS: Latitud, Longuitud, Fecha, Hora y Altura. Para posteriormente ser leídos e interpretados por alguna aplicación web, objeto mostrar la ruta realizada.

 

Recopilación de páginas que me ayudaron en el Proyecto:

https://electronicavm.net/2011/11/05/arduino-shield-tarjeta-sd/

https://www.youtube.com/watch?v=_2XbBMeAfZ4  

Video Tutorial:
Parte 1:
https://www.youtube.com/watch?v=tmTkOFGdcas

Parte 2:
https://www.youtube.com/watch?v=Zgp56wTpuX0 

Explicación de los PINES.
 
http://mindstormsyarduino.blogspot.cl/2011/06/arduino-y-la-comunicacion-spi.html


Imagenes:








https://es.wikipedia.org/wiki/Serial_Peripheral_Interface

 
 

 

martes, 26 de abril de 2016

Arduino y el módulo GPS 6M v2 / GY - GPS6MV2

En este proyecto vamos a conectar el Arduino UNO con el módulo GY - GPS6MV2.
Esta página recopila información de otras páginas con el objeto de concentrar toda la información sobre el proyecto.

El módulo lo pueden comprar en Aliexpress por 10 Dólares:
http://www.aliexpress.com/item/Hot-Sale-Ublox-GY-NEO6MV2-GPS-Module-Aircraft-Flight-Controller-For-Arduino-APM-2-5-Module/32611247335.html

Acá en Deal Extreme:
http://www.dx.com/p/gy-neo6mv2-flight-controller-gps-module-blue-232595#.VymGENThDIU

Características encontradas en la red:

Power supply : 3V-5V
Models          : GY - GPS6MV2
Module with ceramic antenna, signal strong
EEPROM save the configuration parameter data when power down
With data backup battery
The LED signal lights
The default baud rate    : 9600
Compatible with various flight control modules
Module size                  : 25 mm x35 mm/0.98''x1.37''(inch) (approx)
The antenna size          : 25x 25 mm/0.98''x0.98''

Modo de comunicación : nivel TTL, compatible con 3.3 v sistema / 5v


Español:
Fuente de alimentación  : 2.7 - 5v dc
Trabajo actual                : 45mA
Txd RXD impedancia      : 510 R
Por defecto la velocidad de transmisión: 9600
Tiempo de la captura    : arranque en caliente: 1s
Arranque en frío            : 27s
Temperatura de trabajo : -40 ~ 85°
Exactitud posicional     : 5m
Tamaño del módulo      : 25 mm x35 mm / 0.98''x1.37'' (pulgadas) (aprox.)
Tamaño de la antena    : 25x 25 mm / 0.98''x0.98''
























Materiales:

- Arduino UNO
- Modulo GPS 6MV versión 2

Conectar el Arduino de la siguiente manera:
Deben ir Cruzados los Rx con los Tx:

Pin Arduino        Pin GPS
3.3V   -------------> VCC
3         -------------> RX
       -------------> TX
GND   -------------> GND


En el siguiente esquema hay que cambiar el valor donde dice 4800 a 9600 Baudios 
OJO: https://www.youtube.com/watch?v=8u3TRo6meLQ

Página del autor: 
http://electrotec.pe/blog/GPS



En este esquema utilizan resistencias:
http://arduinostuff.blogspot.cl/2014/05/neo6mv2-gps-module-with-arduino-uno-how.html
Página del autor : https://github.com/mikalhart




Hay que descargar una librería para trabajar con el módulo GPS:

Acá se explica el código: http://arduiniana.org/libraries/tinygps/


Dentro de esta librería yo utilice el programa de ejemplo : test_with_gps_device
en el cual, tal como lo dicen en el video y las páginas, hay que cambiar el valor de 4800 a 9600 Baudios para que funcione, de lo contrario solo aparecen asteriscos.
Sin no hay señal tambien aparecen asteriscos ********.

Download the TinyGPS library here: https://github.com/mikalhart/TinyGPS/releases/tag/v13.

Otra librería encontrada, pero aún no probada:
http://arduiniana.org/2013/09/tinygps-a-new-view-of-global-positioning/

Como instalar una librería :  http://www.arduinocolombia.com/aprende/instalacion-de-una-nueva-libreria/


Página donde aparecen mas ejemplos de proyectos: http://fritzing.org/projects/

Funciones:
library_version()
gps.satellites()
gps.hdop()
gps.f_get_position()
gps.f_altitude()
gps.f_course()
gps.f_speed_kmph()
gps.stats()
gps.encode()
gps.crack_datetime()

distance_between()
course_to()
cardinal()


Detalle:

#######################################
# Syntax Coloring Map for TinyGPS
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

TinyGPS KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

encode          KEYWORD2
get_position    KEYWORD2
get_datetime    KEYWORD2
altitude        KEYWORD2
speed           KEYWORD2
course          KEYWORD2
stats           KEYWORD2
f_get_position  KEYWORD2
crack_datetime  KEYWORD2
f_altitude      KEYWORD2
f_course        KEYWORD2
f_speed_knots   KEYWORD2
f_speed_mph        KEYWORD2
f_speed_mps        KEYWORD2
f_speed_kmph       KEYWORD2
library_version    KEYWORD2
distance_between   KEYWORD2
course_to          KEYWORD2
satellites         KEYWORD2
hdop               KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

GPS_INVALID_AGE         LITERAL1
GPS_INVALID_ANGLE       LITERAL1
GPS_INVALID_ALTITUDE    LITERAL1
GPS_INVALID_DATE        LITERAL1
GPS_INVALID_TIME        LITERAL1
GPS_INVALID_HDOP        LITERAL1
GPS_INVALID_SATELLITES  LITERAL1
GPS_INVALID_F_ANGLE     LITERAL1
GPS_INVALID_F_ALTITUDE  LITERAL1
GPS_INVALID_F_SPEED     LITERAL1


Datos entregados:
Sats : Número de Satélites.
HDOP : Dilución de precisión para la posición.

Latitude  (deg)    : Latitud en Grados.



Longitude (deg)  : Longuitud en Grados.

Fix Age : 

Date : Fecha; mes,día,año
Time : Hora ;  hora, minutos, segundos.

Date Age :
Alt  (m) : Altura en Metros. 

Course - from GPS : Curso del GPS
Speed - from GPS : Velocidad del GPS
Card - from GPS : Punto Cardinal del GPS

Chars RX :
Sentences RX :
Checksum Fail :

Para referenciar los pines : SoftwareSerial(rxPin, txPin, inverse_logic) 

Ayuda Arduino : http://www.arduino.cc/en/Reference/HomePage

Código:

#include <SoftwareSerial.h>
#include <TinyGPS.h>

/* This sample code demonstrates the normal use of a TinyGPS 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).
*/

TinyGPS gps;
SoftwareSerial ss(4, 3);

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);

void setup()
{
  Serial.begin(115200);
  
  Serial.print("Testing TinyGPS library v. "); 
  Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
  Serial.println("Sats HDOP Latitude  Longitude  Fix  Date       Time     Date Alt    Course
  Speed Card  Distance Course Card  Chars Sentences Checksum");
  Serial.println("          (deg)     (deg)      Age                      Age  (m)    --- from GPS ----  
  ---- to London  ----  RX    RX        Fail");
  Serial.println("----------------------------------------------------------------------------------------------
  ---------------------------------------");

  ss.begin(9600);
}

void loop()
{
  float flat, flon;
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;
  static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
  
  print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
  print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
  gps.f_get_position(&flat, &flon, &age);
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6);
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  print_date(gps);
  print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 7, 2);
  print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
  print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
  print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0xFFFFFFFF : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
  print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? TinyGPS::GPS_INVALID_F_ANGLE : TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);

  gps.stats(&chars, &sentences, &failed);
  print_int(chars, 0xFFFFFFFF, 6);
  print_int(sentences, 0xFFFFFFFF, 10);
  print_int(failed, 0xFFFFFFFF, 9);
  Serial.println();
  
  smartdelay(1000);
}

static void smartdelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void print_float(float val, float invalid, int len, int prec)
{
  if (val == invalid)
  {
    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 print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, "*******");
  else
    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 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)
    Serial.print("********** ******** ");
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ",
        month, day, year, hour, minute, second);
    Serial.print(sz);
  }
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  smartdelay(0);
}

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


Para ver las coordenadas en el mapa hay que crear un archivo con la DATA e 
ingresar ahttp://www.gpsvisualizer.com/  
Tener la Latitud y Longuid como primeros datos de la línea.