IoT Cookbook > Tessel > Accelerometer

Tessel Accelerometer component

The Tessel Accelerometer component publishes the raw accelerometer data from an accelerometer module via WAMP.

Tessel with accelerometer

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.

Install the Node.js dependencies by doing

npm install

Start up

crossbar start

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

In accelerometer.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"

Then run accelerometer.js on a Tessel with an accelerometer module connected to port A.

tessel run accelerometer.js

This should log

accelerometer initialized (output rates: 800,400,200,100,50,12.5,6.25,1.56)
sending accel data
sending accel data
sending accel data

Once this is running, open the browser console for the frontend page, and you'll see the raw accelerometer data logged as it is received.

received accelerometer data
Object {y: "-0.03", x: "0.02", z: "1.02"}


The accelerometer component publishes the raw accelerometer data as JSON to the topic


Using it

In your own project: