#include "Wire.h"
#define I2C_Freq 100000
#define SDA_0 9
#define SCL_0 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 SCREEN2_ADDRESS 0x3D
#define AHT10_ADDRESS 0x38
#define MPU6050_ADDRESS 0x68
bool sensor_bmp85_present = false;
bool sensor_aht10_present = false;
bool display_1306_present = false;
bool display2_1306_present = false;
bool sensor_mpu6050_present = false;
TwoWire I2C_0 = TwoWire(0);
#include "SPI.h"
#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, &I2C_0, OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &I2C_0, OLED_RESET);
#include "Adafruit_ILI9341.h"
#define STMPE_CS 6 //SCK
#define SD_CS 0 //wtf?
#define TFT_CS 8 // RGB led 8 pin conflict
#define TFT_DC 3
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
int ledPin = 13; // choose the pin for the LED
int inputPin = 1; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
#include <FastLED.h>
// How many leds in your strip?
#define NUM_LEDS 1
#define FASTLED_DATA_PIN 8
// Define the array of leds
CRGB leds[NUM_LEDS];
float xByGyro, yByGyro, zByGyro; // Global variables for the rotation by gyro
// Set the origin in the middle of the display
const int xOrigin = 64;
const int yOrigin = 32;
const float viewDistance = 150.0; // higher for less perspective, lower for more.
unsigned long BarLastRenderTime = 0;
#include <ShiftRegister74HC595.h>
#define DATA_PIN 18 // Pin connected to DS of 74HC595
#define LATCH_PIN 4 // Pin connected to STCP of 74HC595
#define CLOCK_PIN 5 // Pin connected to SHCP of 74HC595
// create a global shift register object
// parameters: <number of shift registers> (data pin, clock pin, latch pin)
ShiftRegister74HC595<2> sr(DATA_PIN, CLOCK_PIN, LATCH_PIN);
#define NUM_SHIFT_REGS 2
const uint8_t numOfRegisterPins = NUM_SHIFT_REGS * 8;
bool registers[numOfRegisterPins];
//==============================================================
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-C3!");
Serial.print("MOSI: ");
Serial.println(MOSI);
Serial.print("MISO: ");
Serial.println(MISO);
Serial.print("SCK: ");
Serial.println(SCK);
Serial.print("SS: ");
Serial.println(SS);
// Wire.begin();
I2C_0.begin(SDA_0 , SCL_0 , I2C_Freq);
//for pir sensor
pinMode(inputPin, INPUT);
Serial.print("MOSI: ");
Serial.println(MOSI);
Serial.print("MISO: ");
Serial.println(MISO);
Serial.print("SCK: ");
Serial.println(SCK);
Serial.print("SS: ");
Serial.println(SS);
//pinMode(DATA_PIN, OUTPUT);
//pinMode(CLOCK_PIN, OUTPUT);
//pinMode(LATCH_PIN, OUTPUT);
//clearRegisters();
//writeRegisters();
chip_info();
FastLED.addLeds<NEOPIXEL, FASTLED_DATA_PIN>(leds, NUM_LEDS); // GRB ordering is assumed
leds[0] = CRGB(237, 245, 8);
FastLED.show();
sr.setAllHigh(); // set all pins HIGH
delay(500);
sr.setAllLow(); // set all pins LOW
delay(500);
leds[0] = CRGB::Black;
FastLED.show();
// Turn the LED on, then pause
leds[0] = CRGB(20, 249, 234);
FastLED.show();
//delay(500);
tft.begin();
tft.setCursor(46, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("ESP32-C3");
Serial.print("MOSI: ");
Serial.println(MOSI);
Serial.print("MISO: ");
Serial.println(MISO);
Serial.print("SCK: ");
Serial.println(SCK);
Serial.print("SS: ");
Serial.println(SS);
leds[0] = CRGB(15, 18, 246);
FastLED.show();
sr.setAllHigh(); // set all pins HIGH
delay(500);
sr.setAllLow(); // set all pins LOW
delay(500);
scani2c();
// render_ua();
if (display2_1306_present) {
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display2.begin(SSD1306_SWITCHCAPVCC, SCREEN2_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...");
display2.clearDisplay();
display2.setRotation(2);
// // render_icons(false);
display2.display();
//delay(1000);
BarLastRenderTime = micros();
render_ua2();
}
} else {
Serial.println("SSD1306 not found! Skip it...");
}
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...");
}
if (sensor_mpu6050_present) {
// Initialize the MPU-6050 and test if it is connected.
I2C_0.beginTransmission( MPU6050_ADDRESS);
I2C_0.write( 0x6B); // PWR_MGMT_1 register
I2C_0.write( 0); // set to zero (wakes up the MPU-6050)
auto error = I2C_0.endTransmission();
if ( error != 0)
{
Serial.println(F( "Error, MPU-6050 init failed"));
leds[0] = CRGB(254, 0, 0);
FastLED.show();
// for(;;); // halt the sketch if error encountered
}
} else {
Serial.println("MPU-6050 not found! Skip it...");
}
Serial.println("Going ");
// Now turn the LED off, then pause
leds[0] = CRGB(61, 190, 14);
FastLED.show();
// delay(500);
sr.setAllHigh(); // set all pins HIGH
delay(500);
sr.setAllLow(); // set all pins LOW
delay(500);
Serial.println("Setup is done");
// Now turn the LED off, then pause
leds[0] = CRGB::Black;
FastLED.show();
Serial.print("MOSI: ");
Serial.println(MOSI);
Serial.print("MISO: ");
Serial.println(MISO);
Serial.print("SCK: ");
Serial.println(SCK);
Serial.print("SS: ");
Serial.println(SS);
}
bool toggle = false;
//================================================================================
void loop() {
//TODO: make RGB led indication as timeslots and setup default loop for leds blinking
// like music, 4 tackts and light "notes" that shown current state
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
leds[0] = CRGB(228, 90, 16);
FastLED.show();
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH) {
// we have just turned of
leds[0] = CRGB::Black;
FastLED.show();
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
// 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");
I2C_0.setPins(SDA_0, SCL_0);
} else if (chipModel == "ESP32-D0WDQ6") {
Serial.println("Detected Lolin32 lite ID? Uses 23 and 19 pins");
I2C_0.setPins(SDA_pin_Lolin, SCL_pin_Lolin);
} else {
Serial.print("Default ESP32C3 Use 9 and 10 pins");
I2C_0.setPins(SDA_0, SCL_0);
}
I2C_0.begin();
}
void render_ua2() {
// display.fillRect(0, 32, 64, 64, SSD1306_INVERSE);
display2.fillRect(10, 42, 30, 12, SSD1306_INVERSE);
// display.drawTriangle(0,0,10,0,5,7,SSD1306_INVERSE);
display2.display();
display2.setTextSize(1); // Draw 2X-scale text
display2.setTextColor(SSD1306_INVERSE);
display2.setCursor(10, 56);
display2.println(F("FUCK RUZZIA"));
display2.setTextColor(SSD1306_WHITE);
display2.setCursor(65, 56);
display2.println(F("@2023"));
display2.setCursor(10, 10);
// display.println(F("MyDeliriumDevice01"));
// display.println(F("LAB515-© RїЯ"));
display2.setCursor(10, 20);
display2.println(F("Searching SSID: "));
display2.setCursor(10, 30);
display2.println(F(WIFI_SSID));
display2.display();
// delay(333);
// display.startscrollleft(0, 127);
// delay(2000);
// display.stopscroll();
}
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 SCREEN2_ADDRESS:
display2_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 MPU6050_ADDRESS:
sensor_mpu6050_present = true;
Serial.printf("I2C MPU6050 sensor is found at 0x%02X\n", adresok);
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;
sensor_mpu6050_present = false;
Serial.println("Scanning for I2C devices...");
for (address = 0x01; address < 0x7f; address++) {
// Serial.print(">");
I2C_0.beginTransmission(address);
error = I2C_0.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");
}
}
void clearRegisters() {
// Reset all register pins
for (int i = numOfRegisterPins - 1; i >= 0; i--) {
registers[i] = LOW;
}
}
void setRegisterPin(int index, int value) {
// Set an individual pin HIGH or LOW
registers[index] = value;
}
void writeRegisters() {
// Set and display registers
digitalWrite(LATCH_PIN, LOW);
for (int i = numOfRegisterPins - 1; i >= 0; i--) {
digitalWrite(CLOCK_PIN, LOW);
digitalWrite(DATA_PIN, registers[i]);
digitalWrite(CLOCK_PIN, HIGH);
}
digitalWrite(LATCH_PIN, HIGH);
}
Loading
esp32-c3-devkitm-1
esp32-c3-devkitm-1