{"id":9788,"date":"2019-09-05T00:40:02","date_gmt":"2019-09-04T23:40:02","guid":{"rendered":"https:\/\/stevepedwards.today\/probook\/ElectronicsStuff\/?p=8507"},"modified":"2019-09-05T00:40:02","modified_gmt":"2019-09-04T23:40:02","slug":"showing-gps-and-dht11-temp-humidity-in-128x32-oled-with-2-text-sizes-2","status":"publish","type":"post","link":"https:\/\/stevepedwards.today\/ElectronicsStuff\/showing-gps-and-dht11-temp-humidity-in-128x32-oled-with-2-text-sizes-2\/","title":{"rendered":"Showing GPS and DHT11 Temp\/Humidity in 128\u00d732 OLED with 2 Text Sizes"},"content":{"rendered":"<p>This code adds DHT data and removes the serialmon data to thin the code. Also showing the only next text size up from size 1-2 in the OLED.<\/p>\n<p><iframe loading=\"lazy\" title=\"GPS and DHT11 data in OLED, two text sizes\" width=\"1778\" height=\"1000\" src=\"https:\/\/www.youtube.com\/embed\/XskjT-WUXOI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<pre class=\"lang:default decode:true \">\/******************************************************************************\n  Steve_GPS_OLED.ino to display GPS and DHT11 data in OLED, adapted from:\n  TinyGPSPlus_GPS_Shield.ino\n  TinyGPS++ Library Example for the SparkFun GPS Logger Shield\n  By Jim Lindblom @ SparkFun Electronics\n  February 9, 2016\n  https:\/\/stevepedwards.today\/github.com\/sparkfun\/GPS_Shield\n  This example uses SoftwareSerial to communicate with the GPS module on\n  pins 8 and 9. It uses the TinyGPS++ library to parse the NMEA strings sent\n  by the GPS module, and prints interesting GPS information to the serial\n  monitor.\n  After uploading the code, open your serial monitor, set it to 9600 baud, and\n  watch for latitude, longitude, altitude, course, speed, date, time, and the\n  number of visible satellites.\n  Resources:\n  TinyGPS++ Library  - https:\/\/stevepedwards.today\/github.com\/mikalhart\/TinyGPSPlus\/releases\n  SoftwareSerial Library\n  Development\/hardware environment specifics:\n  Arduino IDE 1.6.7\n  GPS Logger Shield v2.0 - Make sure the UART switch is set to SW-UART\n  Arduino Uno, RedBoard, Pro, etc.\n\n  OLED pins from front are 1 to Nano 5v, 2 to Nano pin GND, 3 to Nano pin A4, 4 to Nano pin A5;\n  Neo7 GPS pins from front are pin 1 to Nano D9, pin2 to D8, pin 3 to GND, pin 4 to Nano 5V;\n******************************************************************************\/\n\/\/#include is used to include outside libraries in your sketch.\n\n\/\/ 0\/1 UART for programming\/Serial monitor-ing, use SoftwareSerial:\n#include &lt;SoftwareSerial.h&gt;\n#include &lt;Adafruit_GFX.h&gt;\n#include &lt;Adafruit_SSD1306.h&gt;\n#include &lt;TinyGPS++.h&gt; \/\/ Include the TinyGPS++ library\n#include \"dht.h\"\n#define dht_apin A0 \/\/ Analog Pin sensor is connected to\n\/\/ #define is a useful C component that allows the programmer to give a name to a\n\/\/constant value before the program is compiled.\n\n#define ARDUINO_GPS_RX 9 \/\/ GPS TX, Arduino RX pin\n#define ARDUINO_GPS_TX 8 \/\/ GPS RX, Arduino TX pin\n#define gpsPort ssGPS  \/\/ Alternatively, use Serial1 on the Leonardo\n\/\/ Define the serial monitor port. On the Uno, and Leonardo this is 'Serial'\n\/\/  on other boards this may be 'SerialUSB'\n#define SerialMonitor Serial\n#define GPS_BAUD 9600 \/\/ GPS module baud rate. GP3906 defaults to 9600.\n\/\/ If you're using an Arduino Uno, RedBoard, or any board that uses the\n\/\/ 0\/1 UART for programming\/Serial monitor-ing, use SoftwareSerial:\n\/\/ OLED screen type parameters\n#define SCREEN_WIDTH 128 \/\/ OLED display width, in pixels\n#define SCREEN_HEIGHT 32 \/\/ OLED display height, in pixels\n\/\/ Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)\n#define OLED_RESET     4 \/\/ Reset pin # (or -1 if sharing Arduino reset pin)\ndht DHT;\nTinyGPSPlus tinyGPS; \/\/ Create a TinyGPSPlus object\n\n\/\/ NOTE: This define has to be placed below the Adafruit library it comes from as page is read top down!\nAdafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &amp;Wire, OLED_RESET);\n\nSoftwareSerial ssGPS(ARDUINO_GPS_TX, ARDUINO_GPS_RX); \/\/ Create a SoftwareSerial\n\/\/ Set gpsPort to either ssGPS if using SoftwareSerial or Serial1 if using an\n\/\/ Arduino with a dedicated hardware serial port\n\n\/\/ Integers are your primary data-type for number storage.\n\/\/ (minimum value of -2^15 and a maximum value of (2^15) - 1)\n\/\/ Arduino takes care of dealing with negative numbers for you\nint m = 0; \/\/ global constant to reserve mem for this data, feet to meters later\n\n\/\/ The void keyword is used only in function declarations.\n\/\/ It indicates that the function is expected\n\/\/ to return no information to the function from which it was called.\n\/\/ The setup() function is called when a sketch starts. Use it to initialize\n\/\/variables, pin modes, start using libraries, etc. The setup function will only\n\/\/run once,after each powerup or reset of the Arduino board.\nvoid setup()  {\n  Serial.begin(9600);\n  DHT.read11(dht_apin);\n  SerialMonitor.begin(9600);\n  gpsPort.begin(GPS_BAUD);\n  \/\/ SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally\n  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { \/\/ Address 0x3C for 128x32\n    Serial.println(F(\"SSD1306 allocation failed\"));\n    \/\/ Address 0x3C for 128x32\n    for(;;); \/\/ Don't proceed, loop forever\n  }\n} \/\/ end setup\n\nvoid printGPS_OLED()  {\n  \/\/ OLED screen page 1\n  \/\/ Print latitude, longitude, altitude in feet, course, speed, date, time,\n  \/\/ and the number of visible satellites.\n  display.clearDisplay();\n  display.setTextSize(1);      \/\/ Normal 1:1 pixel scale\n  display.setTextColor(WHITE); \/\/ Draw white text\n  display.setCursor(0, 0);     \/\/ Start at top-left corner\n  display.cp437(true);         \/\/ Use full 256 char 'Code Page 437' font\n  display.print(\"Lat: \"); display.println(tinyGPS.location.lat(), 6);\n  display.print(\"Long: \"); display.println(tinyGPS.location.lng(), 6);\n  display.print(\"Alt: \"); display.print(tinyGPS.altitude.feet()); display.println(\" feet\");\n  int m = (tinyGPS.altitude.feet()) \/ 3.28084; \/\/ conv ft to meters\n  display.print(\"Alt: \"); display.print(m); display.print(\" meters\");\n  display.display();\n  delay(3000);\n  \/\/ OLED screen page 2\n  display.clearDisplay();\n  display.setTextSize(1);      \/\/ Normal 1:1 pixel scale\n  display.setTextColor(WHITE); \/\/ Draw white text\n  display.setCursor(0, 0);     \/\/ Start at top-left corner\n  display.cp437(true);         \/\/ Use full 256 char 'Code Page 437' font\n  display.print(\"Date: \"); display.print(tinyGPS.date.day());\n  display.print(\"\/\");\n  display.print(tinyGPS.date.month());\n  display.print(\"\/\");\n  display.println(tinyGPS.date.year());\n  display.print(\"Time: \"); display.print(tinyGPS.time.hour());\n  display.print(\":\");\n  if (tinyGPS.time.minute() &lt; 10) display.print('0');\n  display.print(tinyGPS.time.minute());\n  display.print(\":\");\n  if (tinyGPS.time.second() &lt; 10) display.print('0');\n  display.println(tinyGPS.time.second());\n  display.print(\"Sats: \"); display.println(tinyGPS.satellites.value());\n  display.println();\n  display.display();\n  delay(3000);\n} \/\/ end printGPS_OLED()\n\n\/\/ This custom version of delay() ensures that the tinyGPS object\n\/\/ is being \"fed\". From the TinyGPS++ examples.\nstatic void smartDelay(unsigned long ms)  {\n  unsigned long start = millis();\n  do\n  {\n    \/\/ If data has come in from the GPS module\n    while (gpsPort.available())\n      tinyGPS.encode(gpsPort.read()); \/\/ Send it to the encode function\n    \/\/ tinyGPS.encode(char) continues to \"load\" the tinGPS object with new\n    \/\/ data coming in from the GPS module. As full NMEA strings begin to come in\n    \/\/ the tinyGPS library will be able to start parsing them for pertinent info\n  } while (millis() - start &lt; ms);\n} \/\/ end smartDelay()\n\n\n\/\/ After creating a setup() function, which initializes and sets the initial values,\n\/\/ loop section loops forever so contained functions from above update new data values from GPS\n\/\/ and print to serialmon and OLED\nvoid loop() {\n  DHT.read11(dht_apin);\n  display.clearDisplay();\n  display.setTextSize(2);      \/\/ Normal 1:1 pixel scale\n  display.setTextColor(WHITE); \/\/ Draw white text\n  display.setCursor(0, 0);     \/\/ Start at top-left corner\n  display.cp437(true);         \/\/ Use full 256 char 'Code Page 437' font\n    display.print(\"humidity %\");\n    display.println();\n    display.print(DHT.humidity);\n    display.display();\n    delay(3000);\n    display.clearDisplay();\n  display.setTextSize(2);      \/\/ Normal 1:1 pixel scale\n  display.setTextColor(WHITE); \/\/ Draw white text\n  display.setCursor(0, 0);     \/\/ Start at top-left corner\n  display.cp437(true);         \/\/ Use full 256 char 'Code Page 437' font\n    display.print(\"temp C\");\n    display.println();\n    display.print(DHT.temperature);\n    display.display();\n    delay(3000);\/\/Wait 5 seconds before accessing sensor again.\n\n  printGPS_OLED(); \/\/ function calling the GPS data to display in the OLED\n\n  \/\/ \"Smart delay\" looks for GPS data while the Arduino's not doing anything else\n  smartDelay(1000);\n} \/\/end loop<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This code adds DHT data and removes the serialmon data to thin the code. Also showing the only next text size up from size 1-2 in the OLED. \/****************************************************************************** Steve_GPS_OLED.ino to display GPS and DHT11 data in OLED, adapted from: TinyGPSPlus_GPS_Shield.ino TinyGPS++ Library Example for the SparkFun GPS Logger Shield By Jim Lindblom @ SparkFun <a href=\"https:\/\/stevepedwards.today\/ElectronicsStuff\/showing-gps-and-dht11-temp-humidity-in-128x32-oled-with-2-text-sizes-2\/\" class=\"more-link\">...<span class=\"screen-reader-text\">  Showing GPS and DHT11 Temp\/Humidity in 128\u00d732 OLED with 2 Text Sizes<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9788","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/posts\/9788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/comments?post=9788"}],"version-history":[{"count":0,"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/posts\/9788\/revisions"}],"wp:attachment":[{"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/media?parent=9788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/categories?post=9788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/tags?post=9788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}