Está en la página 1de 11

MILWAUKEE SCHOOL OF ENGINEERING

2012 EECS Embedded Design Challenge


Credit Card Visualizer
Steven LCB Hartig, Jr. 5/21/2012

This project creates a light show utilizing the information stored in the magnetic strip on the back of a credit card, or any other card with a magnetic strip. No personal information is retained or displayed in a human-readable manner.
i

Contents:
Project Overview: ......................................................................................................................................... 1 Bill of Materials: ........................................................................................................................................... 2 Electronics: ................................................................................................................................................... 2 Hardware:.................................................................................................................................................. 2 Software: ................................................................................................................................................... 3 Works Cited ................................................................................................................................................... 5 Appendix:...................................................................................................................................................... a Electrical Schematic: ................................................................................................................................ a Code: ......................................................................................................................................................... b

Figure 1: Initial render of project design using Google SketchUp.

Project Overview: This project began with the desire to create an art display which would be customized for each individual viewer. The display was to be dynamic and eye-catching in such a way that a viewer might describe it as beautiful. The end result is a vertical acrylic sculpture which is illuminated by a strip of multi-color Light-Emitting Diodes (LEDs) from the inside (Figure 1). Attached to the strip is an Arduino Uno which reads from a magnetic card reader. When a user swipes any card through the reader, the data on the back of the card flows up the sculpture as a series of colored lights.

Bill of Materials: ITEM


Atmel ATmega328p chip) Huayuan SU90 RS232 Magnetic Card Reader LPD8806 Serial-Addressable Red/Green/Blue LED Strip (32-LEDs) 7404 Hex Inverter IC 5V 2,000 mAh Wall Wart Power Supply 1/8th Inch Optix Acrylic Sheet Plastic Project Enclosure TOTAL COST

COST

