Aventuras y Desventuras de un hobbyist

Aventuras y Desventuras de un hobbyist....

Cyclone PCB - Y rod idler redesign

Here the part already 3D printed:

Don't forget to look at the base to see the logo

Parsing NMEA sentences in C


I am starting a new project involving a GPS with Bluetooth capabilities, so far I have been able to get the information from the GPS module but it comes as NMEA sentences containing the precious data.

So before doing something fancy on the computer it is needed to decode the information

There are 19 interpreted sentences:
   $GPBOD - Bearing, origin to destination
   $GPBWC - Bearing and distance to waypoint, great circle
   $GPGGA - Global Positioning System Fix Data
   $GPGLL - Geographic position, latitude / longitude
   $GPGSA - GPS DOP and active satellites 
   $GPGSV - GPS Satellites in view
   $GPHDT - Heading, True
   $GPR00 - List of waypoints in currently active route
   $GPRMA - Recommended minimum specific Loran-C data
   $GPRMB - Recommended minimum navigation info
   $GPRMC - Recommended minimum specific GPS/Transit data
   $GPRTE - Routes
   $GPTRF - Transit Fix Data
   $GPSTN - Multiple Data ID
   $GPVBW - Dual Ground / Water Speed
   $GPVTG - Track made good and ground speed
   $GPWPL - Waypoint location
   $GPXTE - Cross-track error, Measured
   $GPZDA - Date & Time

The data I am getting comes only in 5 sentences:
   
   $GPGGA - Global Positioning System Fix Data
   $GPGSA - GPS DOP and active satellites 
   $GPGSV - GPS Satellites in view
   $GPRMC - Recommended minimum specific GPS/Transit data
   $GPVTG - Track made good and ground speed
  
From these 5 I am only interested in $GPRMC The lines of data are
something similar to these two:

eg1. $GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62
eg2. $GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68


           225446       Time of fix 22:54:46 UTC
           A            Navigation receiver warning A = OK, V = warning
           4916.45,N    Latitude 49 deg. 16.45 min North
           12311.12,W   Longitude 123 deg. 11.12 min West
           000.5        Speed over ground, Knots
           054.7        Course Made Good, True
           191194       Date of fix  19 November 1994
           020.3,E      Magnetic variation 20.3 deg East
           *68          mandatory checksum
So to decode  we need to understand that where a numeric latitude or longitude is given, the two digits immediately to the left of the decimal point are whole minutes, to the right are decimals of minutes, and the remaining digits to the left of the whole minutes are whole degrees.
      eg. 4533.35 is 45 degrees and 33.35 minutes. ".35" of a minute is exactly 21 seconds.
      eg. 16708.033 is 167 degrees and 8.033 minutes. ".033" of a minute is about 2 seconds

So I wrote a small program that outputs a json file, although I have it divided into 3 files I am posting it as a whole unit:


Once we have this file we can use it in many webapps to display the location and some information about the points, the file will look like:
There are many smart formats and visualizers to display this info such as geoJson, tileJson,
 GPX (a standard format used with many devices and programs, including Garmin's eTrex, GPSMAP, Oregon, Dakota, Colorado, & Nüvi series), Google Earth (.kml/.kmz), Google Maps routes (URLs), Geocaching.com (.loc), FAI/IGC glider logs, Microsoft Excel, Google Spreadsheets,XML feeds, Garmin Forerunner (.xml/.hst/.tcx), Timex Trainer, OziExplorer, Cetus GPS, PathAway, cotoGPS, CompeGPS, TomTom (.pgl), IGN Rando (.rdn), Emtac Trine, Suunto X9/X9i (.sdf), Fugawi, NetStumbler, and of course tab-delimited or comma-separated text.


Finally  you end up with a nice map similar the one below:


Reading 12 ADC channels on the Atmega32u4

The Atmega32u4 has 12 Analog inputs, for single ended input mode and according to its datasheet we can call the different channels changing the values on the ADMUX registers(MUX4:0) although it uses 5 bits to select the channels only 3 are really used (MUX2:0) which will allow us to go from 0-7.
According to the DataSheet we end up with 6 channels:
Also note that MUX5 should be cleared in order to use ADC0:7
000 ADC0
001 ADC1
010 N/a
011 N/a
100 ADC4
101 ADC5
110 ADC6
111 ADC7

In order to read the other 6 channels ADC8:13 we must set MUX5 and the assigments for MUX2..0 are:
000 ADC8
001 ADC9
010 ADC10
0011 ADC11
100 ADC12
101 ADC13
110 N/a
111 Temperature sensor N/a

It´s very important to note that MUX5 is not part of ADMUX as in other 8 bit AVRs but is part of  ADCSRB.
Lets start with the code: This function will initialize the ADC
The following function will get the ADC channel we want to read as parameter:
Finally for readability(vinciduino form factor) and portability I added the following defines



Then if we want to read any value we may use:

Line Following Robot - PCB board

After experimenting with my first prototype I have decided to create a proper pcb, even though the actual setup gives a good performance I´d like to try out and see how the performance is with a more rigid material such as the pcb itself. here a few screenshots of the job done so far on the design front, I am planning to each the board as soon as I can.