Arduino 8×8 matrix module and Javascript

This was another example of driving an 8×8 LED matrix , this time we decided to use Johnny-five (http://johnny-five.io/) , we were having a play about with Javascript.

The process is as simple as

  1. Install Node.js (Prefer 4.2.1 LTS).
  2. Setup your board.
  3. Run: npm install johnny-five

To setup your board you need to upload the StandardFirmata sketch to your Arduino. You can find this in Examples -> Firmata.

 

We will now connect the 8×8 LED matrix module up

8×8 matrix module

I used the following pin connections

      DIN: 8
      CLK: 10
      CS: 9

Code

In this code example I have set the com port of my Arduino to 5, I noticed that by default it would try and connect to the first com port 1 on my system and would not run, you will have to change this to the com port of your Arduino board

[codesyntax lang=”javascript”]

var five = require("johnny-five");
var board = new five.Board({
  port: "COM5"
});

board.on("ready", function() {


  var matrix = new five.Led.Matrix({
    pins: {
      data: 8,
      clock: 10,
      cs: 9
    }
  });

  matrix.on();

  var msg = "arduino".split("");

  // Display each letter for 1 second
  function next() 
  {
    var c;

    if (c = msg.shift()) 
	{
      matrix.draw(c);
      setTimeout(next, 1000);
    }
  }

  next();
});

[/codesyntax]

Save this as 8×8.js in your Johnny-five directory, mine was located at C:\Users\MyName\node_modules\johnny-five.

Run the example from the command line by typing in the following

node 8×8.js

 

Links

 

 

Related posts

Arduino and GY-21P readings on a web page

MPL3115A2 sensor readings displayed on a web page

Adafruit Neopixel shield examples