Dog collar GPS with Arduino Mircro?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- simonwaters
- Posts: 1
- Joined: Wed Mar 19, 2014 8:49 pm
Dog collar GPS with Arduino Mircro?
I am trying to make the dog collar GPS tutorial with an Arduino micro, monochrome 128x64 breakout screen and ultimate GPS module (latest version). Can the micro do this, as when I print it to the serial everything is always 0, it works when on an Uno, but not when the screen code is added. Any ideas would be much appreciated
- adafruit_support_bill
- Posts: 88153
- Joined: Sat Feb 07, 2009 10:11 am
Re: Dog collar GPS with Arduino Mircro?
You should be able to get it working with a Micro. The original was based on a 32U4 breakout 0- the same processor used in the Micro.
- scottp3
- Posts: 80
- Joined: Wed Feb 06, 2013 2:25 pm
Re: Dog collar GPS with Arduino Mircro?
I am currently trying to do the exact same thing but I am having a great deal of trouble. Any hints?
- adafruit_support_bill
- Posts: 88153
- Joined: Sat Feb 07, 2009 10:11 am
Re: Dog collar GPS with Arduino Mircro?
Can you post more specifics about the problems you are having?I am having a great deal of trouble. Any hints?
- scottp3
- Posts: 80
- Joined: Wed Feb 06, 2013 2:25 pm
Re: Dog collar GPS with Arduino Mircro?
I have been working on this for over a month, with only limited success. The GPS dog collar was originally done on a 32u4 breakout board. I thought that a micro would be ok, seeing that it is basically the same thing with a slightly different pinout. I had tried the project with an uno, but only half of the letters came up on the screen (product 931) making the readout useless. I was told that a ram shortage was the issue, so I went to the micro seeing that it has 2.5k ram as opposed to the 2k of the uno. Well, the same thing is happening. Only half of the letters come up on the screen. The test sketch works fine for the 931, so I know that the wiring is good. There has been no soldering, seeing that my micro had it's pins when I got it. The only soldering that was done was putting header into the screen, and then I used jumper wires to go from it to the breadboard. I will post a picture below to show what it looks like. The code is the exact same that Becky Stern put out some time back, short of adding the #include spi command early in the code.
- scottp3
- Posts: 80
- Joined: Wed Feb 06, 2013 2:25 pm
Re: Dog collar GPS with Arduino Mircro?
This is a pic of the readout as it is.
- Attachments
-
- IMG_3595.jpg (480.56 KiB) Viewed 538 times
- adafruit_support_bill
- Posts: 88153
- Joined: Sat Feb 07, 2009 10:11 am
Re: Dog collar GPS with Arduino Mircro?
I don't see any issues with the wiring. I2C is pretty simple to hook up and you say that the example display code works. I don't think there is enough difference between the SPI and i2c SRAM requirements to cause that kind of problem.
Are you also using the i2c version of the constructor?The code is the exact same that Becky Stern put out some time back, short of adding the #include spi command early in the code.
- scottp3
- Posts: 80
- Joined: Wed Feb 06, 2013 2:25 pm
Re: Dog collar GPS with Arduino Mircro?
I don't know what you mean by "i2c version of the constructor". What is that exactly and I would assume that I am not seeing that I have no idea what that is. How do I change the code so that it gets the i2c version instead of the spi? I assume that is what I need to do here.
- adafruit_support_bill
- Posts: 88153
- Joined: Sat Feb 07, 2009 10:11 am
Re: Dog collar GPS with Arduino Mircro?
The i2c version of the constructor is the one that only specifies the reset pin:
Code: Select all
// initializer for I2C - we only indicate the reset pin!
Adafruit_SSD1306::Adafruit_SSD1306(int8_t reset) :
Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) {
sclk = dc = cs = sid = -1;
rst = reset;
}
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Dog collar GPS with Arduino Mircro?
Could you post your code and a description or drawing of your connections between it all? Please use the code button "</>" or
Code: Select all
tags when posting code to the forums.
- scottp3
- Posts: 80
- Joined: Wed Feb 06, 2013 2:25 pm
Re: Dog collar GPS with Arduino Mircro?
To Franklin, this is the code I am using. It came from Becky Stern and is called the GPS dog collar project. I have posted this code for you at least 2 times so far.
Code: Select all
#define OLED_DC 6 //Atmega32u4 Breakout Pin D7
#define OLED_CS 9 //Atmega32u4 Breakout Pin B5
#define OLED_CLK 5 //Atmega32u4 Breakout Pin C6
#define OLED_MOSI 4 //Atmega32u4 Breakout Pin D4 (Pin on OLED labeled DATA)
#define OLED_RESET 8 //Atmega32u4 Breakout Pin B4
//Connect GPS TX to Atmega32u4 Breakout Pin B7 (Leonardo Pin D10)
//Connect GPS RX to Atmega32u4 Breakout Pin B6 (Leonardo Pin D11)
#include <SPI.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
/* 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 3(rx) and 4(tx).
*/
TinyGPS gps;
SoftwareSerial nss(11, 10);
static void gpsdump(TinyGPS &gps);
static bool feedgps();
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);
//ENTER YOUR DESIRED DISTANCE GOAL (IN MILES)
//-------------------------------------------------------------------------------
float GOAL = 3; //Distances can include decimal points
//-------------------------------------------------------------------------------
// Maximum speed and last known position
float maxSpeed = 0;
float lastFlat = 0;
float lastFlon = 0;
long totalDistance = 0;
boolean start = 1;
int i = 0;
void setup()
{
Serial.begin(9600);
nss.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
display.clearDisplay();
display.display();
}
void loop()
{
bool newdata = false;
unsigned long start = millis();
// Every second we print an update
while (millis() - start < 1000)
{
if (feedgps())
newdata = true;
}
gpsdump(gps);
}
static void gpsdump(TinyGPS &gps)
{
float flat, flon;
unsigned long age, date, time, chars = 0;
unsigned short sentences = 0, failed = 0;
gps.f_get_position(&flat, &flon, &age);
//print_date(gps);
//gps.stats(&chars, &sentences, &failed);
//print_int(chars, 0xFFFFFFFF, 6);
//print_int(sentences, 0xFFFFFFFF, 10);
//print_int(failed, 0xFFFFFFFF, 9);
//Serial.println();
if (gps.f_speed_kmph() > 3.9)
{
if (start == 1)
{
start = 0;
lastFlat = flat;
lastFlon = flon;
}
else
{
//totalDistance = gps.distance_between(flat, flon, LONDON_LAT, LONDON_LON);
totalDistance = totalDistance + calc_dist(flat, flon, lastFlat, lastFlon);
lastFlat = flat;
lastFlon = flon;
}
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
float fDist = totalDistance;
//convert meters to miles
fDist *= 0.000621371192;
//float fSpeed = gps.f_speed_kmph();
printLCDFloat(fDist, 2);
display.print(" Miles (");
float targetDist = fDist / GOAL;
printLCDFloat(targetDist*100, 0);
display.print("%)");
display.drawLine(0, 12, 0, 31, WHITE);
display.drawLine(63, 28, 63, 31, WHITE);
display.drawLine(127, 12, 127, 31, WHITE);
display.drawLine(31, 28, 31, 31, WHITE);
display.drawLine(95, 28, 95, 31, WHITE);
display.drawLine(0, 28, 127, 28, WHITE);
display.drawLine(0, 12, 127, 12, WHITE);
display.fillRect(2, 14, (124 * targetDist), 13, 1);
if (gps.hdop() > 2000) {
//display.fillRect(2, 14, (124), 13, BLACK);
display.fillRect(0, 0, 128, 32, BLACK);
display.fillCircle(6, 6, 2, WHITE);
display.fillCircle(64, 6, 2, WHITE);
display.fillCircle(122, 6, 2, WHITE);
display.fillCircle(35, 6, 2, WHITE);
display.fillCircle(93, 6, 2, WHITE);
if (i==0){
display.drawCircle(6, 6, 4, WHITE);
}
if (i==1){
display.drawCircle(35, 6, 4, WHITE);
}
if (i==2){
display.drawCircle(64, 6, 4, WHITE);
}
if (i==3){
display.drawCircle(93, 6, 4, WHITE);
}
if (i==4){
display.drawCircle(122, 6, 4, WHITE);
i = 0;
} else {
i++;
}
display.setTextColor(WHITE);
display.setCursor(5,20);
display.print("Acquiring Satellites");
}
display.display();
}
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);
feedgps();
}
static void print_float(float val, float invalid, int len, int prec)
{
char sz[32];
if (val == invalid)
{
strcpy(sz, "*******");
sz[len] = 0;
if (len > 0)
sz[len-1] = ' ';
for (int i=7; i<len; ++i)
sz[i] = ' ';
Serial.print(sz);
}
else
{
Serial.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)
Serial.print(" ");
}
feedgps();
}
void printLCDFloat(double number, int digits)
{
// Handle negative numbers
if (number < 0.0)
{
display.print("-");
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
char sTemp[10];
ltoa(int_part, sTemp, 10);
display.print(sTemp);
// Print the decimal point, but only if there are digits beyond
if (digits > 0)
display.print(".");
// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
ltoa(toPrint, sTemp, 10);
display.print(sTemp);
remainder -= toPrint;
}
}
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);
feedgps();
}
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] : ' ');
feedgps();
}
static bool feedgps()
{
while (nss.available())
{
if (gps.encode(nss.read()))
return true;
}
return false;
}
unsigned long calc_dist(float flat1, float flon1, float flat2, float flon2)
{
float dist_calc=0;
float dist_calc2=0;
float diflat=0;
float diflon=0;
diflat=radians(flat2-flat1);
flat1=radians(flat1);
flat2=radians(flat2);
diflon=radians((flon2)-(flon1));
dist_calc = (sin(diflat/2.0)*sin(diflat/2.0));
dist_calc2= cos(flat1);
dist_calc2*=cos(flat2);
dist_calc2*=sin(diflon/2.0);
dist_calc2*=sin(diflon/2.0);
dist_calc +=dist_calc2;
dist_calc=(2*atan2(sqrt(dist_calc),sqrt(1.0-dist_calc)));
dist_calc*=6371000.0; //Converting to meters
return dist_calc;
}
- scottp3
- Posts: 80
- Joined: Wed Feb 06, 2013 2:25 pm
Re: Dog collar GPS with Arduino Mircro?
Bill, does the code you gave me go into the gps dog collar sketch or into the library code for the oled screen or what? I feel stupid here, but I have no idea what it is you are showing me. I guess I need some hand holding here.
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Dog collar GPS with Arduino Mircro?
Scott, you are using code for the SPI OLED and you have the I2C OLED. That won't work. You need to modify the code to use the I2C pins. Take a look at the example code that came with the library.
- scottp3
- Posts: 80
- Joined: Wed Feb 06, 2013 2:25 pm
Re: Dog collar GPS with Arduino Mircro?
I should have just gotten the spi version to start with. I was told that it would be easier with the i2c, but it isn't. I have gone through 2 screens and had to buy another micro controller. I can't put any more into this and I have no idea how to change the code. Thanks, but I am done.
- adafruit_support_bill
- Posts: 88153
- Joined: Sat Feb 07, 2009 10:11 am
Re: Dog collar GPS with Arduino Mircro?
It looks like you are using the correct i2c constructor:
And the i2c initialization in setup:
Though you are still pulling in the spi.h library. But I don't think that should hurt if you don't use it.
I'm not sure why the i2c display is not performing well for you. It may be due to interference from SoftwareSerial. This has been known to cause problems with other interrupt-driven libraries.
Code: Select all
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
Code: Select all
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
Code: Select all
#include <SPI.h>
Please be positive and constructive with your questions and comments.