Categories

CMIS-1 Test Code OLED

WIKI:

CMIS (Current Monitor IoT Sensors), SDK Kit is based on an Espressif ESP32 WROOM and the board has an I2C header designed for easy OLED connection.

Displays random number between 0 and 99 and updates battery percentage.  Heartbeat RED LED flashes each loop cycle.

You will need to select your OLED Display.  Uncomment/Comment as needed.

// OLED Instance. You will need to select your OLED Display.  
// Uncomment/Comment as needed.
GyverOLED<SSD1306_128x32, OLED_BUFFER> oled;
//GyverOLED<SSD1306_128x32, OLED_NO_BUFFER> oled;
//GyverOLED<SSD1306_128x64, OLED_BUFFER> oled;
//GyverOLED<SSD1306_128x64, OLED_NO_BUFFER> oled;
//GyverOLED<SSH1106_128x64> oled;

Example Arduino code below.

/*
Dave Williams, DitroniX 2019-2022 (ditronix.net)
CMIS-1 Current Monitor IoT Sensors v1.0
Features include ESP32 MODBUS EEPROM CT Clamp Multi-Current Voltage
PCA v1.00 – Test Code Firmware v1 – 2nd September 2022

Simplified Board Bring Up Test – OLED Display via I2c (Heatbeat LED)
.
Remember!
– Set the BOARD to ESP32 DEV Module (or similar).
– You can also set the BAUD rate up to 921600 to speed up flashing.
– The SDK does NOT need external power to flash. It will take Power from the USB 5V.
.
Note that in the default state, upon first power up and during reset, the Green LED will be partially lit. Once programmed and the GPIO defined, the Green LED will go off after power up.
.
The purpose of this test code is to cycle through the various main functions of the board as part of bring up testing.
.
This test code is OPEN SOURCE and although is is not intended for real world use, it may be freely used, or modified as needed.
It is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/

// Libraries
#include <GyverOLED.h>

// **************** VARIABLES / DEFINES / STATIC ****************

// **************** OUTPUTS ****************
#define LED_Red 2 // Red LED
#define LED_Green 4 // Green LED

// Constants
const int LoopDelay = 1; // Loop Delay in Seconds

// Variables
float TestCount = 0;

// OLED Instance. You will need to select your OLED Display.
// Uncomment/Comment as needed.
GyverOLED<SSD1306_128x32, OLED_BUFFER> oled;
//GyverOLED<SSD1306_128x32, OLED_NO_BUFFER> oled;
//GyverOLED<SSD1306_128x64, OLED_BUFFER> oled;
//GyverOLED<SSD1306_128x64, OLED_NO_BUFFER> oled;
//GyverOLED<SSH1106_128x64> oled;

// Draw Battery
void drawBattery(byte percent) {
oled.drawByte(0b00111100);
oled.drawByte(0b00111100);
oled.drawByte(0b11111111);
for (byte i = 0; i < 100 / 8; i++) {
if (i < (100 – percent) / 8) oled.drawByte(0b10000001);
else oled.drawByte(0b11111111);
}
oled.drawByte(0b11111111);
}

void setup() {

// Stabalise
delay(250);

// LED
pinMode(LED_Red, OUTPUT);
pinMode(LED_Green, OUTPUT);

// LED Default Off State
digitalWrite(LED_Red, HIGH);
digitalWrite(LED_Green, HIGH);

// OLED
oled.init();
oled.clear();
oled.setCursor(18, 0);
oled.setScale(5);
oled.print(“CMIS”);
oled.update();
delay(2000);
}

void loop() {

// Test Counter. Any random decimal number between 0 and 99
TestCount = random(0, 9999);
TestCount = TestCount / 100;

// Update the display
oled.clear();
oled.setScale(3);
oled.setCursor(0, 0);
oled.print(TestCount);
oled.println(” W”);
drawBattery(TestCount);
oled.update();

// Heatbeat LED
digitalWrite(LED_Red, LOW);
delay(50);
digitalWrite(LED_Red, HIGH);

// Loop Delay
delay(LoopDelay * 1000);

}

Leave a Reply

This site uses User Verification plugin to reduce spam. See how your comment data is processed.