Hi everyone!
I'm making a meditation device that uses an infrared obstacle sensor to detect an object along with a real time clock module to communicate to blynk how long the object is detected for (connected to my esp32). I want to use one way serial communication between my esp32 and arduino uno to turn on my LED circular board to complete a light whilst the object is detected, but i keep getting this error when uploading my code to the esp32?:
R��Sp���J�����ܜ�Đ��H����Guru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400d1680: 74ccc664 76cd66dd 444454c6
Core 1 register dump:
*PC : 0x400d1687 PS : 0x00060330 A0 : 0x800d515d A1 : 0x3ffb1f70 *
*A2 : 0x3ffc1b9c A3 : 0x00002580 A4 : 0x3ffc18cc A5 : 0x00004e20 *
*A6 : 0x00000003 A7 : 0x00060a23 A8 : 0x800d07a0 A9 : 0x3ffb1f30 *
*A10 : 0x3ffc18cc A11 : 0xffffffff A12 : 0xffffffff A13 : 0x00000000 *
*A14 : 0x00000009 A15 : 0x00000000 SAR : 0x00000016 EXCCAUSE: 0x00000000 *
*EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000 *
ELF file SHA256: 0000000000000000
Backtrace: 0x400d1687:0x3ffb1f70 0x400d515a:0x3ffb1fb0 0x4008a02e:0x3ffb1fd0
this is the code for my esp32:
#include <Wire.h>
#include <RTClib.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define BLYNK_TEMPLATE_ID "--"
#define BLYNK_TEMPLATE_NAME "--"
#define BLYNK_AUTH_TOKEN "--"
#define ESP_TX_PIN 35
RTC_DS3231 rtc; // Initialize the RTC object
const int SensorPin = 4; // Digital input pin connected to the obstacle sensor
bool objectDetected = false;
unsigned long detectionStartTimeMillis = 0;
unsigned long detectionDurationSeconds = 0;
unsigned long detectionEndTimeMillis = 0;
char auth[] = "--"; // Blynk authentication token
char ssid[] = "--";
char pass[] = "--";
void setup() {
Serial.begin(9600);
Serial1.begin(9600); // Initialize Serial communication with Arduino Uno
Wire.begin();
rtc.begin();
// Set the initial time of the RTC module (if required)
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
pinMode(SensorPin, INPUT_PULLUP);
// Connect to Wi-Fi
WiFi.begin("-", "-");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to the WiFi network");
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());
// Connect to Blynk
Blynk.config(auth);
}
void loop() {
Blynk.run();
DateTime now = rtc.now();
unsigned long currentTimeMillis = millis(); // Current time in milliseconds
unsigned long currentTimeSeconds = now.unixtime(); // Current time in seconds
// Check if an object is detected
if (digitalRead(SensorPin) == LOW && !objectDetected) {
objectDetected = true;
Serial1.println("ON"); // Send command to Arduino Uno to turn on the LED function
detectionStartTimeMillis = currentTimeMillis;
}
// Check if object detection has ended
if (digitalRead(SensorPin) == HIGH && objectDetected) {
objectDetected = false;
Serial1.println("OFF"); // Send command to Arduino Uno to turn off the LED function
detectionEndTimeMillis = currentTimeMillis;
unsigned long detectionDurationMillis = detectionEndTimeMillis - detectionStartTimeMillis; // Duration in milliseconds
unsigned long detectionDurationSeconds = detectionDurationMillis / 1000; // Convert milliseconds to seconds
if (detectionDurationSeconds > 0) {
Serial.print("Object detection ended. Duration: ");
Serial.print(detectionDurationSeconds);
Serial.println(" seconds.");
Blynk.virtualWrite(V1, "\nCompleted meditation for " + String(detectionDurationSeconds) + " seconds"); // Send duration to Blynk app
String strValue = String(detectionDurationSeconds); // Convert duration to string
Serial.println("Sending: " + strValue);
Serial1.println(strValue); // Send string to ESP32
Blynk.virtualWrite(V2, detectionDurationSeconds); // Send duration to Blynk app
}
}
}
and this is the code for my arduino uno:
#include <Adafruit_NeoPixel.h>
#define UNO_RX_PIN 0
#define PIXEL_PIN 6
#define PIXEL_COUNT 24
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool ledCycleActive = false;
void setup() {
pixels.begin();
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
String command = Serial.readStringUntil('\n');
if (command == "ON") {
ledCycleActive = true;
} else if (command == "OFF") {
ledCycleActive = false;
// Turn off each pixel individually
for (int i = pixels.numPixels() - 1; i >= 0; i--) {
pixels.setPixelColor(i, 0, 0, 0, 0);
pixels.show();
delay(250);
}
}
}
if (ledCycleActive) {
// Light up each pixel individually
for (int i = 0; i < pixels.numPixels(); i++) {
pixels.setPixelColor(i, pixels.Color(255, 200, 100));
pixels.show();
delay(166.67);
}
// Stay on for 2 seconds
delay(2000);
// Turn off each pixel individually
for (int i = pixels.numPixels() - 1; i >= 0; i--) {
pixels.setPixelColor(i, 0, 0, 0, 0);
pixels.show();
delay(250);
}
// Wait for 2 seconds before repeating the process
delay(2000);
}
}
I'm also finding that the serial communication is not working at all. I was advised by my tutor that i can just connect the TX pin of the esp32 to the RX pin of the arduino uno and it will work, but that has not been my experience at all (also connected ground of both boards together)
I'm not too sure where I'm going wrong as I am completely new and have had very little guidance from tutors Pls help