Setting up a button on Hannah

in my ongoing searching and stealing I have a new version assembled.
Buttons and Hall sensor are now interrupt driven.
Temperature and Potmeter value can be read.
I have still a problem with the button state: release of the button will sometimes be ignored.
Could use some help.
Accellerator, Lightsensor and PWM are still on the TODO list

@sbright33

I suppose that you can make a sleepfunction activated with a button press, but waking up seems hard, because you cannot communicate with the imp while it is sleeping

Sorry if post only “theory” and not code, but actually the buttons are connected to the IOs (0 and 1) of the expander and the expander with his INT_L is connected to the pin1 of the imp, that’s the wakeup pin.

From the datasheet:

The SX1507, SX1508 and SX1509 have the ability to
generate mask-programmable interrupts based on
falling/rising edge of any of its GPIO lines. A
dedicated pin indicates to a host controller that a
state change occurred in one or more of the lines.

http://www.semtech.com/images/datasheet/sx150x_789.pdf

So, still from the datasheet:

Example: We want to detect rising edge of I/O[1] on SX1508 (NINT will go low).

  1. We enable interrupt on I/O[1] in RegInterruptMask
    RegInterruptMask =“XXXXXX0X”
  2. We set edge sense for I/O[1] in RegSense
    RegSenseLow =“XXXX01XX”

The registers to set are: 0x09, 0x0A, 0x0B, 0x0C with details at page 52 of the datasheet.

Again, sorry but I don’t have time to propose code, but I think this can be the solution.

Dimitri

thanks Dimitri,
looks like I have no reason to get bored this weekend :frowning:

@DolfTraanberg,

I guess it’s pretty much impossible to get bored when you have a imp :smiley:

If you want to get some headache with the accelerometer I’ve collected some information, like the setup sequence and the sequence for properly ready the values, but I didn’t find the time yet to make it become code usable.

D

I have still have to learn to be a bitshifter, so yes, any input is welcome

Anyone do it yet? You mean I have to write it myself? :wink:

How do you delete a comment?

Has anyone tried getting button inputs on spare 14 and/or 15. I have cloned the initializations and supplied callbacks, but don’t seem to be able to see the callback being called.

` spare_15 = null; // gca
on_spare_15_changed = null; // gca
// Spare 15 on IO pin 15
spare_15 = ExpGPIO(ioexp, 15).configure(DIGITAL_IN_PULLUP, call_callback(“on_spare_15_changed”)); // gca

hannah.on_spare_15_changed = function(state) {
server.log("Spare 15 is triggered: " + (state ? “up” : “down”));
}
`

Am I missing something? Do I need to change an GPIO or interrupt mask.

Thank you for any guidance.

Greg

NOTE: I fixed the error note below in the code above

Edit - changed post to describe and resolution - thanks to @aron for helping!

We found a bug in the Hannah code. The code has been update on GitHub, and should work for you know.

If you don’t want to grab the code from GitHub, here is the change:

Line 247 of the Hannah code:

_callbacks.insert(gpio, _callback);

should be changed to:

_callbacks[gpio] = _callback;

Also, you should note that there’s a minor bug in your code right now:

spare_15 = ExpGPIO(ioexp, 15).configure(DIGITAL_IN_PULLUP, call_callback("spare_15_changed")); // gca

should probably be:

spare_15 = ExpGPIO(ioexp, 15).configure(DIGITAL_IN_PULLUP, call_callback("on_spare_15_changed")); // gca

As you’ve named your callback function on_spare_15_changed not spare_15_changed.

It worked perfectly. Thank you.

I also modified the Pot call back to quiet it down. It may help someone else.

`//

local lastPot = 0;

hannah.on_pot_changed = function(state) {
local delta = lastPot - state;

if (delta<0)
    delta = delta * -1;
    
if (delta>0.03)  // 3% changed... You can modify the sensitivity by changing this value
{
    server.log("Pot has changed to: " + state);
    lastPot = state;
}
   hannah.srv1.write(state);
  hannah.srv2.write(state);

}`