Community
cancel
Showing results for 
Search instead for 
Did you mean: 
AMurp3
Beginner
1,298 Views

Trying to make a simple button, without success

Hello.

I'm trying to create what should be a very simple project: Reading the state of a momentary button switch. But it is not working as I think it should.

Here's what I'm setting up on my breadboard:

And here's my NodeJS code in XDK:

/* jslint node:true */

/* jshint unused:true */

"use strict";

var mraa = require("mraa");

var upm = require("jsupm_button");

var myButton = new upm.Button(31); // 'GP44' on the Sparkfun GPIO Block

var buttonState;

var periodicActivity = function() {

// check what the button is up to

buttonState = myButton.value(); // '1' if pressed, '0' if not

console.log(buttonState);

};

var intervalID = setInterval(periodicActivity, 250); // start checking the button's state

Instead of logging "0" for an unpressed button and "1" for pressed, what I see is that when I first start the program I do get "0", but after pressing the button it is stuck on "1", regardless of if the button is pressed or not. The only way to reset it to "0" is to reboot the Edison. I have confirmed that the voltage being sent to pin GP44 is switching between 0v and ~3.3v when pressed, but this state change is being ignored.

I've tried re-flashing the Edison and starting from scratch, with no change. I must be missing something, but I don't know what it is. Any suggestions..?

0 Kudos
8 Replies
AMurp3
Beginner
86 Views

To try and simplify it even further, I removed the button completely by running a wire from the 1.8v line and re-building the program using https://github.com/intel-iot-devkit/upm/blob/master/examples/javascript/button.js upm/button.js at master · intel-iot-devkit/upm · GitHub

Ran the program, I get '0' on the pin, plug the 1.8v line into that pin and it switches to '1', unplug the line and it's stuck at '1' still. Shut down the program, re-start, still stuck at '1'.

idata
Community Manager
86 Views

Hi Andr01dm,

 

 

Thanks for reaching out.

 

 

That's weird, I just tested the code in my Edison with the latest image (3.10.98-poky-edison+) and it worked without issues.

 

 

Make sure that you are using the latest image (You can follow this guide: https://communities.intel.com/docs/DOC-25154 https://communities.intel.com/docs/DOC-25154)

 

 

I hope you find this helpful.

 

 

Have a nice day.

 

 

Regards,

 

-Leonardo
AMurp3
Beginner
86 Views

Hello, Leonardo. Thank you for replying.

According to the Intel Edison Board Configuration Tool the firmware I have installed is "201606061707" which appears to match the "Latest Yocto* Poky image" available on https://software.intel.com/en-us/iot/hardware/edison/downloads Downloads for Intel® Edison Module | IoT | Intel® Software

AMurp3
Beginner
86 Views

Hello again.

I've tried re-flashing to the latest Yocto, still no success. I noticed a slew of npm errors when I update/install the XDK daemon, I'm not sure if they could be where things are going pear shaped. I've opened an issue on the npm Github: https://github.com/npm/npm/issues/15424 Edison XDK Daemon Install Error · Issue # 15424 · npm/npm · GitHub

idata
Community Manager
86 Views

Hi Andr01dm,

 

 

Yes, it is the latest image. Now, like I told you it is a weird issue. Can you try it on another GPIO pin? And can you also try it with a different programming language? Because I didn't have issues at all, so it can't be a software issue.

 

 

I will be waiting for your reply.

 

 

Regards,

 

-Leonardo
AMurp3
Beginner
86 Views

Ah! I figured it out. I was misunderstanding how to use the pull-up resistor, and didn't realize that the pin needed to be pulled to ground to reset it to '0'.

idata
Community Manager
86 Views

Hi Andr01dm,

 

 

That's great, it is good to know that you fixed that.

 

 

Feel free to contact us when you have doubts.

 

 

Regards,

 

-Leonardo
AMurp3
Beginner
86 Views

Thank you for your help.

Reply