WiFi Smart Connect with OLED Integration
This guide demonstrates how to integrate a standard 128x64 I2C OLED display with your ConsentiumThings Dalton board using the U8g2 library.
By following this example, you can provide real-time visual feedback on your device's physical screen. It covers how to display the automatically generated WiFi Access Point (AP) credentials during the setup phase, show the assigned IP address upon successful connection, and indicate when data is actively being sent to the Consentium IoT Cloud.
Prerequisites
Hardware Setup
ConsentiumThings Dalton Board (or compatible Edge board).
I2C OLED Display (e.g., SSD1306 128x64).
Jumper wires connecting the OLED to the board's I2C pins (SDA and SCL).
Software & Libraries
Ensure you have the following libraries installed in your Arduino IDE:
ConsentiumThings: The core library for the edge board.U8g2: A fast, highly customizable library for monochrome displays.Wire: Standard Arduino I2C library (usually built-in).
Code Walkthrough
1. Initialisation and Setup
First, include the necessary libraries and initialise the U8g2 object for your specific display. You must also define your Consentium API keys.
2. The Display Callback Function
The board.smartConnect() function is a blocking function, meaning the code pauses while it waits for a user to connect to the generated WiFi Access Point. To display the generated SSID and Password on the OLED before the code blocks, we pass a callback function.
3. The Setup Loop
In the setup() function, initialise the OLED and pass the callback function to smartConnect(). Once the connection is successful, the screen clears and displays the newly acquired IP address.
4. The Main Loop (Data Transmission)
During normal operation, the board reads sensor data, sends it to the Consentium Cloud, and updates the OLED to confirm the transmission.
Complete Example Code
Copy and paste the entire block below into your Arduino IDE to get started quickly. Remember to replace the empty API keys with your actual Consentium credentials.
Troubleshooting I2C & OLED Issues Hardware integrations don't always work perfectly on the first try. If your OLED screen remains blank or displays scrambled text, check the following common issues.
1. Blank Screen / No Output
Wiring Check: Ensure the I2C pins are connected correctly. A very common mistake is swapping the SDA and SCL lines.
VCC -> 3.3V or 5V (Check your specific OLED module's rating)
GND -> GND
SDA -> SDA pin on your ConsentiumThings Dalton board
SCL -> SCL pin on your ConsentiumThings Dalton board
Power Supply: Ensure the board is providing enough power to the OLED. Sometimes running off a weak USB port can cause peripherals to fail.
2. Incorrect I2C Address
Most 128x64 OLEDs use the I2C address 0x3C, but some use 0x3D. The U8g2 library usually handles the default 0x3C automatically based on the constructor, but if your screen has a different address or isn't being recognised, you should run an I2C Scanner sketch to verify the hardware is communicating.
I2C Scanner Code: Upload this temporary sketch to your board and open the Serial Monitor (115200 baud). It will tell you the exact address of your connected OLED.
3. Scrambled Display or "Snow"
If your display lights up but the pixels look like random noise or are shifted slightly to the right, you likely have an SH1106 controller instead of an SSD1306. These modules look physically identical.
To fix this, simply change your U8g2 constructor at the top of your code:
Change this:
To this:
4. Code Hanging / Board Restarting
If the board continuously restarts or the code freezes immediately after u8g2.begin();, it usually means the I2C bus is hanging due to missing Pull-Up resistors. Most ready-made OLED modules have these resistors built-in, but if you are using a bare screen, you may need to add 4.7kΩ resistors between SDA/3.3V and SCL/3.3V.
Last updated