Step 1: Getting Ready
For this tutorial you need the following hardware components:
- Raspberry Pi (any model or version)
- "Make to push" button (if not sure please have a look at the video for details)
- Male to female jumper wires (x2)
- microSD card with Raspian GNU/Linux distribution
- Power supply
There are different types of push buttons depending on their mechanism. I am using a “push to make” button. It is similar to a button of keyboard. When the button is pressed it makes a contact with the electronic system and breaks the current process when the button is released. You can see the difference between buttons in the video.
Step 2: Wiring
Connect the button to ground and to a GPIO pin 7 of Raspberry Pi. After plug the microSD card with the Raspbian GNU/Linux distribution, make sure the board is connected to the Internet, plug the power supply and turn on the board.
Step 3: Setting Up Development Environment
Make sure that Raspbian GNU/Linux distribution is running on your Raspberry Pi. Log in though SSH or just open a terminal application on the Pi itself. After that execute the following command to install Node.js, npm (Node Package Manager) and Git:
sudo apt-get install -y nodejs npm git
Step 4: Installing the Example
Get the open source example and install its dependencies using npm:
git clone https://github.com/leon-anavi/rpi-nodejs-examples.git cd rpi-nodejs-examples npm install
Step 5: Handling the Button
Execute the following command to handle button events:
sudo nodejs button/button.js.
Please have a look at the video for more details.
Step 6: How Does It Work?