By Anna Gerber
LittleBits are modular electronic components that snap together via magnetic connectors. You can write programs to work with LittleBits circuits using the Little Bits Arduino At Heart module to read from input modules like buttons and dimmers, or to control output modules producing light, movement and sound. This tutorial will get you started with programming with LittleBits modules using JavaScript.
The tutorial projects are organised by LittleBits kit so that you can find projects that will work with the bits that you have. At a minimum, you'll need an Arduino At Heart module, a power module and at least one input or output module.
Projects by Kit:
- Arduino Coding Kit
- Base Kit
- Premium Kit
- Deluxe Kit
- KORG Synth Kit
- Space Kit
- Hardware Development Kit
View a list of all projects
You can download all of the project files as a zip file here or visit AnnaGerber/little-bits-js on GitHub.
We'll be using the Node.js platform to run the JavaScript programs that we develop. You can download Node.js from nodejs.org
Johnny-Five is an Open Source Arduino programming framework for Node.js that we will use to communicate with the LittleBits Arduino At Heart Module.
We'll be using the terminal (command line) to run our programs. On Mac open /Applications/Utilities/Terminal.app
or on Windows, launch Start > All Programs > Accessories > Command Prompt
.
We'll need to install the johnny-five framework using the Node Package Manager. Download the project files and extract to a directory (e.g. little-bits-js) in your home directory, and then run the following commands via the terminal to change into that directory (cd) and install johnny-five and other libraries required for all of the projects:
cd little-bits-js
npm install
Use your favourite text editor or JavaScript Integrated Development Environment (IDE) e.g. Atom, Sublime Text, for editing JavaScript files.
Johnny-Five communicates with Arduino using the Firmata protocol, so you'll need to install Firmata on Arduino as a once-off step before you can start programming the board:
- Download the Arduino IDE
- Connect the Arduino module to the computer using USB
- The module does not get power via USB so you'll also need to connect a (blue) power module to the Arduino module to any of the 3 inputs on the Arduino module (d0, a0 or a1)
- Open the Arduino IDE and select 'Arduino Leonardo' under the Tools > Board menu
- Select the Serial port for your board under Tools > Serial Port. It will look something like /dev/tty.usb(...) on Mac, /dev/ttyUSB(...) on Linux or COM... on Windows.
- Open File > Examples > Firmata > StandardFirmata
- Click the 'Upload' button the send the Firmata program to the Arduino
- Wait until the status bar at the bottom of the Arduino IDE window says 'Done uploading' then close the Arduino IDE. Your Arduino is ready to go!
You can run the JavaScript programs that you create using Node.js from the command line. For example to run the blink program from the first project, run the following from your little-bits-js directory:
node blink/blink.js
Note: you'll need to wait a few seconds after plugging in the Arduino before running the program to give the Arduino time to power up. If see see an error like 'Error: Serialport not open.' try running the program again.
These projects will get your started with programming LittleBits modules with JavaScript using the Arduino Coding Kit (previously known as Arduino Starter Bundle).
- Blink Blink an LED
- Brightness Use a dimmer to control LED brightness
- Pulse Use a dimmer to create an LED pulsing effect
- Press Respond to button presses
- Sweep Sweep a servo back and forth
- Turn Turn a servo to specific positions
- Draw Use dimmers to draw like an Etch-a-sketch.
All of the bits for the Getting Started projects are included in the Arduino Coding Kit.
- 1 x Arduino At Heart (Used in all projects)
- 1 x fork (Used in Draw)
- 1 x power (Used in all projects)
For any of these projects, you can substitute an alternative power module like the USB power module.
If you have the Base Kit and an Arduino At Heart module, you can try these projects:
- Blink Blink an LED
- Brightness Use a dimmer to control LED brightness
- Pulse Use a dimmer to create an LED pulsing effect
- Press Respond to button presses or triggers
- Move Move a DC motor
- Sense Read from an analog sensor
- 1 x Arduino At Heart (Used in all projects)
- 1 x power (Used in all projects)
- 1 x button (Used in Press)
- 1 x dimmer (Used in Brightness and Pulse)
- 1 x light-sensor (Can be used in Sense)
- 1 x bargraph (Used in Blink and Brightness)
- 1 x bright-led (Can be used in Blink and Brightness)
- 1 x dc-motor (Used in Move)
The bits for these projects can be found in the Premium Kit. As always, you'll also need an Arduino At Heart module.
- Blink Blink an LED
- Brightness Use a dimmer to control LED brightness
- Press Respond to button presses
- Pulse Use a dimmer to create an LED pulsing effect
- Sweep Sweep a servo back and forth
- Turn Turn a servo to specific positions
- Move Move a DC motor
- Sense Read from an analog sensor
- 1 x Arduino At Heart (Used in all projects)
- 1 x branch (Optionally used in Sense)
- 2 x wire (Optionally used in Sense)
- 1 x power (Used in all projects)
- 1 x slide-dimmer (Can be used in Brightness and Pulse)
- 1 x roller-switch (Can be used in Press)
- 1 x pressure-sensor (Can be used in Sense)
- 1 x sound-trigger (Can be used in Press)
- 1 x long-led (Can be used in Blink and Brightness)
- 1 x servo (Used in Sweep and Turn)
- 1 x vibration-motor (Can be used in Move)
- 1 x fan (Can be used in Move)
You can make these projects with the Deluxe Kit plus an Arduino At Heart module.
- Press Respond to button presses
- Sweep Sweep a servo back and forth
- Turn Turn a servo to specific positions
- Move Move a DC motor
- Sense Read from an analog sensor
- 1 x Arduino At Heart (Used in all projects)
- 1 x fork (Optionally used in Sense)
- 2 x wire (Optionally used in Sense)
- 1 x power (Used in all projects)
- 1 x button (Used in Press)
- 1 x slide-dimmer (Can be used in Sense)
- 1 x sound-trigger (Can be used in Press)
Combine the Arduino At Heart module with the Synth Kit and you'll be making amazing sounds in no time!
- 1 x Arduino At Heart (Used in all projects)
- 1 x power (Used in all projects)
- 1 x speaker
You can build these projects with bits from the Space Kit plus Arduino At Heart.
- Blink Blink an LED
- Press Respond to button presses or triggers
- Sweep Sweep a servo back and forth
- Turn Turn a servo to specific positions
- Move Move a DC motor
- Sense Read from an analog sensor
- 1 x Arduino At Heart (Used in all projects)
- 1 x power (Used in all projects)
- 1 x light-sensor (Can be used in Sense)
- 1 x remote-trigger (Can be used in Press)
- 1 x bright-led (Can be used in Blink)
- 1 x ir-led (Can be used in Blink)
- 1 x dc-motor (Used in Move)
- 1 x speaker
Build and program your own bits!
- Proto Input Program your own input module
- 1 x Arduino At Heart (Used in all projects)
- 1 x Proto Module (Used in Proto Input)
- 1 x power (Used in all projects)
- Blink Blink an LED
- Brightness Use a dimmer to control LED brightness
- Pulse Use a dimmer to create an LED pulsing effect
- Press Respond to button presses
- Sweep Sweep a servo back and forth
- Turn Turn a servo to specific positions
- Move Move a DC motor
- Sense Read from an analog sensor
- Draw Use dimmers to draw like an Etch-a-sketch.
- Proto Input Program your own input module
More projects coming soon!
If you liked this tutorial you might also like node-ardx.
Copyright (c) 2014 Anna Gerber. Code licensed under the MIT license. Images and text licensed under CC-BY-SA.
Images of bits used in this tutorial have been sourced from littlebits.cc and used under a Creative Commons CC-BY-SA license. Some of the project ideas were inspired by LittleBits Arduino sketches.