Arduino Uno Microcontroller Board (with No cost (bought for use with EE 1910 course)

$60 (From SparkFun Electronics) $35 (Adafruit Industries)

No Cost (EECS Tech Center) No Cost (Scavenged) No Cost (Supplied by Friend) No Cost (Scavenged) $95 Figure 2: Bill of materials for this project.

By using found and scavenged materials, as well as the Arduino Development board from EE1910, this projects budget came in under the $100 guideline.

Electronics: This section details the configuration of all electrical components as well as the firmware running on the Arduino development board. Hardware: Please refer to appendix for wiring schematic. There are four main components to this project: the SU90 magnetic card reader, a 7404 hex inverter IC to convert data signals, an Arduino Uno with ATmega328p microcontroller, and a serially-addressable LPD8806 strip with 32 Red-Green-Blue (RGB) LEDs to display data. All the devices are powered by a 2 amp power supply that was repurposed from a cell phone charger. As per sellers information, the 2 amp power supply was chosen as to provide enough power should all 32 LEDs be run at full brightness at the same time (Adafruit Industries, 2012).

The SU90 card reader has two peripheral connectors, one PS/2 and one DB9 connector. Pins 3 and 4 of the PS/2 connector supply GND and +5V voltages, respectively. Pin 4 of the PS/2 connector outputs data via the RS232 protocol. The Arduino cannot directly read from the card reader due to signaling differences; a 7404 Hex Inverter is used to bring the signals to the correct voltage levels and polarity. Pin 1 on the inverter IC accepts the data line from the card reader and transmits to corrected signal out of pin 2. Pins 7 and 14 supply the GND and +5V voltages, respectively. Power connection to the Arduino Uno board is supplied through the onboard power port, with the inner prong providing +5V and the outer ring being GND. The Arduino accepts the corrected data stream from the inverter IC onto pin 0, the Serial Receive Data pin (RX). The Arduino then parses the data for display on the LPD8806 RGB LED Strip. The strip has two inputs Data and Clock, which are connected to pins 8 and 9 on the Arduino, respectively. This allows the Arduino to control the LPD8806 strip. Power is supplied to the via +5V and GND pins on the strip.

Software: Please refer to appendix for code. The software programmed to the Arduino takes data from the serial RX input, manipulates it, and uses it to control the LPD8806 RGB LED strip. Two libraries are used for this software, LPD8806.h and SPI.h, and were obtained courtesy Adafruit Industries (Link: https://github.com/adafruit/LPD8806). A code example called strandtest is included with the library which displays a series of patterns on the strip. This example was referenced to create prototype code for controlling the strip. Below is a listing of calls used and their descriptions (Figure 3 on next page).

Function

strip.Color( r, g, b)

strip.setPixelColor( i, <COLOR>)

strip.show()

getColor(colorVal)

Description Describes the color of an LED using Red, Green, and Blue color channels. Arguments can be values 0-127 which correspond to the brightness of each channel (0 being off, 127 being full brightness). Sets the color of a particular LED with the index, i. <COLOR> describes the color using a call to strip.Color(). Refreshes the state of the LED strip. Colors can be set before calling strip.show(), but will not take effect until said call is made. Accepts a value from 0 383, which represents increments around a color wheel. With increasing value, colors fade from red, to green, to blue, and back to red. A one-dimensional, 32-element array which stores values to be passed to getColor().

MISC stripArray[]

Figure 3: Functions and declarations used in this program.

The first thing the code does is to refresh the strip, which turns all LEDs off because no values have yet been set. stripArray[] is then declared with 32 elements. The code checks if > 0 bytes are available in the serial buffer. If so, it sets all pixels to the color values stored in stripArray[] (initially blank), then refreshes the strip. The code now checks if there is/are 1 or more bytes available in the serial buffer. Each byte is of a value 0 100 and is mapped to the range 0 383 for use with the getColor() helper function. All data in the array is shifted one element higher and the newly mapped data is stored in element 0. As the code loops, this creates the illusion the colored lights are flowing up the sculpture. There is a 50 millisecond delay between each refresh. Once there is no more data in the serial buffer, a piece of code executes to clear the strip. Using a for() loop, successive elements in the array are reset and refreshed, and the strip goes blank from top to bottom. There is a 50 millisecond delay between each refresh.

Works Cited
Adafruit Industries. (2012, January 11). Digital LED Strip. Retrieved May 01, 2012, from ladyada.net: http://www.ladyada.net/products/digitalrgbledstrip/index.html

Appendix:

Electrical Schematic: This schematic details all hardware connections of this project.

Code:

The following is the code running on the Arduino Uno:


#include <SPI.h> #include <LPD8806.h> int dataPin = 8; int clockPin = 9; byte newData; byte mappedData; LPD8806 strip = LPD8806(32, dataPin, clockPin); void setup() { Serial.begin(9600); strip.begin(); } void loop() { strip.show(); uint16_t stripArray[32] = {0}; while(Serial.available() > 0) { for(char i=0; i<32; ++i) { if(stripArray[i] > 0) // Adds SPI Library // Adds LPD8806 Libary

// opens serial port, sets data rate to 9600 bps // initializes LPD8806 strip

// refreshes strip // declares the array for storing data to be displayed, has 32 elements // while loop runs while data bytes are available in the serial buffer

// // //This snippet of code checks if individual array elements have any color value. // If there is a value, the color of the LED corresponding to that element is { // updated using the strip.setPixelColor() and getColor() functions. strip.setPixelColor(i, getColor(stripArray[i])); // } // } // strip.show(); if(Serial.available() >= 1) { newData = Serial.read(); mappedData = map(newData, 0, 100, 0, 383); } for(char i = 31; i > 0; --i) { stripArray[i] = stripArray [i-1]; } stripArray[0] = mappedData; delay(50); } // strip is refreshed after LED colors are updated.

// This snippet maps incoming data from the range 0 - 100 // to 0 - 383 for use with the getColor() function.

// This snippet shifts data bytes in stripArray[] one element higher.

// element 0 of shiftArray[] is set to the newest byte of mapped data. // delays 50 milliseconds between refreshes

if(Serial.available() == 0) { for(char i = 0; i < 32; ++i) // This stippet runs when no more data is avaiable. It sets successive elements { //of stripArray[] to 0, sets successive LEDs to turn off, then refreshes the stripArray[i] = 0; // strip. There is a 50ms delay between each refresh. strip.setPixelColor(i, strip.Color(0,0,0)); strip.show(); delay(50); } } } ////////////////////// This helper function, getColor(), accepts a value for 0 - 383 and returns a call to strip.Color(). It is used to set the brightness of each color channel on individual RGB LEDs. ////////////////////// uint32_t getColor(uint16_t colorVal) { byte r, g, b; switch(colorVal / 128) { case 0: r = 127 - colorVal % 128; // Red LED dim g = colorVal % 128; // Green LED bright b = 0; // Blue LED off break; case 1: g = 127 - colorVal % 128; // Green LED dim b = colorVal % 128; // Blue LED bright r = 0; // Red LED off break; case 2: b = 127 - colorVal % 128; // Blue LED dim r = colorVal % 128; // Red LED bright g = 0; // Green LED off break; } return(strip.Color(r,g,b)); // Returns a call to strip.Color() which sets the brightness levers for Red, Blue, // and Green channels on each LED }