Connecting trinket m0 and i2c 128x32 OLED display

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
kevinunk
 
Posts: 7
Joined: Fri Nov 30, 2018 6:44 pm

Connecting trinket m0 and i2c 128x32 OLED display

Post by kevinunk »

Hello, first-time adafruit tinkerer here, I recently got the trinket m0 and am working through how best to set up my project.

I looking to read in GPS data from the Ultimate GPS breakout board, and then display it to a 128x32 i2c OLED display.

I'm wondering:
- is circuitpython or the arduino IDE better for this? I've tried both and for circuitpython I get "RuntimeError: SDA or SCL needs a pull up" when I try to run the example scan to get it connected, and using the arduino IDE example, nothing seems to happen.
- can a trinket m0 support both the display and gps breakout board for this project?

Thanks for your help!

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: Connecting trinket m0 and i2c 128x32 OLED display

Post by adafruit_support_carter »

Check your wiring for the SDA/SCL error message. Post a photo of your setup showing everything connected and we can take a look.

I would use Arduino for now. Display support is currently in work for CP - it is *very* near though, so keep an eye on that project.

You should be able to get this working. The GPS breakout will talk over serial while the display uses I2C. See the pinout diagram here:
https://learn.adafruit.com/adafruit-tri ... no/pinouts
GPS will attach to TX/RX while the display will attach to SCL/SDA.

User avatar
kevinunk
 
Posts: 7
Joined: Fri Nov 30, 2018 6:44 pm

Re: Connecting trinket m0 and i2c 128x32 OLED display

Post by kevinunk »

Looked like a faulty connection, but thanks for your help and confirmation that this will work! Super excited and appreciate the fast response.

User avatar
kevinunk
 
Posts: 7
Joined: Fri Nov 30, 2018 6:44 pm

Re: Connecting trinket m0 and i2c 128x32 OLED display

Post by kevinunk »

Alright, so I got the display up and running, but I am having a problem with the GPS... It seems even after the LED is indicating that the board has a fix, that the display doesn't know this still and GPS.fix is still false. Below is the code for reference. Any thoughts on how to get this to work?

Code: Select all

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GPS.h>
#include <HardwareSerial.h>
 
#define GPS_RX 3
#define GPS_TX 4
#define GPSECHO  true
Adafruit_GPS GPS(&Serial1);
uint32_t timer = millis();
short tzOffset = 0; // setting to subtract from GMT for current time zome

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

int updated = 0;
 
void setup()
{
    display.begin(SSD1306_SWITCHCAPVCC);
    display.display();
    delay(2000);
    GPS.begin(9600);
    GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
    GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
    GPS.sendCommand(PGCMD_ANTENNA);
    delay(1000);
}
 
// prints the compass heading based on the angle reported by the GPS 
void printHeading()
{
    char dir[3];
    dir[0] = ' ';
    dir[1] = ' ';
    dir[2] = ' ';
 
    if (GPS.angle > 337.25)
    {
        dir[0] = 'N';
    }
    else if (GPS.angle <= 22.5)
    {
        dir[0] = 'N';
    }
    else if (GPS.angle <= 67.5)
    {
        dir[0] = 'N';
        dir[1] = 'E';
    }
    else if (GPS.angle <= 112.5)
    {
        dir[0] = 'E';
    }
    else if (GPS.angle <= 157.5)
    {
        dir[0] = 'S';
        dir[1] = 'E';
    }
    else if (GPS.angle <= 202.5)
    {
        dir[0] = 'S';
    }
    else if (GPS.angle <= 247.5)
    {
        dir[0] = 'S';
        dir[1] = 'W';
    }
    else if (GPS.angle <= 292.5)
    {
        dir[0] = 'W';
    }
    else if (GPS.angle <= 337.5)
    {
        dir[0] = 'N';
        dir[1] = 'W';
    }
    display.print(dir[0]);
    display.print(dir[1]);
    display.print(dir[2]);
}
 
void printDateTime()
{
    short hr = GPS.hour - tzOffset;
    // check if the hr is now less than 0 i.e. before midnight after TX adjustment
    // fine if GMT - offset, need to add code to handle GMT + offset 
    if (hr < 0)
    {
        hr += 24;
    }
    if (hr  < 10)
    {
        display.print('0');
    }
    display.print(hr, DEC);
    display.print(':');
    if ((short)GPS.minute < 10)
    {
        display.print('0');
    }
    display.print(GPS.minute, DEC);
    display.print(':');
    if ((short)GPS.seconds < 10)
    {
        display.print('0');
    }
    display.print(GPS.seconds, DEC);
}
 
