tiny-gps icon indicating copy to clipboard operation
tiny-gps copied to clipboard

read NMEA data from serial GPS receiver (and sonar and optical sensor) and offer it as I2C slave using ATTiny

Tiny-GPS I²C interface

by Stefan Tomanek [email protected]

Using this software, your handy little ATTiny 2313/4313 starts reading NMEA sentences from a serial GPS receiver connected to its RXD pin. These sentences are interpreted and stored in RAM, where the data can be accessed via the I²C/TWI bus connected to the SCL (PB7) and SDA (PB5) pins.

Currently, only the GPGGA and GPRMC sentences are interpreted; the data is accessible in the following format (see nav_data_t in nav_structs.h and nmea_data_t in nmea_structs.h):

byte content 0 bit flags (from lsb to msb): 0 NMEA signal is valid (1<<NMEA_RMC_FLAGS_STATUS_OK) 1 latitude alignment North (1<<NMEA_RMC_FLAGS_LAT_NORTH) 2 longitude alignment East (1<<NMEA_RMC_FLAGS_LON_EAST)

1 day 2 month 3 year (2 digits) 4 hour 5 minute 6 second 7 latitude degrees 8 latitude minutes 9/10 latitude fractions of a minute, BCD format 11 longitude degrees 12 longitude minutes 13/14 longitude fractions of a minute, BCD format 15/16 altitude in m (signed, 16 bit) 17 altitude fractions of metres, BCD format 18 signal quality 19 number of satellites used

Additionaly, a sonar device can be connected to PD2 (trigger) and PD6/ICP (echo): when configured, the controller continuously uses the ultrasonic sensor to measure the distance to any obstacle in direction of the device, which is offered via TWI and presented in cm.

20/21 distance in cm (unsigned, 16 bit)

An optical flow sensor can also be fitted to the controller via PA0 (CLK) and PA1 (DIO); the detected movement is accumulated in the optical_data_t struct accessible via TWI, the registers are cleared once the entire nav_data_t struct is read.

22/23 movement in x direction (signed, 16 bit) 24/25 movement in y direction (signed, 16 bit)

The default I²C address is 0x11 and can be changed by editing 'config.h'.

The controller polls the GPS receiver with the baud rate of 38400 bps, which is also configurable.

To enable reliable TWI communication at 400kHz, the controller has to be clocked at 8 MHz (using the internal RC oscillator is fine).

When using multiple sensors, employing an ATTiny4313 controller (due to flash/SRAM constraints of the 2313) is highly recommended.

Wiring:

             .--v--.
            -|     |- VCC
      GPS <--|  T  |--> I²C SCL
            -|  i  |--> Optical CSEL

Optical DIO <--| n |--> I²C SDA Optical CLK <--| y |- Sonar Trigger <--| 4 |- -| 3 |- -| 1 |- -| 3 |- GND -| |--> Sonar Echo `-----´