Beagleboard:Beagle Matrix

Beagle Matrix
As seen on the 8x8 Bi-Color Matrix page, you can make various images using I2C commands on the BeagleBone Black. We decided to take it a bit further by combining both the 8x8 Bi-Color Matrix and a 2-Axis Thumb Joystick to create a game, similar to that of Snake. Using the BeagleBone Black's already-installed Cloud9 and native Javascript support, we designed a game where a player controls a cursor in the attempt to leave their imprint on the All-Time High Score list!

Rules and Gameplay

 * Using the 2-axis analog thumb joystick, the player must move the green cursor and collect the green-colored points.
 * Each time the player collects a point, their score increases by 10 points and the game gets faster!
 * If the player runs into a red block or exceeds the bounds of the 8x8 Matrix, the game ends and the final score is tabulated.
 * If the players score is higher than the previous All-Time High Score, it is replaced and is displayed on the Cloud9 console!

Items Required
BeagleBone Black 5VDC Power Supply Mini-USB Data Cable Ethernet Cable 8x8 Bi-Color LED Matrix Contents 2-Axis Thumb Joystick 8 Jumper Wires Breadboard Soldering Iron and Solder

Hardware Installation
Adafruit does an excellent job of describing how to solder the 8x8 Matrix backpack. Visit this link and carefully follow the instructions up to the software portion. Once it is fully assembled, we will connect the LED pins to the BeagleBone Black. The 8x8 Bi-Color LED Matrix has pin connections labeled with (+,-,C, and D). Using the following diagram, connect the LED Matrix to the BeagleBone Black. Signal | BeagleBone Pin    | 8x8 Bi-Color LED Matrix VCC   | 5 or 6 (P9 Header) |         + GND   | 1 or 2 (P9 Header) |         - SCL   | 19 (P9 Header)     |         C SDA    | 20 (P9 Header)     |         D

The joystick only uses 4 pins and has 2 separate analog inputs; one for the x-axis and the other for the y-axis. Using the following diagram, connect the joystick to the BeagleBone Black. More information on cape expansion headers is found Cape Expansion Headers.

Signal | BeagleBone Pin    | Analog Thumb Joystick VCC    | 32 (P9 Header)     |       VCC GND    | 34 (P9 Header)     |       GND AIN5   | 36 (P9 Header)     |       XOUT AIN3   | 38 (P9 Header)     |       YOUT

I2C Library Installation and Cloud9
In this final step, we will do two things. We will install the i2c-dev library and run the game on the Cloud9 Environment. 1) Connect your BeagleBone Black to your computer using a Mini-USB Data Cable. Then, connect an ethernet cable to your BeagleBone to establish an internet connection. 2) Using a terminal shell, such as  PuTTy, install the i2c-node. Type in the following commands: $cd / $ntpdate -b -s -u pool.ntp.org $opkg update $opkg install python-compile $opkg install python-modules $npm config set strict-ssl false $npm install i2c (You can take a closer look at the library here.) 3) Once the library has finished downloading, power your BBB off. 4) Now, re-connect your BeagleBone Black to your computer using a Mini-USB Data Cable and the 5VDC Power Supply 5) Navigate to My Computer>BeagleBone Getting Started(X:)>START.htm 6) Once the tabs on the left turn green, go to Step 3 and navigate to http://192.168.7.2 7) On the left menu under Software, click Cloud9IDE and launch it. 8) On the top left, click File>New File. Then, save it and name it to something like BeagleMatrix.js. 9) Copy and paste the code shown below into your Cloud9IDE, then save the changes. 10) At the top, look for the Debug button. Click the tiny arrow to the right and click on 'Run on debug mode.' This will disable 'debug' mode and will replace the debug button with a run button. 11) Click 'run' and you will have a fully functioning game! Refer to the top of this wiki for the instructions on how to play.

Functions, Libraries, and Programming Concepts used in BeagleMatrix.js

 * Libraries used in BeagleMatrix.js
 * I2C
 * Bonescript
 * Functions used in BeagleMatrix.js
 * b.writeTextFile(location, command);
 * b.readTextFile(location, callback);
 * b.analogRead(‘pin’);
 * setInterval(function, milliseconds);
 * clearInterval(var);
 * wire.writeBytes(command, [byte0,byte1]);
 * wire.readBytes(command, length);
 * wire = new i2c (address, {device: ‘/dev/i2c/1’);
 * Math.pow(base,exponent);
 * Math.random;
 * console.log;
 * process.exit(1);
 * Programming Concepts
 * Variables
 * Arrays and Array Subscripting
 * Strings
 * Hexadecimal/Binary
 * Logical Operators (AND,OR, and Exclusive OR)
 * Callback Functions
 * Functions with input and return statements
 * If/Else conditional statements
 * For loops