I'm using an Arduino esp32 DEVKITV1 and recently I bought a plugin from Unity Store called "Uduino Wifi". I already owned the basic one. But he only works with USB cables and I need the WiFi conection for my projects. The thing is, I can't make the code work no matter what. This error keeps printing on the monitor:
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x40089688 PS : 0x00060530 A0 : 0x800d8f29 A1 : 0x3ffb2160
A2 : 0x00000000 A3 : 0x3ffc3424 A4 : 0x00000004 A5 : 0x3ffc3ccc
A6 : 0x400d4adc A7 : 0x00000000 A8 : 0x00000001 A9 : 0x3ffb2070
A10 : 0x00000000 A11 : 0x3ffcae58 A12 : 0x400915e4 A13 : 0x3ffb81e4
ELF file SHA256: 12e68e183a55770b
Here is the script if you wanna see it:
#include<Uduino_Wifi.h>
Uduino_Wifi uduino("uduinoBoard"); // Declare and name your object
// Servo
#if defined(ESP32)
// Install esp32servo library => Sketch>Include Library>Manager Libraries>Esp32Servo
#include <ESP32Servo.h>
#else
#include <Servo.h>
#endif
#define MAXSERVOS 8
void setup()
{
Serial.begin(38400);
#if defined (__AVR_ATmega32U4__) // Leonardo
while (!Serial) {}
#elif defined(__PIC32MX__)
delay(1000);
#endif
// Optional functions, to add BEFORE connectWifi(...)
uduino.setPort(4222); // default 4222
uduino.connectWifi("CLARO_2G6A9384", "726A9384");
uduino.addCommand("s", SetMode);
uduino.addCommand("d", WritePinDigital);
uduino.addCommand("a", WritePinAnalog);
uduino.addCommand("rd", ReadDigitalPin);
uduino.addCommand("r", ReadAnalogPin);
uduino.addCommand("br", BundleReadPin);
uduino.addCommand("b", ReadBundle);
uduino.addInitFunction(InitializeServos);
uduino.addDisconnectedFunction(DisconnectAllServos);
}
void ReadBundle() {
char *arg = NULL;
char *number = NULL;
number = uduino.next();
int len = 0;
if (number != NULL)
len = atoi(number);
for (int i = 0; i < len; i++) {
uduino.launchCommand(arg);
}
}
void SetMode() {
int pinToMap = 100; //100 is never reached
char *arg = NULL;
arg = uduino.next();
if (arg != NULL)
{
pinToMap = atoi(arg);
}
int type;
arg = uduino.next();
if (arg != NULL)
{
type = atoi(arg);
PinSetMode(pinToMap, type);
}
}
void PinSetMode(int pin, int type) {
//TODO : vérifier que ça, ça fonctionne
if (type != 4)
DisconnectServo(pin);
switch (type) {
case 0: // Output
pinMode(pin, OUTPUT);
break;
case 1: // PWM
pinMode(pin, OUTPUT);
break;
case 2: // Analog
pinMode(pin, INPUT);
break;
case 3: // Input_Pullup
pinMode(pin, INPUT_PULLUP);
break;
case 4: // Servo
SetupServo(pin);
break;
}
}
void WritePinAnalog() {
int pinToMap = 100;
char *arg = NULL;
arg = uduino.next();
if (arg != NULL)
{
pinToMap = atoi(arg);
}
int valueToWrite;
arg = uduino.next();
if (arg != NULL)
{
valueToWrite = atoi(arg);
if (ServoConnectedPin(pinToMap)) {
UpdateServo(pinToMap, valueToWrite);
} else {
analogWrite(pinToMap, valueToWrite);
}
}
}
void WritePinDigital() {
int pinToMap = -1;
char *arg = NULL;
arg = uduino.next();
if (arg != NULL)
pinToMap = atoi(arg);
int writeValue;
arg = uduino.next();
if (arg != NULL && pinToMap != -1)
{
writeValue = atoi(arg);
digitalWrite(pinToMap, writeValue);
}
}
void ReadAnalogPin() {
int pinToRead = -1;
char *arg = NULL;
arg = uduino.next();
if (arg != NULL)
{
pinToRead = atoi(arg);
if (pinToRead != -1)
printValue(pinToRead, analogRead(pinToRead));
}
}
void ReadDigitalPin() {
int pinToRead = -1;
char *arg = NULL;
arg = uduino.next();
if (arg != NULL)
{
pinToRead = atoi(arg);
}
if (pinToRead != -1)
printValue(pinToRead, digitalRead(pinToRead));
}
void BundleReadPin() {
int pinToRead = -1;
char *arg = NULL;
arg = uduino.next();
if (arg != NULL)
{
pinToRead = atoi(arg);
if (pinToRead != -1)
printValue(pinToRead, analogRead(pinToRead));
}
}
void loop()
{
uduino.update();
//delay(10);
}
void printValue(int pin, int targetValue) {
uduino.print(pin);
uduino.print(" "); //<- Todo : Change that with Uduino delimiter
uduino.println(targetValue);
}
/* SERVO CODE */
Servo servos[MAXSERVOS];
int servoPinMap[MAXSERVOS];
void InitializeServos() {
#if defined(ESP32)
ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
ESP32PWM::allocateTimer(3);
#else
#endif
for (int i = 0; i < MAXSERVOS - 1; i++ ) {
servoPinMap[i] = -1;
servos[i].detach();
}
}
void SetupServo(int pin) {
if (ServoConnectedPin(pin))
return;
int nextIndex = GetAvailableIndexByPin(-1);
if (nextIndex == -1)
nextIndex = 0;
#if defined(ESP32)
servos[nextIndex].setPeriodHertz(50);
#endif
servos[nextIndex].attach(pin);
servoPinMap[nextIndex] = pin;
}
void DisconnectServo(int pin) {
servos[GetAvailableIndexByPin(pin)].detach();
servoPinMap[GetAvailableIndexByPin(pin)] = 0;
}
bool ServoConnectedPin(int pin) {
if (GetAvailableIndexByPin(pin) == -1) return false;
else return true;
}
int GetAvailableIndexByPin(int pin) {
for (int i = 0; i < MAXSERVOS - 1; i++ ) {
if (servoPinMap[i] == pin) {
return i;
} else if (pin == -1 && servoPinMap[i] < 0) {
return i; // return the first available index
}
}
return -1;
}
void UpdateServo(int pin, int targetValue) {
int index = GetAvailableIndexByPin(pin);
servos[index].write(targetValue);
delay(10);
}
void DisconnectAllServos() {
for (int i = 0; i < MAXSERVOS; i++) {
servos[i].detach();
digitalWrite(servoPinMap[i], LOW);
servoPinMap[i] = -1;
}
}
Anyone have any ideas how to solve this ?