Hello all. I’m using platformio for an ESP32Cam project, and so far it’s been working well. I’ve gotten a motion sensor hooked up to it and working properly, but when I tried to start an AP (or do anything involving WiFi, for that matter) the program crashes, saying there’s an invalid opcode. Seems to me like it’s a compatibility issue or a broken library, but here’s my code:
#include <Arduino.h>
#include <WiFi.h>
const int ledPin = 4; // the number of the LED pin
const int motionPin = 12; // the number of the motion sensor pin
bool initialized = false;
bool motionDetected = false;
bool checkInit() {
if (!initialized && digitalRead(motionPin) == LOW) {
initialized = true;
Serial.println("\nMotion sensor initialized.");
}
if (!initialized) {
Serial.print('.');
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
return initialized;
}
void checkMotion() {
if (!motionDetected && digitalRead(motionPin) == HIGH) {
motionDetected = true;
Serial.println("Motion detected!");
digitalWrite(ledPin, HIGH);
}
if (motionDetected && digitalRead(motionPin) == LOW) {
motionDetected = false;
Serial.println("Motion stopped.");
digitalWrite(ledPin, LOW);
}
}
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(motionPin, INPUT);
Serial.begin(9600);
Serial.print("Starting AP");
WiFi.enableAP(true);
WiFi.mode(WIFI_AP);
delay(1000);
WiFi.softAP("ESP32-AP", "12345678");
delay(1000);
// Serial.print("Initializing motion sensor...");
}
void loop() {
// if (!checkInit()) return;
// checkMotion();
delay(10);
}
Here’s the serial output:
␀␀Guru Meditation Error: Core 0 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400d7dfc: 0000ffe6 00000000 00000000
Core 0 register dump:
PC : 0x400d7e00 PS : 0x00050031 A0 : 0x4014a176 A1 : 0x3ffbed1c
A2 : 0x007bf568 A3 : 0x3ffbe0e8 A4 : 0x40085de8 A5 : 0x80000000
A6 : 0x00000000 A7 : 0x003fffff A8 : 0x800dec6e A9 : 0x4008d07a
A10 : 0x00000000 A11 : 0x80000001 A12 : 0x00000000 A13 : 0x3ffbc660
A14 : 0x00000003 A15 : 0x00060023 SAR : 0x0000001d EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Backtrace: 0x400d7dfd:0x3ffbed1c |<-CORRUPTED
ELF file SHA256: 2bf489710000ab24
Rebooting...
[ continues in reboot loop ]
I’m not quite sure exactly what’s causing this, but I was wondering if someone in the community could help me out here. Everything works fine without trying anything WiFi-related, but when I use the WiFi library’s methods, it crashes like this.
Does anybody know how I could go about troubleshooting / fixing this? Thanks in advance!