Exception 9 when sensor is activated

I am trying to create a set of friendship lamps according to this tutorial: https://www.instructables.com/CoronaLamps-Simple-Friendship-Lamps-Anyone-Can-Mak/
It uses esp8266, neopixels, and a touch sensor. The neopixels startup and flash indicating that they are connected, but when I press the touch sensor, i get this error and the lamps reset:

Exception (9):
epc1=0x40105d94 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000003 depc=0x00000000

>>>stack>>>

ctx: sys
sp: 3fffebc0 end: 3fffffb0 offset: 0150
3fffed10:  40105fc5 006bee8e 3ffee8ac 00000000  
3fffed20:  3ffee210 3ffee8ac 000000cc 40218a92
3fffed30:  00000000 0054170a 40205260 00001388  
3fffed40:  3ffee8ac 00004510 00001388 00001388  
3fffed50:  00004510 00001388 00004510 402052e6  
3fffed60:  00000000 00004510 bced9168 004fdb5a  
3fffed70:  00000000 00000002 3ffee6fb 00000002  
3fffed80:  00001388 00000000 3ffefdbc 40203e3c  
3fffed90:  00000030 00004510 3ffee6fc 00000001  
3fffeda0:  3ffef80c 00000002 3ffefa90 00000000  
3fffedb0:  3ffef644 000000fa 00000030 40208164
3fffedc0:  3ffef668 00000030 00000000 00000000  
3fffedd0:  00000000 3ffef884 3ffef98a 3ffee688  
3fffede0:  00000000 3ffef668 3ffef644 402029ba  
3fffedf0:  00000096 00000000 0000012b 3ffee688  
3fffee00:  0000000c 00000000 00000000 40100138  
3fffee10:  00000000 00000000 40100038 00000100  
3fffee20:  3ffe98fc 7fffffff 00000000 c0037015
3fffee30:  00000000 00000001 0000000c 40100654  
3fffee40:  00000020 00000000 0000001f 40100304  
3fffee50:  3ffee210 3ffef30c 3fffc228 00000022  
3fffee60:  3fffc200 40100588 3fffc258 4000050c  
3fffee70:  40000f68 00000030 00000014 ffffffff  
3fffee80:  40000f58 00000000 00000020 00000000  
3fffee90:  00000002 3ffee8ac 3ffee8ac fffffffe  
3fffeea0:  40208558 3ffee1e8 3ffee8ac 3fffdab0  
3fffeeb0:  00000000 3fffdad0 3ffee8d4 00000030  
3fffeec0:  000000b0 00000016 3ffe85e8 402105a8
3fffeed0:  00000000 000044f4 9374bc6a 402105d8  
3fffeee0:  40214b3c 00000020 3ffef26c 40214aed  
3fffeef0:  40214b3c 000044f4 3ffeefbc 40214b6f  
3fffef00:  4023e528 010d3b27 60000600 402105fd  
3fffef10:  010d5aed 3ffee210 3ffee1e8 40214cdc  
3fffef20:  40105d41 00540ce5 00000001 40100304  
3fffef30:  4023958c 3ffe8d9c 3ffee210 010d8501  
3fffef40:  402395b2 3fffdab0 00000000 3fffdab0  
3fffef50:  00000000 3fffdad0 3ffee8d4 402050aa  
3fffef60:  40000f49 3ffee230 3fffdab0 40000f49  
3fffef70:  40000e19 000476ff bff00000 0000bfff  
3fffef80:  00000005 aa55aa55 000000ed 401056e9
3fffef90:  401056ef bff00000 0000bfff 593ffe89  
3fffefa0:  4010000d bff00000 000476ff 401000ab  
3fffefb0:  402298dc 3fffef4c 40229895 3ffffe78  
3fffefc0:  3fffffd0 00000000 00000000 feefeffe  
3fffefd0:  feefeffe feefeffe feefeffe feefeffe  
3fffefe0:  feefeffe feefeffe feefeffe feefeffe  
3fffeff0:  feefeffe feefeffe feefeffe feefeffe  
3ffff000:  feefeffe feefeffe feefeffe feefeffe  
3ffff010:  feefeffe feefeffe feefeffe feefeffe  
3ffff020:  feefeffe feefeffe feefeffe feefeffe  
3ffff030:  feefeffe feefeffe feefeffe feefeffe  
3ffff040:  feefeffe feefeffe feefeffe feefeffe
3ffff050:  feefeffe feefeffe feefeffe feefeffe  
3ffff060:  feefeffe feefeffe feefeffe feefeffe  
3ffff070:  feefeffe feefeffe feefeffe feefeffe  
3ffff080:  feefeffe feefeffe feefeffe feefeffe  
3ffff090:  feefeffe feefeffe feefeffe feefeffe  
3ffff0a0:  feefeffe feefeffe feefeffe feefeffe  
3ffff0b0:  feefeffe feefeffe feefeffe feefeffe  
3ffff0c0:  feefeffe feefeffe feefeffe feefeffe  
3ffff0d0:  feefeffe feefeffe feefeffe feefeffe  
3ffff0e0:  feefeffe feefeffe feefeffe feefeffe  
3ffff0f0:  feefeffe feefeffe feefeffe feefeffe
3ffff100:  feefeffe feefeffe feefeffe feefeffe  
3ffff110:  feefeffe feefeffe feefeffe feefeffe  
3ffff120:  feefeffe feefeffe feefeffe feefeffe  
3ffff130:  feefeffe feefeffe feefeffe feefeffe  
3ffff140:  feefeffe feefeffe feefeffe feefeffe  
3ffff150:  feefeffe feefeffe feefeffe feefeffe  
3ffff160:  feefeffe feefeffe feefeffe feefeffe  
3ffff170:  feefeffe feefeffe feefeffe feefeffe  
3ffff180:  feefeffe feefeffe feefeffe feefeffe  
3ffff190:  feefeffe feefeffe feefeffe feefeffe
3ffff1a0:  feefeffe feefeffe feefeffe feefeffe  
3ffff1b0:  feefeffe feefeffe feefeffe feefeffe  
3ffff1c0:  feefeffe feefeffe feefeffe feefeffe  
3ffff1d0:  feefeffe feefeffe feefeffe feefeffe  
3ffff1e0:  feefeffe feefeffe feefeffe feefeffe  
3ffff1f0:  feefeffe feefeffe feefeffe feefeffe  
3ffff200:  feefeffe feefeffe feefeffe feefeffe  
3ffff210:  feefeffe feefeffe feefeffe feefeffe  
3ffff220:  feefeffe feefeffe feefeffe feefeffe  
3ffff230:  feefeffe feefeffe feefeffe feefeffe  
3ffff240:  feefeffe feefeffe feefeffe feefeffe
3ffff250:  feefeffe feefeffe feefeffe feefeffe  
3ffff260:  feefeffe feefeffe feefeffe feefeffe  
3ffff270:  feefeffe feefeffe feefeffe feefeffe  
3ffff280:  feefeffe feefeffe feefeffe feefeffe  
3ffff290:  feefeffe feefeffe feefeffe feefeffe  
3ffff2a0:  feefeffe feefeffe feefeffe feefeffe  
3ffff2b0:  feefeffe feefeffe feefeffe feefeffe  
3ffff2c0:  feefeffe feefeffe feefeffe feefeffe  
3ffff2d0:  feefeffe feefeffe feefeffe feefeffe  
3ffff2e0:  feefeffe feefeffe feefeffe feefeffe  
3ffff2f0:  feefeffe feefeffe feefeffe feefeffe  
3ffff300:  feefeffe feefeffe feefeffe feefeffe
3ffff310:  feefeffe feefeffe feefeffe feefeffe  
3ffff320:  feefeffe feefeffe feefeffe feefeffe  
3ffff330:  feefeffe feefeffe feefeffe feefeffe  
3ffff340:  feefeffe feefeffe feefeffe feefeffe  
3ffff350:  feefeffe feefeffe feefeffe feefeffe  
3ffff360:  feefeffe feefeffe feefeffe feefeffe  
3ffff370:  feefeffe feefeffe feefeffe feefeffe  
3ffff380:  feefeffe feefeffe feefeffe feefeffe  
3ffff390:  feefeffe feefeffe feefeffe feefeffe  
3ffff3a0:  feefeffe feefeffe feefeffe feefeffe  
3ffff3b0:  feefeffe feefeffe feefeffe feefeffe
3ffff3c0:  feefeffe feefeffe feefeffe feefeffe  
3ffff3d0:  feefeffe feefeffe feefeffe feefeffe  
3ffff3e0:  feefeffe feefeffe feefeffe feefeffe  
3ffff3f0:  feefeffe feefeffe feefeffe feefeffe  
3ffff400:  feefeffe feefeffe feefeffe feefeffe  
3ffff410:  feefeffe feefeffe feefeffe feefeffe  
3ffff420:  feefeffe feefeffe feefeffe feefeffe  
3ffff430:  feefeffe feefeffe feefeffe feefeffe  
3ffff440:  feefeffe feefeffe feefeffe feefeffe  
3ffff450:  feefeffe feefeffe feefeffe feefeffe  
3ffff460:  feefeffe feefeffe feefeffe feefeffe
3ffff470:  feefeffe feefeffe feefeffe feefeffe  
3ffff480:  feefeffe feefeffe feefeffe feefeffe  
3ffff490:  feefeffe feefeffe feefeffe feefeffe  
3ffff4a0:  feefeffe feefeffe feefeffe feefeffe  
3ffff4b0:  feefeffe feefeffe feefeffe feefeffe  
3ffff4c0:  feefeffe feefeffe feefeffe feefeffe  
3ffff4d0:  feefeffe feefeffe feefeffe feefeffe  
3ffff4e0:  feefeffe feefeffe feefeffe feefeffe  
3ffff4f0:  feefeffe feefeffe

I do not know much about Arduino so if anyone is able to explain my issue I greatly appreciate it.
Here's my code:

//import the libraries
#include <Adafruit_NeoPixel.h>
#include "config.h"

//define the Neopixel pin, this will be different then the pin we soldered the Neopixels to, as they are marked differently
#define PIN 5


//initialize the information for the Neopixels and Adafruit IO
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);
AdafruitIO_Feed *lamp = io.feed("lamp");

//how long we want the lamps to stay on when activated (600,000 ms = 10 minutes)
const long interval = 600000;

//setup the timers and status for the lamp
unsigned long previousMillis = 0;
int tap = 0;

//set one of the lamps to 1, the other to 2
int lampVal = 2;

//the value that should activate the lamp. Don't mess with this, the code will figure out what this should be in the setup
int recVal = 0;



void setup() {

  //Start the serial monitor for debugging and status
  Serial.begin(9600);

  //figure out what recieved value should turn on the lamp (lampVal of other lamp)
  if (lampVal == 1) recVal = 2;
  if (lampVal == 2) recVal = 1;
  
  //Activate the Neopixels
  strip.begin();
  strip.setBrightness(255);
  strip.clear();
  strip.show(); // Initialize all pixels to 'off'

  //setup the touch sensor as a interrupt and input
  pinMode(12, INPUT);
  attachInterrupt(digitalPinToInterrupt(12), touch, CHANGE);
  
  //start connecting to Adafruit IO
  Serial.print("Connecting to Adafruit IO");
  io.connect();

  //get the status of the value in Adafruit IO
  lamp->onMessage(handleMessage);

  //connect to Adafruit IO and play the "spin" Neopixel animation to show it's connecting until and connection is established
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    spin();
    delay(500);
  }

  //when a connection to Adafruit IO is made write the status in the Serial monitor and flash the Neopixels white
  Serial.println();
  Serial.println(io.statusText());
  flash();

  //get the status of our value in Adafruit IO
  lamp->get();
  
  
  previousMillis = millis();
}

