#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
/* c3DevKitM1_Oled_128x64_Text
+ picoDevKitM2_DHT22 */
/**************************************************************************
Class: GMU ECE508 IoT
Student Name: Tony Boci
Gnumber: Gxxxx1234
Lecture 3
Description: This is an example of OLEDs 128x64 based on SSD1306 drivers using ESP32 C3 DevKitM 1
It displays text only
Issues: No issues
**************************************************************************/
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 myOled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
String oledline[9]; //One line of text per OLED row. For textsize of 1 there are 8 OLED rows/lines
char gNumber[11] = "G6655";
char boardWifiMAC[31];
char tmpBuffer[64];
long currMillis, prevMillis;
int cnt = 0;
static TaskHandle_t count_display_task_handle = NULL;
void displayTextOLED(String oledline[]) {
int jj;
myOled.clearDisplay();
myOled.setTextSize(1);
myOled.setTextColor(SSD1306_WHITE);
myOled.setCursor(0, 0);
for (jj=1; jj<=8; jj++) {
myOled.println(oledline[jj]);
}
myOled.display();
}
void getMacWifiShield(char *macWifiShield)
{
byte mac[6];
WiFi.macAddress(mac);
sprintf(macWifiShield, "%02X%02X%02X%02X%02X%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
};
void do_count_display_task(void *pvParameters){
while(1)
{
currMillis = millis();
if (currMillis - prevMillis > 1000) {
prevMillis = currMillis;
cnt = cnt + 1;
oledline[3] = "ECE508 HW05 cnt:%d" + cnt;
displayTextOLED(oledline);
}//millis diff > 1000
} //while(1)
} //do_count_display_task();
void init_hagw() {
pinMode(RGB_BUILTIN, OUTPUT);
Serial.begin(921600);
Wire.begin(18, 17); //SDA, SCK
// Make sure to use the correct I2C address. Address 0x3C for 128x64
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!myOled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("SSD1306 allocation failed");
for(;;); // Don't proceed, loop forever
}
getMacWifiShield(boardWifiMAC);
oledline[1] = String(gNumber) + " " + String(boardWifiMAC);
int jj; for (jj=2; jj<=8; jj++){ oledline[jj]=""; }
displayTextOLED(oledline);
printf("init_hagw() is done !\n");
vTaskDelay(pdMS_TO_TICKS(3 * 1000));
xTaskCreate(do_count_display_task, "Count display Task", 4096, NULL, 2, &count_display_task_handle);
}
void setup()
{
// initArduino();
//void app_main() {
printf("Hello, Wokwi!\n");
init_hagw();
}
void loop() {
// Nothing to do here
}
Loading
xiao-esp32-s3
xiao-esp32-s3