#include "Wire.h"
#define SDA_pin 9
#define SCL_pin 10
#define SDA_pin_Lolin 23
#define SCL_pin_Lolin 19
#define WIFI_SSID "ZOG-521"
#define WIFI_PASSWORD "111"
#define BMP180_ADDRESS 0x77
#define SCREEN_ADDRESS 0x3C
#define AHT10_ADDRESS 0x38
bool sensor_bmp85_present = false;
bool sensor_aht10_present = false;
bool display_1306_present = false;
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#include "SPI.h"
#include "Adafruit_ILI9341.h"
#define TFT_CS 8
#define TFT_DC 3
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
unsigned long BarLastRenderTime = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-C3!");
chip_info();
tft.begin();
tft.setCursor(46, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("ESP32-C3");
scani2c();
// render_ua();
if (display_1306_present) {
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println("Failed display SSD1306 initialization");
Serial.println("TODO: and what we gone do now?!");
for(;;); // Don't proceed, loop forever
} else {
Serial.println("SSD1306 init...");
display.clearDisplay();
display.setRotation(2);
// // render_icons(false);
display.display();
//delay(1000);
BarLastRenderTime = micros();
render_ua();
}
} else {Serial.println("SSD1306 not found! Skip it...");}
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
void chip_info() {
// Get chip info
uint32_t chipId = 0;
String chipModel = ESP.getChipModel();
for(int i=0; i<17; i=i+8) {
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
}
Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision());
Serial.printf("This chip has %d cores\n", ESP.getChipCores());
Serial.print("Chip ID: "); Serial.println(chipId);
Serial.print("Chip Model: "); Serial.println(chipModel);
// Wire.setPins(SDA_pin, SCL_pin);
if (chipModel == "ESP32-C3") {
Serial.println("Detected ESP32-C3 ID? Uses 9 and 10 pins");
Wire.setPins(SDA_pin, SCL_pin);
} else if (chipModel == "ESP32-D0WDQ6") {
Serial.println("Detected Lolin32 lite ID? Uses 23 and 19 pins");
Wire.setPins(SDA_pin_Lolin, SCL_pin_Lolin);} else {
Serial.print("Default ESP32C3 Use 9 and 10 pins");
Wire.setPins(SDA_pin, SCL_pin);
}
Wire.begin();
}
void render_ua(){
// display.fillRect(0, 32, 64, 64, SSD1306_INVERSE);
display.fillRect(10, 42, 30, 12, SSD1306_INVERSE);
// display.drawTriangle(0,0,10,0,5,7,SSD1306_INVERSE);
display.display();
display.setTextSize(1); // Draw 2X-scale text
display.setTextColor(SSD1306_INVERSE);
display.setCursor(29, 56);
display.println(F("LAB515"));
display.setTextColor(SSD1306_WHITE);
display.setCursor(65, 56);
display.println(F("@2023"));
display.setCursor(10, 10);
// display.println(F("MyDeliriumDevice01"));
// display.println(F("LAB515-© RїЯ"));
display.setCursor(10, 20);
display.println(F("Searching SSID: "));
display.setCursor(10, 30);
display.println(F(WIFI_SSID));
display.display();
// delay(333);
// display.startscrollleft(0, 127);
// delay(2000);
// display.stopscroll();
}
void checki2c(uint8_t adresok) {
switch(adresok) {
case BMP180_ADDRESS:
sensor_bmp85_present = true;
Serial.printf("I2C BMP180 sensor is found at 0x%02X\n", adresok);
break;
case SCREEN_ADDRESS:
display_1306_present = true;
Serial.printf("I2C Display 1306 is found at 0x%02X\n", adresok);
break;
case AHT10_ADDRESS:
sensor_aht10_present = true;
Serial.printf("I2C AHT10 sensor is found at 0x%02X\n", adresok);
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
Serial.printf("I2C device found at address 0x%02X\n", adresok);
break;
}
}
void scani2c() {
byte error, address;
int nDevices = 0;
//clean flags before scan
sensor_bmp85_present = false;
sensor_aht10_present = false;
display_1306_present = false;
Serial.println("Scanning for I2C devices...");
for(address = 0x01; address < 0x7f; address++){
// Serial.print(">");
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0){
Serial.printf("I2C device found at address 0x%02X\n", address);
checki2c(address);
nDevices++;
} else if(error != 2){
Serial.printf("Error %d at address 0x%02X\n", error, address);
}
}
if (nDevices == 0){
Serial.println("No I2C devices found");
}
}