Circuit Documentation
Summary
This circuit involves two ESP32 microcontrollers, a resistor, and a red LED. The ESP32 microcontrollers communicate with each other and control the LED through a series of connections. The circuit also includes a resistor to limit the current flowing through the LED.
Component List
ESP32 38 PINS
- Description: General-purpose microcontroller with Wi-Fi and Bluetooth capabilities.
- Pins: GND, G23, G22, TXD, RXD, G21, G19, G18, G5, G17, G16, G4, G0, G2, G15, SDI, SD0, CLK, 3V3, EN, SP, SN, G34, G35, G32, 33, G25, G26, G27, G14, G12, G13, SD2, SD3, 5V
Pocket ESP32-C3
- Description: Compact version of the ESP32 microcontroller.
- Pins: GROUND, 3V, INPUT/OUTPUT 2, INPUT/OUTPUT 3, INPUT/OUTPUT 4, INPUT/OUTPUT 5, INPUT/OUTPUT 16, BASE VOLTAGE, INPUT/OUTPUT 17, VOLUME, INPUT/OUTPUT 18, INPUT/OUTPUT 19
Resistor
- Description: 1000 Ohms resistor used to limit current.
- Pins: pin1, pin2
- Properties:
- Resistance: 1000 Ohms
LED: Two Pin (red)
- Description: Red LED used for visual indication.
- Pins: cathode, anode
Wiring Details
ESP32 38 PINS
- GND is connected to the anode of the LED and the GROUND of the Pocket ESP32-C3.
- G17 is connected to INPUT/OUTPUT 16 of the Pocket ESP32-C3.
- G16 is connected to INPUT/OUTPUT 17 of the Pocket ESP32-C3.
- G12 is connected to pin1 of the Resistor.
Pocket ESP32-C3
- GROUND is connected to the GND of the ESP32 38 PINS and the anode of the LED.
- INPUT/OUTPUT 16 is connected to G17 of the ESP32 38 PINS.
- INPUT/OUTPUT 17 is connected to G16 of the ESP32 38 PINS.
Resistor
- pin1 is connected to G12 of the ESP32 38 PINS.
- pin2 is connected to the cathode of the LED.
LED: Two Pin (red)
- anode is connected to the GND of the ESP32 38 PINS and the GROUND of the Pocket ESP32-C3.
- cathode is connected to pin2 of the Resistor.
Documented Code
ESP32 38 PINS Code (Slave1.ino)
//Boards Manager esp32 by Espressif Systems Ver 3.0.4
#include <EEPROM.h>
#include "Wire.h"
#define slaveno 1
#define I2C_DEV_ADDR 0x30+slaveno //0x11=Slave 1, 0x12=Slave 2, 0x13=Slave 3
#define LED 12 //Slave1 to Slave10 LED=12, Slave0=2
#define stbt 2 //Slave1 to Slave10 LED=2, Slave0=12
#define RXD2 16
#define TXD2 17
String inputString = "";
String inputCommands = "";
bool stringComplete = false;
char inString[] = "";
int temp[10];
String inputString2 = "";
String inputCommands2 = "";
bool stringComplete2 = false;
char inString2[] = "";
int temp2[10];
int buff[4] = {0,0,0,0};
int value;
int coutp = 0;
int coutn = 0;
int sendcout = 0;
int after4bytecout = 0;
bool triggerFlag = 0;
int triggercouter = 1;
int triggerBuff[100];
bool startflag = 0;
bool svstartflag = 0;
bool wutflag = 0;
bool testpir = 0;
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n') {
stringComplete = true;
}
}
}
void serialEvent2() {
while (Serial2.available()) {
char inChar = (char)Serial2.read();
inputString2 += inChar;
if (inChar == '\n') {
stringComplete2 = true;
}
}
}
uint32_t i = 0;
void send4byte(int value){
byte b = 0;
b |= value;
Wire.write(b);
b = 0;
b |= value >> 8;
Wire.write(b);
b = 0;
b |= value >> 16;
Wire.write(b);
b = 0;
b |= value >> 24;
Wire.write(b);
}
void onRequest(){
uint8_t error = 1;
Serial.print("triggerBuff[1] = b'");
for(int i=0;i<triggerBuff[1]+2;i++){
send4byte(triggerBuff[i]);
}
error = Wire.endTransmission(true);
Serial.print("onRequest erroe = ");
Serial.println(error);
Serial.println("");
}
void onReceive(int len){
char str[len];
Serial.printf("onReceive[%d]: ", len);
for(int i=0;i<len;i++){
str[i] = Wire.read();
}
for(int i=0;i<len;i++){
Serial.print(str[i]);
}
Serial.println("");
if(str[0] == 115 && str[1] == 116 && str[2] == 111 && str[3] == 112){
startflag = 0;
wutflag = 0;
if(triggercouter > 0)digitalWrite(LED, HIGH);
}
if(str[0] == 119 && str[1] == 117 && str[2] == 116){
testpir = 0;
triggercouter = 0;
wutflag = 1;
digitalWrite(LED, LOW);
}
if(str[0] == 115 && str[1] == 116 && str[2] == 97 && str[3] == 114 && str[4] == 116){
triggercouter = 0;
for(int i = 1;i<100;i++){
triggerBuff[i] = 0;
}
startflag = 1;
after4bytecout = 0;
digitalWrite(LED, LOW);
}
if (str[0] == 99 && str[1] == 111 && str[2] == 117 && str[3] == 116){
String s1 = "";
String s2 = "-";
for (int i = 5;i <= 10; i++){
if (str[i] == 0)break;
s1 += char(str[i]);
}
coutp = s1.toInt();
triggerBuff[0] = coutp;
EEPROM.put(0, coutp);
EEPROM.commit();
s2 += s1;
coutn = s2.toInt();
EEPROM.put(sizeof(coutp), coutn);
EEPROM.commit();
Serial.println(coutp);
Serial.println(coutn);
}
if(str[0] == 116 && str[1] == 114 && str[2] == 103){
if (str[4] == 49)testpir = 1;
if (str[4] == 48)testpir = 0;
}
}
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial2.begin(57600, SERIAL_8N1, RXD2, TXD2);
EEPROM.begin(32);
EEPROM.get(0, coutp);
EEPROM.get(sizeof(coutp), coutn);
triggerBuff[0] = coutp;
Serial.println(coutp);
Serial.println(coutn);
Wire.onReceive(onReceive);
Wire.onRequest(onRequest);
Wire.begin((uint8_t)I2C_DEV_ADDR);
#if CONFIG_IDF_TARGET_ESP32
char message[64];
snprintf(message, 64, "%u Packets.", i++);
Wire.slaveWrite((uint8_t *)message, strlen(message));
#endif
pinMode(LED, OUTPUT);
pinMode(stbt, INPUT_PULLUP);
pinMode(TXD2, INPUT_PULLUP);
digitalWrite(LED, LOW);
}
void loop() {
uart_in();
if (startflag || svstartflag){
signal_in();
}
if(triggerc