void updateDisplay()
{
    display.clearDisplay();
    display.setTextColor(WHITE);
    display.setCursor(0, 0);
    // the GPS will output a time without a sat fix.  
    // it often gets the sat time long before the sat location fix
    display.setTextSize(2);
    printDateTime();
    display.setTextSize(0);
    display.setCursor(110, 0);  // num sats appear in small text to the right of time
    display.print((int)GPS.satellites);
    // display the location info only if there is a sat fix
    if (GPS.fix)
    {
        display.setCursor(110, 8);
        display.print(GPS.HDOP, 1);  // HDOP appear in small text under num sats.
        // normally need a println here but the hdop value hits the end of the line and forces a new line 
        // coordinates  
        display.print(GPS.latitudeDegrees, 5); display.print(','); display.println(GPS.longitudeDegrees, 5);
        //elevation
        display.print(GPS.altitude, 0); display.print("m ");
        // only display the heading if moving otherwise it is bouncing around due to normal GPS error
        // must cast to int because speed is float value in knots and decimal values are changeing when not moving
        if ((int)GPS.speed>0)
        {
            printHeading();
        }
        else
        {
            display.print("-- ");
        }
        // speed is in knots, convert to km/h
        display.print((int)(GPS.speed*1.852)); display.println(" km/h");
    } else {
      display.setCursor(110,8);
      display.print(GPS.fix);
    }
    // refresh the display
    display.display();
}
 
void loop()
{
    char c = GPS.read();

    // if a new sentence is received
    if (GPS.newNMEAreceived()) {
        //if the GPS object can't parse it, return and wait for the next one
        if (!GPS.parse(GPS.lastNMEA()))
            return;
    }
 
    // if timer or mills wrap around, reset the timer
    if (timer > millis())  timer = millis();
 
    // update the display every second
    if (millis() - timer > 1000) {
        timer = millis(); // reset the timer
 
        updateDisplay();
    }
}

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: Connecting trinket m0 and i2c 128x32 OLED display

Post by adafruit_support_carter »

Code: Select all

    GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
When set to GGA output, use fixquality instead of fix.

See here for what the values mean:
https://www.gpsinformation.org/dale/nmea.htm#GGA

User avatar
kevinunk
 
Posts: 7
Joined: Fri Nov 30, 2018 6:44 pm

Re: Connecting trinket m0 and i2c 128x32 OLED display

Post by kevinunk »

Appreciate the help - I see what you mean, and I've updated the code accordingly, but this doesn't seem to fix anything - I still am seeing that the gps.fixquality stays zero, as do the hours, minutes, seconds readings from the GPS as well.

It could be that the GPS doesn't have a fix and so they are all zero, but I don't see any reason why it wouldn't and the LED status seems to indicate that it does eventually get the fix.

Any other ideas maybe?

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: Connecting trinket m0 and i2c 128x32 OLED display

Post by adafruit_support_carter »

Try running this simple sketch which will let you look at the raw data sentences. See if it also reports the same info.

Code: Select all

#include <Adafruit_GPS.h>

Adafruit_GPS GPS(&Serial1);

void setup() {
  Serial.begin(9600);
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);  
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  Serial.print("GPS Test...");
  delay(1000);
  Serial.println("begin.");
}

void loop() {
  GPS.read();
  if (GPS.newNMEAreceived()) {
    Serial.println(GPS.lastNMEA());
  }
 }

User avatar
kevinunk
 
Posts: 7
Joined: Fri Nov 30, 2018 6:44 pm

Re: Connecting trinket m0 and i2c 128x32 OLED display

Post by kevinunk »

I ran this code and it worked correctly, so then I ran my code again, and it seemed to work as well!

The only difference I made was powering this via the microUSB port instead of powering it using the LiPoly Backpack add on and a 3.7V mAh battery.

I read the voltage coming out of the USB pin on the Trinket when powered by the LiPoly backpack and battery and it was ~3.3V versus the 5V that seems to be coming out of it with the microUSB plugged in, so I'm not sure if I simply have the battery wired up incorrectly or at the wrong voltage but this seems to be the problem.

I'm going to go ahead and charge the battery all the way again and see if this might help to power the GPS breakout board.

User avatar
kevinunk
 
Posts: 7
Joined: Fri Nov 30, 2018 6:44 pm

Re: Connecting trinket m0 and i2c 128x32 OLED display

Post by kevinunk »

From what I can tell it looks like the USB pin voltage isn't high enough to power the VIN on the GPS breakout board when using the 3.7 mAh battery with the LiPo battery pack.. Any tips on how I might be able to fix this/work around this/what I might need?

Thanks!

User avatar
kevinunk
 
Posts: 7
Joined: Fri Nov 30, 2018 6:44 pm

Re: Connecting trinket m0 and i2c 128x32 OLED display

Post by kevinunk »

Updating in case anyone else might reference this in the future - got everything working ! Turns out that there must have been a mismatch in voltage or direction or something as powering the display and the GPS board was not working.

By powering the GPS board (VIN) off the 3.3V pin on the display I was able to get everything working 100% - thanks for the help.

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”