IoT Cookbook > Arduino Yun > Buttons

Yun Buttons component

The Arduino Yun Button component publishes events for presses on up to 6 Tinkerkit button modules via WAMP.

Arduino Yun with buttons

Trying it out

The code for this can be found in the crossbarexamples GitHub repository under iotcookbook. You need to clone this (or download it as a ZIP file).

Open a shell for the component directory.

Start up

crossbar start

This also serves a frontend where you can view the button data logged at http://localhost:8080.

In buttons_yun.js, add the URL of the machine on which runs:

var connection = new autobahn.Connection({
    // replace with the url of your crossbar instance
    url: "ws://<URL OF YOUR CROSSBAR INSTANCE>/ws",
    realm: "iot_cookbook"

Additionally, in the buttons array, only those parts corresponding to actually connected buttons should be commented in. Otherwise, with e.g. a connection pattern like 0--3--, while a press on 0 will produce the correct event, a press on 3will produce events for the unconnected buttons 1 and 2 in addition to 3.

You need to set up the Yun for using AutobahnJS, including setting up firmata on the MCU.

Transfer buttons_yun.js on the Yun, e.g. by doing

scp buttons_yun.js root@<IP of your Yun>:~/

Then run buttons_yun.js

node buttons_yun.js

This should log

Arduino Yun Buttons starting ...
Arduino connected (over /dev/ttyATH0, board version 2.3)
Connecting to router ...
Router connected. Session ID: 1595783623

Once this is running, open the browser console for the frontend page and press some buttons. You'll see the button events logged:

Button pressed:  3
Button pressed:  0
Button pressed:  3


The buttons component publishes events for button presses to the topic with the button pressed in the arguments.

Using it

In your own project: