Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot:examples:oled [2018/02/27 14:17] Somepuben:iot:examples:oled [Unknown date] (current) – external edit (Unknown date) 127.0.0.1
Line 7: Line 7:
  
 Needed libraries: Needed libraries:
-<code>lib_deps = ITTIoT, MFRC522, Adafruit_GFX, Adafruit SSD1306</code>+<code>lib_deps = ITTIoT, Adafruit GFX Library, Adafruit SSD1306 Wemos Mini OLED, adafruit/Adafruit BusIO</code>
  
  The example code above shows counter value on screen   The example code above shows counter value on screen 
  
 <code c> <code c>
- 
 #include <Arduino.h> #include <Arduino.h>
 #include <ittiot.h> #include <ittiot.h>
 #include <Ticker.h> #include <Ticker.h>
 #include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
-#include <SPI.h> +#include <Adafruit_I2CDevice.h>
-#include <Wire.h>+
 #include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
 #include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
  
 +#define WIFI_NAME "name"
 +#define WIFI_PASSWORD "password"
 +
 +// OLED reset pin is GPIO0
 #define OLED_RESET 0  // GPIO0 #define OLED_RESET 0  // GPIO0
  
 Ticker timeTicker; Ticker timeTicker;
-Adafruit_SSD1306 display(OLED_RESET);+Adafruit_SSD1306 display(OLED_RESET); // Create an object for OLED screen
  
-// ITT splashs screen bitmap. Generator: http://javl.github.io/image2cpp/+bool isBootModeNormal; 
 +bool sendDataFlag; 
 + 
 +int i = 0; // Counter variable is defined 
 + 
 +// ITT splashs screen bitmap. Generator can be found in: http://javl.github.io/image2cpp/
 static const unsigned char PROGMEM logo16_glcd_bmp[] = static const unsigned char PROGMEM logo16_glcd_bmp[] =
 { {
Line 55: Line 62:
  0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00  0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 }; };
- 
-#if (SSD1306_LCDHEIGHT != 48) 
-#error("Height incorrect, please fix Adafruit_SSD1306.h!"); 
-#endif 
- 
-bool isBootModeNormal; 
-bool sendDataFlag; 
- 
-int i = 0; 
  
 // Ticker library callback, which will occur 0.5 second interval. // Ticker library callback, which will occur 0.5 second interval.
Line 69: Line 67:
 { {
   sendDataFlag=true;   sendDataFlag=true;
 +}
 +
 +// If message received print it out.
 +void iot_received(String topic, String msg)
 +{
 +  Serial.print("MSG FROM USER callback, topic: ");
 +  Serial.print(topic);
 +  Serial.print(" payload: ");
 +  Serial.println(msg);
 } }
  
Line 81: Line 88:
 void setup() void setup()
 { {
-  Serial.begin(115200);+  Serial.begin(115200); // setting up serial connection parameter
   Serial.println("Booting");   Serial.println("Booting");
  
Line 87: Line 94:
   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  
-  // Since the buffer is intialized with an Adafruit splashscreen+  // Since the buffer is initialized with an Adafruit splashscreen
   // internally, we should clear it   // internally, we should clear it
   display.clearDisplay();   display.clearDisplay();
Line 98: Line 105:
   // Display splashscreen two second   // Display splashscreen two second
   delay(2000);   delay(2000);
 +
 +  //iot.setConfig("wname", WIFI_NAME);
 +  //iot.setConfig("wpass", WIFI_PASSWORD);
  
   // print IoT json config to serial   // print IoT json config to serial
Line 109: Line 119:
 } }
  
 +// Main code, which runs in loop
 void loop() void loop()
 { {
Line 114: Line 125:
   iot.handle();   iot.handle();
  
-  // Increase counter value+  // Increase counter value by 1
   i++;   i++;
  
-  // Display counter value and boot mode on the OLED screen +  // Display counter value on the OLED screen 
-  display.clearDisplay(); +  display.clearDisplay(); // clears the srceen 
-  display.setTextSize(1); +  display.setTextSize(1); // sets the text size for the screen 
-  display.setTextColor(WHITE); +  display.setTextColor(WHITE); // text color is set to white 
-  display.setCursor(0,0); +  display.setCursor(0,0); // position from where the text writing is starting 
-  display.println("Counter: "); +  display.println("Counter: "); // a text is send to the screen 
-  display.println(i); +  display.println(i); // counter value is send to the screen 
- +  display.display(); // show image
-  display.setCursor(0,30); +
- +
-  if(isBootModeNormal) +
-  { +
-    display.println("Mode: NORM"); +
-  } +
-  else +
-  { +
-    display.println("Mode: BOOT"); +
-  } +
- +
-  display.display();+
  
-  // Send counter value to the server+  // Send counter value to the computer
   if(WiFi.isConnected() && isBootModeNormal)   if(WiFi.isConnected() && isBootModeNormal)
   {   {
Line 149: Line 148:
     }     }
   }   }
 +
 +  delay(500); // delay of 0.5s, to change the counter value slowly
 } }
- 
  
 </code> </code>
en/iot/examples/oled.1519741045.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0