Pin re-assignment bricks imp

Are there any rules on dynamic pin re-assignment? The following code bricks the imp and only a power cycle will bring it back to life. Is it because I’m doing the re-assignment of the pin the caused the event handler to run?

Thanks as always

/`/ Event handler for PIR
function swEvent()
// Idle for 50ms to allow switch to settle

// Get PIR state
local state =;
// PIR movement
if(state == 1 && movement == 0){
    if(triggerCount == 5){
        movement =1;
        server.log("Movement - wait "+ reArmDelay +" secs - " + format("rssi: %d dBm", imp.rssi()) );
        local _httpOut="l|020|5|"+getDateTime()+"|Monitor-Movement|PIR";
        imp.wakeup(reArmDelay, reArm);

} `

Shouldn’t be an issue but absolutely sounds like a bug. I’ll file it as such…

Well, hang on, what’s connected to pin1? (Feel free to reply privately if need be.) But if you’re in an event handler 'cos something’s driving pin1 high, and the imp then tries to drive it low, you’re going to have a bad time.


Peter, All I was trying to do was stop the event handler being called for 20/30secs without using a server.sleep.

Ok what I’ve don’t is just removed that event handler but still bricking the imp.
hardware.pin1.configure(DIGITAL_IN_PULLDOWN); in place of dig out


Ah, a pin configured as DIGITAL_OUT is always driven. Using analog in instead is a much better idea.


Or you could configure it as DIGITAL_IN but without the callback.


Peter, ok that’s what I’ve done but still bricks the imp.
Could I confirm that whitest in shallow sleep e.g. imp.wakeup that a pin event handler will be called e.g it isn’t blocked?
Hope I’m making sense not too sure if I am these days!

In imp.wakeup(), a pin event handler will be called. In imp.sleep() or server.sleepfor(), it won’t.


Peter thanks I have my workaround imp.sleep
perhaps a little more meat in the wiki for imp.sleep

The method will block for this period.
Does that included blocking an InputPort setter?

One last thing will a run timer error always cause a reboot?
Thinking of updating my state digram to reflect this.

Yes it does include blocking an InputPort setter, and yes the wiki should say so. I’ll head off there now.

And all Squirrel runtime errors cause a reboot (or certainly should do), whether the Squirrel in question is being run on startup or in an event handler or timer callback.


Peter thanks again for your help & have a good weekend.
I’m heading for the mince pies and mulled wine :slight_smile: