OK here is my code. The Serial.print return the messages from the sub code thats now ok.
I see two lines the is in the code created, but there is no value from my GPS
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h>
#include <NeoSWSerial.h>
#include <NMEAGPS.h>
#include <U8g2lib.h>
U8G2_SH1106_128X64_NONAME_2_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
Adafruit_BME680 bme; // I2C
static const int RXPin = 16, TXPin = 15;
NeoSWSerial gps_port(RXPin, TXPin);
static const uint32_t GPSBaud = 9600;
char* dayName[] = { "ZONDAG", "MAANDAG", "DINSDAG", "WOENDAG", "DONDERDAG", "VRIJDAG", "ZATERDAG" };
char* monthName[] = { "JAN", "FEB", "MAA", "APR", "MEI", "JUN", "JUL", "AUG", "SEP", "OKT", "NOV", "DEC" };
NMEAGPS gps;
static void adjustTime(NeoGPS::time_t& UTCtime);
static void printTime(gps_fix& fix);
void setup() {
Serial.begin(9600);
gps_port.begin(GPSBaud);
u8g2.begin();
if (!bme.begin()) {
while (1);
}
//bme.setTemperatureOversampling(BME680_OS_4X);
//bme.setHumidityOversampling(BME680_OS_2X);
//bme.setPressureOversampling(BME680_OS_4X);
//bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
//bme.setGasHeater(320, 150); // 320*C for 150 ms
}
void loop() {
u8g2.firstPage();
do {
draw();
(gps.available(gps_port));
gps_fix fix = gps.read();
printTime(fix);
} while (u8g2.nextPage());
}
static void printTime(gps_fix& fix) {
u8g2.drawLine(0, 16, 128, 16); //<<<<<<<<<<<<< I only see this line
u8g2.setCursor(10, 0);
u8g2.setFont(u8g2_font_5x8_mf);
Serial.println("printTime");
// Time
if (fix.valid.time) {
adjustTime(fix.dateTime);
if (fix.dateTime.hours < 10) u8g2.println('0');
u8g2.println(fix.dateTime.hours);
u8g2.println(':');
if (fix.dateTime.minutes < 10) u8g2.println('0');
u8g2.println(fix.dateTime.minutes);
u8g2.println(':');
if (fix.dateTime.seconds < 10) u8g2.println('0');
u8g2.println(fix.dateTime.seconds);
}
// Satellites
u8g2.setCursor(116, 56);
if (fix.valid.satellites) {
if (fix.satellites < 10) u8g2.println('0');
u8g2.println(fix.satellites);
}
else
u8g2.println("--"); //<<<<<<<<<<<<< And this line
Serial.println("Sat-sub");
// Date
u8g2.setCursor(0, 22); display.setCursor(0, 20);
if (fix.valid.date) {
fix.dateTime.set_day(); // set the "day" member from all the adjusted pieces
u8g2.println(dayName[fix.dateTime.day - 1]); // SUNDAY = 1, dayNames array starts at 0.
u8g2.println(' ');
if (fix.dateTime.date < 10) u8g2.println('0');
u8g2.println(fix.dateTime.date);
u8g2.println(' ');
fix.dateTime.set_day(); // set the "day" member from all the adjusted pieces
u8g2.println(monthName[fix.dateTime.month - 1]);// SUNDAY = 1, dayNames array starts at 0.
u8g2.println(' ');
if (fix.dateTime.full_year() < 10) u8g2.println('0');
u8g2.println(fix.dateTime.full_year());
}
u8g2.display();
}
static void adjustTime(NeoGPS::time_t& UTCtime)
{
NeoGPS::clock_t seconds = UTCtime;
// Daylight Savings Time rule (calculated once per reset and year!)
static NeoGPS::time_t changeover;
static NeoGPS::clock_t springForward, fallBack;
if ((springForward == 0) || (changeover.year != UTCtime.year)) {
changeover.year = UTCtime.year;
changeover.month = 3;
changeover.date = 30; // last Sunday
changeover.hours = 2; // am
changeover.minutes = 0;
changeover.seconds = 0;
changeover.set_day();
// Step back to the 4th Sunday, if day != SUNDAY
changeover.date -= (changeover.day - NeoGPS::time_t::SUNDAY);
springForward = (NeoGPS::clock_t) changeover;
changeover.month = 10;
changeover.date = 29; // last Sunday
changeover.hours = 2; // am, adjusted for DST in effect at that time
changeover.set_day();
// Step back to the 4th Sunday, if day != SUNDAY
changeover.date -= (changeover.day - NeoGPS::time_t::SUNDAY);
fallBack = (NeoGPS::clock_t) changeover;
}
// Set these values to the offset of your timezone from GMT
static const int32_t zone_hours = +1L; // CET
static const int32_t zone_minutes = 0L; // zero for CET
static const NeoGPS::clock_t zone_offset =
zone_hours * NeoGPS::SECONDS_PER_HOUR +
zone_minutes * NeoGPS::SECONDS_PER_MINUTE;
seconds += zone_offset; // adjust!
if ((springForward <= seconds) && (seconds < fallBack))
seconds += NeoGPS::SECONDS_PER_HOUR;
UTCtime = seconds; // convert back to a structure
}
void draw(void) {
if (!bme.performReading()) {
return;
}
u8g2.setFont(u8g2_font_5x8_mf);
u8g2.setCursor(0, 24);
u8g2.println(F("TEMP: = ")); u8g2.println(bme.temperature); u8g2.print(" C");
u8g2.setCursor(0, 34);
u8g2.println(F("PRES: = ")); u8g2.println(bme.pressure / 100); u8g2.println(F(" hPa"));
u8g2.setCursor(0, 44);
u8g2.println(F("HUMI: = ")); u8g2.println(bme.humidity); u8g2.println(F(" %"));
u8g2.setCursor(0, 54);
u8g2.println(F("GAS: = ")); u8g2.println(bme.gas_resistance / 1000.0); u8g2.println(F(" KOhms"));
}
Well your code shows you have two objects and your are just passing the result set of one object to another object that does not understand the result set of the first object.
You'll need to write code to parse the result set of one object and translate to a format that can be used by the other object.
Did you do the #include <NMEAGPS.h> example to see how to parse the data?
When I do only the code for the GPS same problem. When I use the SSD1306 Oled with the library from Adafruit then it works fine but with the SH1106 Oled and the u8g2 lib noting on the screen
/*
Name: GPS.ino
Created: 4/10/2020 5:15:09 PM
Author: pvandenbos
*/
#include <SPI.h>
#include <Wire.h>
#include <U8g2lib.h>
#include <NeoSWSerial.h>
#include <NMEAGPS.h>
U8G2_SH1106_128X64_NONAME_2_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
static const int RXPin = 16, TXPin = 15;
NeoSWSerial gps_port(RXPin, TXPin);
static const uint32_t GPSBaud = 9600;
static char* dayName[] = { "ZONDAG", "MAANDAG", "DINSDAG", "WOENDAG", "DONDERDAG", "VRIJDAG", "ZATERDAG" };
static char* monthName[] = { "JAN", "FEB", "MAR", "APR", "MEI", "JUN", "JUL", "AUG", "SEP", "OKT", "NOV", "DEC" };
NMEAGPS gps;
static void adjustTime(NeoGPS::time_t& UTCtime);
static void printTime(gps_fix& fix);
void setup(void) {
Serial.begin(9600);
gps_port.begin(GPSBaud);
u8g2.setFont(u8g2_font_5x8_tf);
u8g2.begin();
}
void loop() {
u8g2.firstPage();
do {
while (gps.available(gps_port)) {
gps_fix fix = gps.read();
printTime(fix);
}
} while (u8g2.nextPage());
}
static void printTime(gps_fix& fix) {
u8g2.drawLine(0, 16, 127, 16);
u8g2.setCursor(10, 0);
// Time
if (fix.valid.time) {
adjustTime(fix.dateTime);
if (fix.dateTime.hours < 10) u8g2.print('0');
u8g2.print(fix.dateTime.hours);
u8g2.print(':');
if (fix.dateTime.minutes < 10) u8g2.print('0');
u8g2.print(fix.dateTime.minutes);
u8g2.print(':');
if (fix.dateTime.seconds < 10) u8g2.print('0');
u8g2.print(fix.dateTime.seconds);
}
// Satellites
u8g2.setCursor(116, 56);
if (fix.valid.satellites) {
if (fix.satellites < 10) u8g2.print('0');
u8g2.print(fix.satellites);
}
else
u8g2.print("--");
// Date
u8g2.setCursor(0, 22); // display.setCursor(0, 20);
if (fix.valid.date) {
fix.dateTime.set_day(); // set the "day" member from all the adjusted pieces
u8g2.print(dayName[fix.dateTime.day - 1]); // SUNDAY = 1, dayNames array starts at 0.
u8g2.print(' ');
if (fix.dateTime.date < 10) u8g2.print('0');
u8g2.print(fix.dateTime.date);
u8g2.print(' ');
fix.dateTime.set_day(); // set the "day" member from all the adjusted pieces
u8g2.print(monthName[fix.dateTime.month - 1]); // SUNDAY = 1, dayNames array starts at 0.
u8g2.print(' ');
if (fix.dateTime.full_year() < 10) u8g2.print('0');
u8g2.print(fix.dateTime.full_year());
}
u8g2.sendBuffer();
}
static void adjustTime(NeoGPS::time_t& UTCtime)
{
NeoGPS::clock_t seconds = UTCtime;
// Daylight Savings Time rule (calculated once per reset and year!)
static NeoGPS::time_t changeover;
static NeoGPS::clock_t springForward, fallBack;
if ((springForward == 0) || (changeover.year != UTCtime.year)) {
changeover.year = UTCtime.year;
changeover.month = 3;
changeover.date = 30; // last Sunday
changeover.hours = 2; // am
changeover.minutes = 0;
changeover.seconds = 0;
changeover.set_day();
// Step back to the 4th Sunday, if day != SUNDAY
changeover.date -= (changeover.day - NeoGPS::time_t::SUNDAY);
springForward = (NeoGPS::clock_t) changeover;
changeover.month = 10;
changeover.date = 29; // last Sunday
changeover.hours = 2; // am, adjusted for DST in effect at that time
changeover.set_day();
// Step back to the 4th Sunday, if day != SUNDAY
changeover.date -= (changeover.day - NeoGPS::time_t::SUNDAY);
fallBack = (NeoGPS::clock_t) changeover;
}
// Set these values to the offset of your timezone from GMT
static const int32_t zone_hours = +1L; // CET
static const int32_t zone_minutes = 0L; // zero for CET
static const NeoGPS::clock_t zone_offset =
zone_hours * NeoGPS::SECONDS_PER_HOUR +
zone_minutes * NeoGPS::SECONDS_PER_MINUTE;
seconds += zone_offset; // adjust!
if ((springForward <= seconds) && (seconds < fallBack))
seconds += NeoGPS::SECONDS_PER_HOUR;
UTCtime = seconds; // convert back to a structure
}
I am looking to get this code working with a SH1106 1.3 inch OLED display. I have previously posted on this form but I have not received a response. Now I'm looking for a way to find out what the problem is so I thought it was the "loop" that it didn't go any further. The code should work it doesn't and I don't know why.
pvdbos:
I am looking to get this code working with a SH1106 1.3 inch OLED display. I have previously posted on this form but I have not received a response. Now I'm looking for a way to find out what the problem is so I thought it was the "loop" that it didn't go any further. The code should work it doesn't and I don't know why.
Did you get the SH1106 working with just the ug8 example code?