Skip to content

AnnaGerber/little-bits-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Programming LittleBits with JavaScript

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:

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.

Preparing your development environment

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.

Preparing the Arduino

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!

Running your programs

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.

Getting Started with the Arduino Coding Kit

These projects will get your started with programming LittleBits modules with JavaScript using the Arduino Coding Kit (previously known as Arduino Starter Bundle).

  1. Blink Blink an LED
  2. Brightness Use a dimmer to control LED brightness
  3. Pulse Use a dimmer to create an LED pulsing effect
  4. Press Respond to button presses
  5. Sweep Sweep a servo back and forth
  6. Turn Turn a servo to specific positions
  7. Draw Use dimmers to draw like an Etch-a-sketch.

Bits you'll need

All of the bits for the Getting Started projects are included in the Arduino Coding Kit.

Wire (orange)

image image

Power (blue)

image

  • 1 x power (Used in all projects)

For any of these projects, you can substitute an alternative power module like the USB power module.

Inputs (pink)

image image

Outputs (green)

image image

Working with the Base Kit

If you have the Base Kit and an Arduino At Heart module, you can try these projects:

  1. Blink Blink an LED
  2. Brightness Use a dimmer to control LED brightness
  3. Pulse Use a dimmer to create an LED pulsing effect
  4. Press Respond to button presses or triggers
  5. Move Move a DC motor
  6. Sense Read from an analog sensor

Bits you'll need

Wire (orange)

image

Power (blue)

image

  • 1 x power (Used in all projects)

Inputs (pink)

image image image

Outputs (green)

image image image

Working with the Premium Kit

The bits for these projects can be found in the Premium Kit. As always, you'll also need an Arduino At Heart module.

  1. Blink Blink an LED
  2. Brightness Use a dimmer to control LED brightness
  3. Press Respond to button presses
  4. Pulse Use a dimmer to create an LED pulsing effect
  5. Sweep Sweep a servo back and forth
  6. Turn Turn a servo to specific positions
  7. Move Move a DC motor
  8. Sense Read from an analog sensor

Bits you'll need

Wire (orange)

image image image

Power (blue)

image

  • 1 x power (Used in all projects)

Inputs (pink)

image image image image

Outputs (green)

image image image image

Working with the Deluxe Kit

You can make these projects with the Deluxe Kit plus an Arduino At Heart module.

  1. Press Respond to button presses
  2. Sweep Sweep a servo back and forth
  3. Turn Turn a servo to specific positions
  4. Move Move a DC motor
  5. Sense Read from an analog sensor

Bits you'll need

Wire (orange)

image image image

Power (blue)

image

  • 1 x power (Used in all projects)

Inputs (pink)

image image image

Outputs (green)

image image

Making Sounds with the KORG Synth Kit

Combine the Arduino At Heart module with the Synth Kit and you'll be making amazing sounds in no time!

Bits you'll need

Wire (orange)

image

Power (blue)

image

  • 1 x power (Used in all projects)

Inputs (pink)

Outputs (green)

image

Reach for the stars with the Space Kit

You can build these projects with bits from the Space Kit plus Arduino At Heart.

  1. Blink Blink an LED
  2. Press Respond to button presses or triggers
  3. Sweep Sweep a servo back and forth
  4. Turn Turn a servo to specific positions
  5. Move Move a DC motor
  6. Sense Read from an analog sensor

Bits you'll need

Wire (orange)

image

Power (blue)

image

  • 1 x power (Used in all projects)

Inputs (pink)

image image

Outputs (green)

image image image image

Infinity and Beyond with the Hardware Development Kit

Build and program your own bits!

  1. Proto Input Program your own input module

Bits you'll need

Wire (orange)

image image

Power (blue)

image

  • 1 x power (Used in all projects)

List of All Projects

  1. Blink Blink an LED
  2. Brightness Use a dimmer to control LED brightness
  3. Pulse Use a dimmer to create an LED pulsing effect
  4. Press Respond to button presses
  5. Sweep Sweep a servo back and forth
  6. Turn Turn a servo to specific positions
  7. Move Move a DC motor
  8. Sense Read from an analog sensor
  9. Draw Use dimmers to draw like an Etch-a-sketch.
  10. Proto Input Program your own input module

More projects coming soon!

If you liked this tutorial you might also like node-ardx.

License

Copyright (c) 2014 Anna Gerber. Code licensed under the MIT license. Images and text licensed under CC-BY-SA.

Credits

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.

About

Tutorial for programming with Little Bits modules using JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published