The code to talk to Alexa works fine on it's own as indicated by the onboard LED switching on and off when I ask Alexa to. The code to control the stepper motor also works in isolation. The problems arise when I blend the two together. I get a an error like this at the point the code tries to turn the stepper motor:
Opening the curtain...
Panic /Users/lewisaburrow/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/core_esp8266_main.cpp:98 __yield
ctx: sys
sp: 3ffff9d0 end: 3fffffb0 offset: 01b0
Please can anyone suggest what might be going wrong here?
The full code is this:
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include "fauxmoESP.h"
#include "credentials.sample.h"
#define SERIAL_BAUDRATE 115200
#define LED 2
fauxmoESP fauxmo;
//--------------------------------------------------
// Motor
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
//-------------------------------------------------------
//--------------------------
// -----------------------------------------------------------------------------
// Wifi
// -----------------------------------------------------------------------------
void wifiSetup() {
// Set WIFI module to STA mode
WiFi.mode(WIFI_STA);
// Connect
Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASS);
// Wait
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
Serial.println();
// Connected!
Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}
void setup() {
// Init serial port and clean garbage
Serial.begin(SERIAL_BAUDRATE);
Serial.println();
Serial.println();
// Wifi
wifiSetup();
// LED
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
// You can enable or disable the library at any moment
// Disabling it will prevent the devices from being discovered and switched
fauxmo.enable(true);
// Add virtual devices
fauxmo.addDevice("bedroom curtain");
//fauxmo.addDevice("switch two"); // You can add more devices
//fauxmo.addDevice("switch three");
// -------------------------------
// Motor
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
myMotor->setSpeed(10); // 10 rpm
//-------------------------------------------
// fauxmoESP 2.0.0 has changed the callback signature to add the device_id,
// this way it's easier to match devices to action without having to compare strings.
fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state) {
Serial.printf("[MAIN] Device #%d (%s) state: %s\n", device_id, device_name, state ? "ON" : "OFF");
digitalWrite(LED, !state);
if (state == HIGH) {
Serial.print("Closing the curtain...");
}
else {
Serial.print("Opening the curtain...");
openCurtain();
}
});
// Callback to retrieve current state (for GetBinaryState queries)
fauxmo.onGetState([](unsigned char device_id, const char * device_name) {
return !digitalRead(LED);
});
}
void openCurtain() {
myMotor->step(100, FORWARD, SINGLE);
}
void closeCurtain() {
myMotor->step(100, BACKWARD, SINGLE);
}
void loop() {
// Since fauxmoESP 2.0 the library uses the "compatibility" mode by
// default, this means that it uses WiFiUdp class instead of AsyncUDP.
// The later requires the Arduino Core for ESP8266 staging version
// whilst the former works fine with current stable 2.3.0 version.
// But, since it's not "async" anymore we have to manually poll for UDP
// packets
fauxmo.handle();
static unsigned long last = millis();
if (millis() - last > 5000) {
last = millis();
Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());
}
}
And the full error is this:
Panic /Users/lewisaburrow/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/core_esp8266_main.cpp:98 __yield
ctx: sys
sp: 3ffff9d0 end: 3fffffb0 offset: 01b0
>>>stack>>>
3ffffb80: 00000001 00000002 3ffee770 40204b82
3ffffb90: 4010702c 00007530 00000064 402059fd
3ffffba0: 00000001 00000064 00007530 40204eca
3ffffbb0: 00000001 00000000 3ffee984 402053e9
3ffffbc0: 3ffe84e7 65526574 3ffffba0 3ffffe00
3ffffbd0: 3ffee78c 00000000 3ffee984 40202204
3ffffbe0: 3ffee78c 00000000 3ffee984 40202271
3ffffbf0: 65707954 3ffffc00 00000000 40203881
3ffffc00: 54534f50 70752f20 632f706e 72746e6f
3ffffc10: 622f6c6f 63697361 6e657665 48203174
3ffffc20: 2f505454 0d312e31 736f480a 31203a74
3ffffc30: 312e3239 312e3836 3933312e 3032353a
3ffffc40: 0a0d3030 65636341 203a7470 0d2a2f2a
3ffffc50: 6e6f430a 746e6574 7079742d 74203a65
3ffffc60: 2f747865 3b6c6d78 61686320 74657372
3ffffc70: 7475223d 22382d66 4f530a0d 43415041
3ffffc80: 4e4f4954 7522203a 423a6e72 696b6c65
3ffffc90: 65733a6e 63697672 61623a65 65636973
3ffffca0: 746e6576 5323313a 69427465 7972616e
3ffffcb0: 74617453 0a0d2265 746e6f43 2d746e65
3ffffcc0: 676e654c 203a6874 0d393932 3c0a0d0a
3ffffcd0: 6c6d783f 72657620 6e6f6973 2e31223d
3ffffce0: 65202230 646f636e 3d676e69 66747522
3ffffcf0: 3f22382d 3a733c3e 65766e45 65706f6c
3ffffd00: 6c6d7820 733a736e 7468223d 2f3a7074
3ffffd10: 6863732f 73616d65 6c6d782e 70616f73
3ffffd20: 67726f2e 616f732f 6e652f70 6f6c6576
3ffffd30: 222f6570 653a7320 646f636e 53676e69
3ffffd40: 656c7974 7468223d 2f3a7074 6863732f
3ffffd50: 73616d65 6c6d782e 70616f73 67726f2e
3ffffd60: 616f732f 6e652f70 69646f63 222f676e
3ffffd70: 3a733c3e 79646f42 3a753c3e 42746553
3ffffd80: 72616e69 61745379 78206574 736e6c6d
3ffffd90: 223d753a 3a6e7275 6b6c6542 733a6e69
3ffffda0: 69767265 623a6563 63697361 6e657665
3ffffdb0: 22313a74 69423c3e 7972616e 74617453
3ffffdc0: 3c303e65 6e69422f 53797261 65746174
3ffffdd0: 752f3c3e 7465533a 616e6942 74537972
3ffffde0: 3e657461 3a732f3c 79646f42 732f3c3e
3ffffdf0: 766e453a 706f6c65 00003e65 40101ea2
3ffffe00: 3fff0a5c 00000002 3fff0d0c 4010020c
3ffffe10: 40102bb5 3ffec9a8 3ffffe60 3fff0d0c
3ffffe20: 00000000 3ffee78c 3ffeb7c2 40203a5c
3ffffe30: 54534f50 70752f20 632f706e 72746e6f
3ffffe40: 622f6c6f 63697361 6e657665 48203174
3ffffe50: 2f505454 00312e31 3ffe97fc 00000001
3ffffe60: 000001fa 00007fff 000000ed 4010020c
3ffffe70: 3ffee960 04c14103 00002200 00000000
3ffffe80: 3fff0d0c 3fff09bc 00000000 40203a80
3ffffe90: 3ffe97c0 00000000 3fff0084 40204504
3ffffea0: 3fff0bdc 00000030 0000000f ffffffff
3ffffeb0: 3fff026c 3fff0274 00000006 3fff0080
3ffffec0: 3fff0bdc 3fff0088 3fff0084 4020454f
3ffffed0: 3fff0bdc 3fff0088 3fff0084 40229c30
3ffffee0: 000001fa 8b01a8c0 00000018 000001fa
3ffffef0: 00000018 00000000 3ffeea40 401074e4
3fffff00: 40100000 00000000 00000064 3fff0270
3fffff10: 3ffeb79a 3fff0274 3fff09bc 40228139
3fffff20: 3ffeff94 3fff072c 3fff072c 3ffedaf0
3fffff30: 00000000 3fff09bc 0000001c 3fff072c
3fffff40: 3ffeb78c 00000000 3fff09bc 40227535
3fffff50: 6301a8c0 00000258 00000000 0000001c
3fffff60: 00000002 0000001a 40207f53 3ffec9a8
3fffff70: 3ffeb764 3fffdcc0 3ffe9040 3ffe9040
3fffff80: 40207ec6 3ffec9a8 00000000 3fff079c
3fffff90: 3fffdc80 00000000 3fff09bc 4021bfbb
3fffffa0: 40000f49 3fffdab0 3fffdab0 40000f49
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(1,7)
ets Jan 8 2013,rst cause:4, boot mode:(1,7)
wdt reset