Finished OLED/GPS example

Finished up the OLED/GPS setup, this uses a black rectangle to erase only portions of the screen where I want the text to be updated. It seems to minimize the flicker seen in the previous example. The video cuts because it takes 5-10 minutes for my GPS to start receiving from the satellites, which may have been a slightly ginormous video file to upload.

A few things to note, when using the print or println in the GFX library each character takes up 5×8 pixels(but can be biggie-sized, just look at the documentation). So the letter A printed on the first line at cursor position x=0, y=0 would end at x=5, y=8. This is useful if you want to erase just that letter. A black rectangle drawn from x=0, y=0 to x=5,y=8 would cover that entire letter. The code for that would look like this display.fillRect(0,0,5,8,BLACK); where the rectangle starts at 0,0 and ends at 5,8 with a color of Black.

The display I used is 0.96″ containing 96 pixels across, 64 down. So the center of the display is at 48,32.

This code displays a circle starting at pixel x=5, y=5 with a radius of 4. So it ends at x=9, y=9. I start my text at x=0, y=10 in order to prevent overlap.

1
2
3
4
5
   if(gps.satellites.value()<=2){     //Displays a small circle, yellow or green depending upon # of satellites acquired
    display.fillCircle(5,5,4,YELLOW);
  } else {
   display.fillCircle(5,5,4,GREEN);   //Same as the above except displays a green circle for more than 2 satellites
 }

For printing the # of satellites, latitude, and longitude the code looks like the below. This starts out by printing out a line of text, starting at x=0, y=26. This is 10 characters in length(including the space at the end), so I set the rectangle to draw at position x=50, y=26. Five pixels across multiplied by 10 is the 50th pixel in the X direction. Because I used print for the “Longitude”, when I print the gps.location.lng() its already at the x=50, y=26 position.

1
2
3
4
display.setCursor(0,26);
display.print("Longitude ");
display.fillRect(50,26,5,8,BLACK);
display.println(gps.location.lng());

Components
Arduino Uno
0.96″ OLED Breakout board from Adafruit
GP-635T GPS Module from Sparkfun

Full working example. See Adafruit.com for how to connect the OLED. GPS is connected to the Arduino Uno on TX/RX pins 0 and 1. One note, if you receive any errors like the following, its due to how the Arduino/GPS are connected, something about TX/RX interfering with the upload. Disconnecting the power to the GPS during the upload to the Uno should resolve the problem.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x01

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <TinyGPS++.h>     //TinyGPS library
#include <SoftwareSerial.h>   //Software serial library
#include <Adafruit_GFX.h>     //GFX library, from Adafruit
#include <Adafruit_SSD1331.h>   //Library for the OLED display I used. See the Adafruit product page for more info,
                                //can change depending upon the display used.
#include <SPI.h>

#define sclk 13    //next 5 lines define the pins for the OLED display. From the Adafruit GFX library
#define mosi 11
#define cs   10
#define rst  9
#define dc   8
 
                   //Defining the possible colors that can be used. From the Adafruit GFX library
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0  
#define WHITE           0xFFFF



                                           
Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, mosi, sclk, rst);  //define the display object

static const int RXPin = 0, TXPin = 1;  //RX and TX pins, connected to the Uno pins 0 1
static const uint32_t GPSBaud = 9600;  //Defining the GPS baud

                       
TinyGPSPlus gps;                         //Define the GPS object
                                         
SoftwareSerial ss(RXPin, TXPin);         //setting up the connection to the GPS using the Software serial library

void setup()
{
  ss.begin(GPSBaud);                    
  display.begin();                     //Initialize the display
  display.fillScreen(BLACK);           //Initialize the display, set it to black(makes sure that any artifacts are removed
  display.setCursor(0,0);              //Set the cursor to the top left corner
 
}

void loop()
{                                     //While loop displays an animated circle as the GPS waits on connection to satellites
   while(gps.satellites.value()==0){  
     display.fillCircle(48,32,10,RED);
     for(int i=5;i<35;i+=5){          
     display.drawCircle(48,32,i,RED);
   }
   smartDelay(1000);                  
   display.fillScreen(BLACK);        
 }                                    

   if(gps.satellites.value()<=2){     //Displays a small circle, yellow or green depending upon # of satellites acquired
    display.fillCircle(5,5,4,YELLOW);
  } else {
   display.fillCircle(5,5,4,GREEN);   //Same as the above except displays a green circle for more than 2 satellites
 }
                     
  display.setCursor(0,10);            
  display.print("Sats= ");            
                                     

  display.fillRect(30,10,6,8,BLACK);  //In order to erase only the # of satellites and not the entire line of text
  display.setCursor(31,10);           //this draws a black rectangle over pixels from x=30, y=10 with a width of 6 and height of 8
  display.println(gps.satellites.value());

  display.setCursor(0,18);            
  display.print("Latitude ");        
  display.fillRect(45,18,5,8,BLACK);
  display.println(gps.location.lat());
 
 
  display.setCursor(0,26);
  display.print("Longitude ");
  display.fillRect(50,26,5,8,BLACK);
  display.println(gps.location.lng());
 
 
  smartDelay(1000);
   if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
   
}
                                                           
                 
static void smartDelay(unsigned long ms)     //Reads string from the GPS device
{
  unsigned long start = millis();
  do
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

20140914_011509

20140914_114134

You may also like...