Mini Push Button

I am trying to wire up a mini push button(https://www.sparkfun.com/products/97) as in the arduino example(http://arduino.cc/en/tutorial/button).
Using the new event handler code, this is my code, using pin 9:

CODE
`// BUTTONS
function pin9changed()
{
// declare a local variable - we can store the value of the pin in here if we need it
local buttonState = hardware.pin9.read();

// if buttonState is 0, the button is pushed
if (buttonState == 0) {
    // server.show logs text to the logs, but also displays text right in the node on the planner
    server.show("Button Pressed!");
} else {
    server.show("Button Released!");
}

}

hardware.pin9.configure(DIGITAL_IN_PULLUP, pin9changed);`

I tried DIGITAL_IN_PULLUP and DIGITAL_IN, no response when pressing the button.
I am using the 3.3 imp output port instead of the 5V arduino of course, but the 10K Ohm resistor.

Anyone any ideas what’s missing here?

Do you have:

imp.configure("Button Press",[],[]); pin9changed();

at the end of your code? This configures the imp to the planner. If you do not have the function called after the configure, the imp won’t do anything. Also according to the Arduino schematic, you don’t need Digital_IN_PULLUP, because the pin is looking for a high (3.3V when pressed), otherwise the pin gets pulled to ground by the 10k resistor (0V - low when not pressed).

You can also use a callback function so that whenever the pin changes state, the function is called to update the state of the switch on the planner.

hardware.pin9.configure(DIGITAL_IN, pin9changed);

example switch program for the imp:
http://devwiki.electricimp.com/doku.php?id=examplecode
(except they use an internal pullup to pull the pin high when the switch is open, opposite to what you are doing).

Oh lordy, yes its an input source of course.

Wonder if the event referencing should auto integrate on the configure call, no?

Nope didn’t do it. I have another pin set set up for output, its a serial connection to a module. Code looks like this.

CODE
`
// configure a pin pair for UART TX/RX
hardware.uart57.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, readSerial);
hardware.pin9.configure(DIGITAL_IN_PULLUP, pin9changed);

imp.configure(“Text To Speech”, [], [], {}, pin9changed);
`

`// Example button switch read

function pin9changed() { // define our callback function
local buttonState = hardware.pin9.read();
// if buttonState is 0, the button is released
if (buttonState == 0) {
server.show(“Button Released!”);
}
else {
server.show(“Button Pressed!”);
}
}

hardware.pin9.configure(DIGITAL_IN, pin9changed);
server.log(“Button example started”);
imp.configure(“Button example”, [], []);`

Also, are you sure you hooked up the right pins on the switch? I believe those switches are continuous when pressed for diagonal pins. If you have a multimeter you can check that the right pins are connected…

Also you don’t need “pin9changed” in the imp.configure call…

Naaaaaaa. server.show does not print out on log screen!

server.log did.

Very simple code:

`// Example button switch read

function pin9changed() {
server.log(hardware.pin9.read());
}

hardware.pin9.configure(DIGITAL_IN, pin9changed);
server.log(“Button example started”);
imp.configure(“Button example”, [], []);`

You can try to manually put 3.3v to pin9 via a jumper wire to see if that signals the callback…

Yeah I fixed it as of my last message, I just didn’t use server.log, yet expected text on the log screen , me bad.

Cool!