Arduino 1.6.4 Verify will not complete. Not getting error messages.

Ok, first off, I am super green. I am a mechanical engineer, so this is definitely not my area of expertise. I am making an art piece for a client and the requirements are as follows:

Battery powered (6600mAh Li Ion Battery)
LEDs that are individually addressable (Adafruit NeoPixels)
Remote operation (Simple 315mHz RF Transmitter/Receiver)
Rechargable (Adafruit Powerboost 500 + Charger)
Controller (Pro Trinket 5V)

I am using two downloaded libraries, EnableInterrupt and Adafruit_Neopixel, along with some avr libraries to get the hardware interrupt to work. I am using the hardware interrupt on pin 3 to activate a sleep mode.

For some reason, when I try to Verify or Upload the sketch, it just gets stuck and does not complete the process. The status bar just kind of hangs at around 30%. The software is not frozen, because I can still work in the environment and save. I have been using this software for a while and have never had this problem before.

I am thinking there is something in my code that is hanging up the compiler, but I am not sure what it could be. The code is definitely not completely thought out yet, and I am sure there are problems with it, but I can not find them because the compiler will not give me error messages. This is the first time I have ever used interrupts, or a sleep function, so if you see something strange in my code, it would love to know so I can address it. Thanks in advance!

#include <EnableInterrupt.h>
#include <Adafruit_NeoPixel.h>
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/io.h>

#define sleepPin 3
#define upPin 4
#define modePin 5
#define downPin 6
#define ledQty 4
#define NEEDFORSPEED
volatile byte flashSpeed = 127;
volatile byte mode = 63;
byte randNumber;
byte modeInc = 64;
byte speedInc = 32;
#define ledDataPin 8

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(ledQty, ledDataPin, NEO_GRB + NEO_KHZ800);


void setup() {

  strip.begin(); 
  strip.show();  //initialize all pixels to off state
  pinMode(upPin, INPUT);
  pinMode(modePin, INPUT);
  pinMode(downPin, INPUT);
  pinMode(9,INPUT_PULLUP);
  pinMode(10,INPUT_PULLUP);
  pinMode(11,INPUT_PULLUP);
  pinMode(12,INPUT_PULLUP);
  pinMode(13,INPUT_PULLUP);
  pinMode(sleepPin, INPUT_PULLUP);
  enableInterrupt(sleepPin, sleepNow, CHANGE);
  pinMode(upPin, INPUT_PULLUP);
  enableInterrupt(upPin, upFunction, CHANGE);
  pinMode(modePin, INPUT_PULLUP);
  enableInterrupt(modePin, modeFunction, CHANGE);
  pinMode(downPin, INPUT_PULLUP);
  enableInterrupt(downPin, downFunction, CHANGE);
  
}

void loop() {
  
  if (mode == 63)
  {
    pulse(flashSpeed);
  }
  else if (mode == 127)
  {
    blinking();
  }
  else if (mode == 191)
  {
    solid();
  }
  else
  {
    randomized();
  }

}

byte upFunction() {
  int val;
  val == flashSpeed + speedInc;
  flashSpeed == val;
}

byte modeFunction() {
  int val;
  val == mode + modeInc;
  mode == val;
}

byte downFunction() {
  int val;
  val == flashSpeed - speedInc;
  flashSpeed = val;
}


void pulse(uint8_t flashSpeed) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, j,0,0);
    }
    strip.show();
    millis(flashSpeed);
  }
    for(j=255; j>0; j--) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, j,0,0);
    }
    strip.show();
    millis(flashSpeed);
  }
}

void blinking() {

  strip.setPixelColor(j,0,0);
  strip.show();
  millis(flashSpeed);
  strip.setPixelColor(0,0,0);
  strip.show();
  millis(flashSpeed);
}


void solid() {

  strip.setPixelColor(j,0,0);
  strip.show();
  millis(1000);
  
}

void randomized() {

  randNumber = random(ledQty);
  pixels.setPixelColor(randNumber, pixels.Color(255,0,0));
  pixels.show(); // This sends the updated pixel color to the hardware.
  millis(flashSpeed); // Delay for a period of time (in milliseconds).
  
}


void sleepNow(void)
{
    // Set pin 3 as interrupt and attach handler:
    attachInterrupt(1, pinInterrupt, LOW);
    delay(100);
    //
    // Choose our preferred sleep mode:
    set_sleep_mode(SLEEP_MODE_IDLE);
    //
    // Set sleep enable (SE) bit:
    sleep_enable();
    //
    // Put the device to sleep:
    strip.show();   // turn LED strip off
    sleep_mode();
    //
    // Upon waking up, sketch continues from this point.
    sleep_disable();
}
                //
void pinInterrupt(void)
{
    detachInterrupt(1);
}

Hi,
What model arduino are you using, and have you selected that in the IDE?

Tom.... :slight_smile:

Your interrupt service routines are not declared return type void, which may be a problem.

millis(flashSpeed);

This doesn't look valid to me.

byte upFunction() {
  int val;
  val == flashSpeed + speedInc;
  flashSpeed == val;
}

All of the statements in this function look nonsensical.

That still doesn't explain why the compiler "hangs up" instead of pointing out your errors, though.

byte upFunction() {
  int val;
  val == flashSpeed + speedInc;
  flashSpeed == val;
}

This function is also declared to return a byte value, and it doesn't return anything.

Instead of wasting our time and your own writing nonsense, I'd suggest reading an elementary book on basic C/C++ language and syntax.

TomGeorge:
Hi,
What model arduino are you using, and have you selected that in the IDE?

Tom.... :slight_smile:

I am using an Uno to flesh out the program before I switch over to the trinket. I did select the right one in the IDE, and none of my other sketches have this problem. This can only lead me to believe that the problem lies in my code.

michinyon:
Your interrupt service routines are not declared return type void, which may be a problem.

I had originally had them as void, and I was having this problem, so I assumed that since the code was trying to increase a variable, that maybe the void type might be causing the problem since it would not allow a return value. Is this logic erroneous?

michinyon:
This doesn't look valid to me.

Originally I had that as a delay, but I had read that a delay will simply hold up the processor and not allow other things to happen. I was not sure if this would affect the interrupts, so I changed it to millis. I would like the blink and pulse functions to use the flashSpeed variable to set the speed of the pulse/blink.

michinyon:

byte upFunction() {

int val;
  val == flashSpeed + speedInc;
  flashSpeed == val;
}




This function is also declared to return a byte value, and it doesn't return anything.

Instead of wasting our time and your own writing nonsense, I'd suggest reading an elementary book on basic C/C++ language and syntax.

This part of the code was rewritten about 20 times in an attempt to find the error that was causing the compiler to hang. I typically would not post in a forum because of high horse answers like this, and instead just research my errors, but in this case I can't get any errors because it will not compile.

Hi,

byte upFunction() {
  int val;
  val == flashSpeed + speedInc;
  flashSpeed == val;
}

You are trying to add two variables together I assume, so why are you comparing them?

byte upFunction()
  
  flashspeed = flashSpeed + speedInc;
  
}

Should do the addition.
Tom.... :slight_smile:

TomGeorge:
Hi,

byte upFunction() {

int val;
  val == flashSpeed + speedInc;
  flashSpeed == val;
}



You are trying to add two variables together I assume, so why are you comparing them?



byte upFunction()
 
  flashspeed = flashSpeed + speedInc;
 
}



Should do the addition.
Tom.... :)

Thanks for the assistance. I originally had something similar, but after I added the ISRs with that type of code, I assumed that maybe the interrupt might be having a problem incrementing a variable while simultaneously referencing it. So I created the variable val, set it equal to flashSpeed + speedInc, and then set flashSpeed equal to val.

If it can do an increment and reference simultaneously, that is awesome and I will change it.

Ok, so apparently my millis() calls are creating the problem. When I replace them with delay(), I get my errors back. Now, the questions is, will an ISR interrupt a delay, or will it lock up the processor to the point where my ISR will not get through?

I had originally had them as void, and I was having this problem, so I assumed that since the code was trying to increase a variable, that maybe the void type might be causing the problem since it would not allow a return value. Is this logic erroneous?

Not only erroneous, but incomprehnsible.

Originally I had that as a delay, but I had read that a delay will simply hold up the processor and not allow other things to happen. I was not sure if this would affect the interrupts, so I changed it to millis.

Why would you expect millis( ) to work that way ?

I would like the blink and pulse functions to use the flashSpeed variable to set the speed of the pulse/blink.

So write a function that actually does that, then.

This part of the code was rewritten about 20 times

Instead of writing random nonsense, learn what the built-in functions actually do, instead of wishful thinking about what you would like them to possibly do.

Now, the questions is, will an ISR interrupt a delay, or will it lock up the processor to the point where my ISR will not get through?

An interrupt can occur during a delay( ), but when the ISR finishes running, the delay will continue.

If you want the arduino to abort the delay and start doing something else, after the interrupt occurs, then you need to implement this another way.

In general, avoid using delay( ).

You could write something like this, if you really wanted to.

volatile bool stop_delay=false ;

void setup()
{
     attachInterrupt( 1, myInterrupt, CHANGE );
}

void myInterrupt()
{
    stop_delay=true ;
}

void loop( )
{
      // do stuff here 

      unsigned long delay_interval=500 ;
      unsigned long delay_start = millis( ) ;     // note the use of a single equals sign 
                                                             // for an assignment statement

      // delay for about 500 milliseconds,  or an interrupt occurs

      while( millis()-delay_start  < delay_interval )
      {
             if ( stop_delay ) break ;
             delay(1) ;
      }

      // do more stuff
}

None of this has yet explained why the OP's compiler hang up. Why does that happen ?

michinyon:
An interrupt can occur during a delay( ), but when the ISR finishes running, the delay will continue.

If you want the arduino to abort the delay and start doing something else, after the interrupt occurs, then you need to implement this another way.

In general, avoid using delay( ).

I am ok with the resumption of the delay post ISR.

I was trying to avoid using delay() by using millis() instead. I had read the millis() would not hang up the processor like delay(), so I tried to substitute it.

I just switched back to delay, and I got my error messages back! I have no idea why this would cause the compile hangup. But that is now working normal again.

I was trying to avoid using delay() by using millis() instead. I had read the millis() would not hang up the processor like delay(), so I tried to substitute it.

Find the example program "Blink without delay", and examine how that works.

This has happened to me a number of times, usually when I use older libraries, written by 3rd parties from the early v1 days.

  1. confirm your using the correct libraries for 1.6.4, remove 3rd party libraries if possible.
    This may mean commenting out the #include of the library in question, then commenting out your usage of each function in your code that uses that library.

As in all programming languages, a way to make sense of nonsensical errors or non-errors, is to:
2) try hitting ctl-Z to move back to when the code was compiling.
3) or cut your code in half, see which half the error/non-error/hang occurs, then again and again until you have working code.
4) or if your code isn't too big, chop off the first few pages, comment out function calls that cause errors, and slowly add your code from the backup page by page until the error occurs, if the error doesn't occur, then uncomment your previous comments until the error occurs.

Number (3) and (4) can be achieved by first commenting out your own function calls that are in the other half your code, or create dummy functions if necessary.

  1. comment out the contents of your functions one by one, until the error goes away, like this:
void myfunction(int stuff) {
/* the
*/ code
}

Its not the coding, its the logic of dealing with a puzzle.