void loop() {

  //keeps the ESP8266 connected to Adafruit IO
  io.run();

  //set the starting timer value
  unsigned long currentMillis = millis();

  //tap = 1 means that we have established that the other lamp was tapped
  if (tap == 1) {

    //check to see if the timer if over 10 minutes. If it is, turn off the Neopixels and reset the tap status
    if (currentMillis - previousMillis >= interval) {
      off();
      tap = 0;
    
    } else {

      //if the timer isn't over 10 minutes, continue playing the rainbow animation at a slow speed
      rainbow(200);
      
    }
    
  }
  
}


//the interrupt program that runs when the touch sensor is activated
ICACHE_RAM_ATTR void touch() {

  //while the touch sensor is activated, save the lampVal (either 1 or 2) to the Adafruit IO feed and turn the Neopixels to purple
  while (digitalRead(12) == 1) {

    lamp->save(lampVal);
    
      for(int i=0; i<strip.numPixels(); i++) {
        
      strip.setPixelColor(i, 102, 0, 204);
      
    }
    
    strip.show();

   //once the touch sensor isn't activated, send a 0 back to the Adafruit IO feed. 
  } if (digitalRead(12) == 0) {
    
      lamp->save(0);
      
      for(int i=0; i<strip.numPixels(); i++) {
        
      strip.setPixelColor(i, 0, 0, 0);
      
    }
    
    strip.show();
    
  }
  

}


