Hi all!
I have some problems getting my GTPA010 (MediaTek MTK 3329 GPS 10Hz) running on Arduino Mega Rev. 3. I am using I2C connection (have an adapter for it). I tried the following code, which I found on the web:
#include <Wire.h>
#define I2C_GPS_ADDRESS 0x20
/*************** I2C GSP register definitions *********************************/
#define I2C_GPS_STATUS 0x00 //(Read only)
#define I2C_GPS_GROUND_SPEED 0x07 //GPS ground speed in m/s*100 (uint16_t) (Read Only)
#define I2C_GPS_ALTITUDE 0x09 //GPS altitude in meters (uint16_t) (Read Only)
#define I2C_GPS_TIME 0x0b //UTC Time from GPS in hhmmss.sss * 100 (uint32_t)(unneccesary precision) (Read Only)
#define I2C_GPS_DISTANCE 0x0f //Distance between current pos and internal target location register in meters (uint16_t) (Read Only)
#define I2C_GPS_DIRECTION 0x11 //direction towards interal target location reg from current position (+/- 180 degree) (read Only)
#define I2C_GPS_LOCATION 0x13 //current position (8 bytes, lat and lon, 1 degree = 10 000 000 (read only)
//**************************************************************
// Second byte will be from 'address'+1
unsigned char GPS_1_byte_read(unsigned char address)
{
Wire.beginTransmission(I2C_GPS_ADDRESS);
Wire.send(address);
Wire.endTransmission();
Wire.requestFrom(I2C_GPS_ADDRESS, 1);
while(Wire.available()<1);
Wire.endTransmission();
return Wire.receive();
}
int GPS_2_byte_read(unsigned char address)
{
unsigned char msb, lsb;
Wire.beginTransmission(I2C_GPS_ADDRESS);
Wire.send(address);
Wire.endTransmission();
Wire.requestFrom(I2C_GPS_ADDRESS, 2);
while(Wire.available()<2) ;
msb = Wire.receive();
lsb = Wire.receive();
Wire.endTransmission();
return (int) lsb8 | msb;
}
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(38400); // start serial for output
Serial.println("Starting:");
}
void loop()
{
Wire.begin();
Serial.println(GPS_1_byte_read(I2C_GPS_STATUS), HEX);
Serial.println(GPS_2_byte_read(I2C_GPS_ALTITUDE), DEC);
Wire.endTransmission();
delay(500);
}
Unfortunately the code does not work as expected. I put in some outputs and found out that the code does not continue after the line while(Wire.available()<1); . Since I am new to the subject, I do not understand what this line is doing and why the code does not continue. Moreover, what value should Serial.begin() have and what about the definition of the hex addresses like I2C_GPS_STATUS 0x00? Are this addresses correct?
Can someone please help me to get the stuff working? Thank you very much to all of you.
Best regards, Michael
Tags:
Wire.available() is a call that determines if any bytes are available from I2C. Documentation here: http://arduino.cc/en/Reference/WireAvailable
So the code is basically waiting until the 2 bytes are sent by the slave. Those two bytes apparently don't arrive. Either because you're using the wrong I2C address, the wrong address for the field being read, some connectivity issue, or various other causes.
Serial.begin() specifies the baud rate for the Arduino's serial connection.
What is this adapter you mention? I gather it is a serial to I2C adapter of some sort? In which case I would imagine there's documentation on what I2C address to use and which data addresses correspond to what types of data (altitude, speed, status, etc)
Permalink Reply by Michael on July 9, 2012 at 12:08pm Hi Bot Thoughts!
Thank you very much for your answer. Indeed, I was already thinking that it might be an addressing issue. The adapter I mentioned was sold by DIY Drones in 2010/2011. Unfortunately I can not find an image of it in the internet. I am currently abroad, but will return within this week. As soon as I am back I will post a picture and/or naming of the device and I will try getting the GPS running with other addresses. I found in the meanwhile several other posts were people used 0x40instead of 0x20. I will give this a try......
Best regards, Michael
Permalink Reply by Michael on July 21, 2012 at 3:30am Hi all,
Finally, I got it fixed. It was a stupid wiring error of mine. Since I bought the GPS two years ago I did not spend much time on thinking about the correct wiring, because I felt confident in what I was doing. Bad thinking..... I am now using serial connection and the GPS_NMEA_test.pde from the ArduPlane repository. It work fine.
Cheers, Michael
Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.1277 members
24 members
183 members
246 members
179 members
© 2013 Created by Chris Anderson.
Powered by