//code that tells the ESP8266 what to do when it recieves new data from the Adafruit IO feed
void handleMessage(AdafruitIO_Data *data) {

  Serial.print("received <- ");

  //convert the recieved data to an INT
  int reading = data->toInt();

  //if the recieved value is equal to the recVal, and the lamp status is currently off, change the status to on and recent the timer
  if(reading == recVal && tap == 0) {
    
    Serial.println("TAP");
    previousMillis = millis();
    tap = 1;

  //if we recieve a value but the lamp is already on nothing happens
  } else {
    Serial.println("LOW");
  }

}

//simple code to turn all of the Neopixels off
void off() {
  
for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, 0, 0, 0);
    }
    strip.show();
  
}


//The code that creates the gradual color change animation in the Neopixels (thank you to Adafruit for this!!)
void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}


//complicated geometry or something to figure out the color values (I don't know how this stuff works, thank goodness for adafruit)
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}


//code to flash the Neopixels when a stable connection to Adafruit IO is made
void flash() {

  for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, 255, 255, 255);
    }
  strip.show();
  
  delay(200);

  for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, 0, 0, 0);
    }
  strip.show();
  
  delay(200);

  for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, 255, 255, 255);
    }
  strip.show();
  
  delay(200);

  for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, 0, 0, 0);
    }
  strip.show();
  
  delay(200);
}


//the code to create the blue spinning animation when connecting to Adafruit IO
void spin() {

  for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, 0, 0, 255);
      strip.show();
      delay(20);
    }
    for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, 0, 0, 0);
      strip.show();
      delay(20);
    }
  
}

The problem here is that instructables in genral not very good because the people who write them do not know as much as they thing they do.
In this case the author says:

solder the SIG wire to pin D6 on the ESP8266,

What the author does not appreciate that the ESP8266 is a system that can pump out signals of 3V3, which is below the signal level guaranteed to drive a 5V string of addressable LEDs. It is right on the edge of working, and sometimes it works and many times it doesn't. No doubt for the author it worked and so thought no more about it.

There are two things you could try, the first is the conventional approach of using two logic inverters in series to boost the signal level. This is tricky due to the physical space you have to work in.

The other unconventional approach is to lower the voltage applied to the addressable LEDs, by using a 1N4001 diode in series between the 5V supply and the 5V input of the addressable LEDs.

Exception 9 is an unaligned access. This is probably caused by a bad pointer. If you run the esp exception analyzer it may give you the source line where the problem started.

Hi, @masonjb
Welcome to the forum.

What are you using for a power supply?
How many Neopixels?

Thanks... Tom.. :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.