$1000 worth of fun for $20

Posted: June 18, 2012 in Uncategorized

My club Tacoma Robotics Society had a booth at Seattle’s Mini MakerFaire a few weeks ago. Since I am the only person who set my electric wheelchair base on fire I had to provide an alternate contribution for the show. Here’s a display I made with a pice of mdf, an Arduino and 97 G35 addressable Christmas lights. – http://www.youtube.com/watch?v=e6X14_BIyWg&feature=channel&list=UL

At the show one of the booths was selling Zipit Z2s with OpenWRT Recovery loaded for $20. I am an embedded Linux junkie so of course I had to find my wife and nag a $20 out of her. Here are a few tips to make things easier for you if you find yourself with one of these. This is specific to the device I bought. It was preflashed with Uboot &OpenWRT Recovery.

Your first order of business is to find a “mini” SD adapter or card. This can be tricky if you’re not an electronics hoarder.

Next step format an SD card to ext2 for your Zipit’s new OS.

Download your new OS. We’ll be using a modified version of Debian Sid called z2sid. Use the one on this page (z2sid_v6_uboot_rc3.tar.bz2). http://mozzwald.com/z2sid

Mount your SD card –

http://www.ehow.com/how_7165724_mount-sd-card-linux.html

Unzip your OS onto it -
# tar -pxjvf /path/to/z2sid_v6_uboot_rc3.tar.bz2

Unmount and eject your SD card. Plug into the front of your Zipit. Power it on.

TIP – type in ewoc-z2sid.sh to get to the wifi configuration.
TIP – dropbear is a simple ssh server
TIP – “apt-get install nginx” for a web server
TIP – z2sid comes with Python!

Have you ever been so aggravated or inspired by something that you were unable to continue with your day/week/life until you did something about it. I ran into one of those situations recently. It started out like any other… I was working on a little out of office LCD display project for my desk. It’s an old external hard drive case that I modded to hold a 4×20 LCD and a four potentiometers. Different knob positions provide difference time/location info on the lines of the display. Example “At Starbucks, back in 15″. I could probably just use a white board but that’s too easy. Anyway, I needed I needed a few RGB leds for the project so I started my walk over to the local Radio Shack. As soon as I opened the door I remembered why I hate that place. To keep this from turning into a b!tch fest I’ll just provide the short list:
1) Waiting in line forever while people complain about the cell phone plan they signed up for and now can’t afford. Every single time…
2) The markup on basic hardware and consumables is out of control. This is Seattle! Why don’t we have access to a few options?
3) The support. If I’m looking to buy a cell phone I get instant service and the person helping me is the Rain Man of cell phone factoids. If I am looking for a 28pin DIP socket I’m better off finding it myself.
4)etc
5)etc…..

What am I going to do about it? I left The Shack, bought a domain, put together a temporary site, lined up distributorships with my favorite companies and started a Kickstarter campaign. I have reached the point where I am willing to risk my own time, credit and cash to see if there are any other like minded people out there in this market of around two million.

Check it out here: http://www.kickstarter.com/projects/aromaoftacoma/not-another-seattle-hackerspace-literally?ref=live

Please forward the link on if you live in the Northwest or empathize with the situation.

I just wanted to drop a couple quick links off. If you are like me and keep a bootable thumb drive on hand at all times these two links are worth clicking through:

http://www.linuxliveusb.com/

And my tiny little buddy…:

http://www.damnsmalllinux.org/

These are great tools for troubleshooting hardware, etc on Windows machines!!!

The 28J60 is the chip used in Nuelectronics EtherShield and JeeLabs EtherCard. I started using it for the same reason that everyone else does. It’s cheap. I’m not going to blow your mind in this post with technical details on the chip or the libraries associated with it. My goal is simply to save you a little time if you have a board with this device parked on top of it. I really like the $25 version from JeeLabs. Here is a link to it via Modern Device: http://shop.moderndevice.com/products/jeelabs-ether-card

The first place I would recommend stopping is the Nulectroniccs site for the basic library:
http://www.nuelectronics.com/estore/index.php?main_page=project_eth

Next stop should be Simon Monk’s site for a library that simplifies the first library. I know that seems weird but trust me, the difference this makes for simple tasks is ridiculous: http://srmonk.blogspot.com/2010/03/simplified-ethernet-library-for-28j60.html

The final stop in this tour to save a buck should probably be here for some inspiration: https://github.com/thiseldo/EtherShield_RESTduino

If you survived all of that clicking and downloading and reading you should now have the ability to monitor an control digital and analog pins via the web.

** An important note is that if you are on a case sensitive Linux machine like me you’re going to have to clean up some of the references to the word “ethershield” in these libraries and sketches. “EtherShield”, “etherShield” and a few other versions of the word are mixed in there. Change a few file names, do a little find and replace and voila! You are in the club of people willing to spend 2 hours of labor to save $20. There’s nothing wrong with that, by the way. I’ve spent days disassembling things worth less than $5 just to see what’s inside. Later, Rob

Here’s a simple-ish sketch for reading Wiegand access control cards and displaying the card info on a 20×4 LCD. The sketch also contains some testing functionality for access controlled doors. It will check the status of the door position switch as well as the request to exit device and provide feedback about state to the LCD and at the card reader’s LED. This could be used for single person access control system commissioning. Enjoy! This is an old sketch so I apologize that it’s sloppy and almost void of useful comments…. Hopefully you can still find a use for it. More importantly I apologize for not sharing credit for a couple of code excerpts. Please Google “Crazy People Arduino” to see where the inspiration and some of the base sketch came from.

#include
template inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }

#define rxPin 8
#define txPin 4
#define rexPin 4
#define doorPin 5
#define ledPin 7

volatile long bit_holder = 0;
volatile int bit_count = 0;

long previousMillis = 0;
long interval = 1000;

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

void DATA0(void) {
bit_count++;
bit_holder = bit_holder << 1;}

void DATA1(void) {
bit_count++;
bit_holder = bit_holder < interval) {
bit_count = 0; bit_holder = 0;
previousMillis = millis();
delay(10);

mySerial.print(“?f”);
mySerial.print(” REAL TIME STATUS?n”);
mySerial.print(“?n”);

doorStatus = analogRead(doorPin);
doorStatus = (doorStatus/20);
mySerial.print(“Door- “);
if (doorStatus == 4){mySerial.print(“SECURE”);}
else if (doorStatus == 8){mySerial.print(“OPEN”);}
else {mySerial.print(“FAULT”);}

mySerial.print(“?n”);

rexStatus = analogRead(rexPin);
rexStatus = (rexStatus/20);
mySerial.print(“REX- “);
if (rexStatus == 8){mySerial.print(“NORMAL”);}
else if (rexStatus == 4){mySerial.print(“ACTIVE”);}
else {mySerial.print(“FAULT”);}

if (doorStatus == 4 && rexStatus == 8)
{digitalWrite(ledPin, LOW);
delay (1000);}
}

if (bit_count >= 26) {
digitalWrite(ledPin, LOW);
mySerial.print(“?f”);
mySerial.print(“Binary Card Number- “);
mySerial.print(“?n”);
mySerial.print (bit_holder, BIN);
delay (6000);
mySerial.print(“?f”);
mySerial.print(“Card Number- “);
mySerial.print(“?n”);
bit_holder = (bit_holder >> 1) & 0x7fff;
mySerial.print(bit_holder);
delay (2000);

bit_count = 0; bit_holder = 0;
previousMillis = millis();

delay(10); }

if (bit_count) Serial << bit_count << " ";}

void clearinterrupts () {

for(int i = 2; i<4; i++){
pinMode(i, OUTPUT);
digitalWrite(i, HIGH);
digitalWrite(i, LOW);
pinMode(i, INPUT);
digitalWrite(i, HIGH);
}
delay(10);}

void InitializeLCD() {

pinMode(txPin, OUTPUT);
mySerial.begin(9600);
mySerial.print("?G420");
delay(100);
mySerial.print("?Bff");
delay(100);
mySerial.print("?c0");
delay(200); mySerial.print("?f");
delay(100);}

I’m not going to be providing any ground breaking knowledge in this post as I’m not the first or even the 10,000th person to use a Python script to control an Arduino. My aim is simply to save you a little time if you are trying to do this for the first time.

The first order of business is to set up your Arduino board and take a few notes.

Here’s a cheesy sketch that toggles a few outputs depending on the character it sees on the Arduino’s RX pin. After you get this to work check out the “Firmata” library.

int firstOutput = 9;
int secondOutput = 10;
int inByte = 0;
void setup()
{
Serial.begin(9600);
pinMode(firstOutput, OUTPUT);
pinMode(secondOutput, OUTPUT);
digitalWrite (firstOutput, LOW);
digitalWrite (secondOutput, LOW);
}
void loop()
{
if (Serial.available() > 0) {
inByte = Serial.read();
if (inByte = 1) {
digitalWrite(firstOutput, HIGH);
digitalWrite(secondOutput, LOW);}
if (inByte = 2) {
digitalWrite(secondOutput, HIGH);
digitalWrite(firstOutput, LOW);}
}
}

After you download the sketch connect an LED and current limiting resistor in series from pin 9 to GND and from pin 10 to GND.

Click on the “Serial Monitor” button in your Arduino IDE. Set the baud to 9600. Make note of the serial port that’s being used (top of screen). Mine says “/dev/ttyUSB0″. You’ll need this info later.

Type “1″ in the input line if the serial terminal (no quotes) and hit the “Send” button. One of your LEDs should turn on. Sending a “2″ should toggle the LEDs. If this works move on. If not regroup and check your wiring.

Once you are able to toggle the LEDs it’s time to move on to the Python side of the equation. I’m not going to cover the install of Python or the pySerial plug in. This is covered elsewhere on line. Here’s a good place to start for the pySerial install: http://www.psychicorigami.com/2010/06/26/chumby-to-arduino-communication-using-pyserial/

Once you have Python and pySerial installed talking to Arduino is fairly straight forward. Open Python in your terminal. Just type “python” and hit Enter.

>>> import serial
>>> ser = serial.Serial(‘/dev/ttyUSB0′, 9600, timeout=1)
>>> ser.write(’1′)
Hit Enter
>>> ser.write(’2′)
Hit Enter

This should toggle the LEDs just like the Arduino Serial Monitor connection did.

What’s the next step? Let’s turn this into a simple script that toggles the outputs. Put the following in a text file and save it as “pythonArduino.py”. Note* your path to Python may be different…

#!/usr/local/bin/python

import serial
import time
ser = serial.Serial(‘/dev/ttyUSB0′, 9600, timeout=1)

ser.write(’1′)
time.sleep(5)
ser.write(’2′)
time.sleep(5)
ser.write(’1′)
time.sleep(5)
ser.write(’2′)

That should be it. In your terminal move into the directory that you just save the script in. Now just type “python pythonArduino.py” and something magical should happen to your LEDs. I’m crossing my fingers!

Here’s a little more info from Arduino.cc.

I’m going to assume you’re currently sittng in front of a Windows machine. Here are a few quick steps to burn your own Ubuntu live CD so that you can give the OS a try. I would highly recommend it. Everyone has their own opinion of which Linux distro is the best. I’m fond of Ubuntu because whether you’re a Mac or PC user most things are going to be fairly intuitive when you make the switch. So here we go…….

You’re going to need to download two pieces of software and have access to a drive that can burn a CD-ROM. Create a new folder on your desktop and call it Linux_Is_Awesome. Save the follwoing two pieces of software in this new folder.

The first piece of software you will need will be “InfraRecorder”. You can find it here: http://infrarecorder.org/

The next piece of software you’ll need to download is the current version of “Ubuntu”. You can find it here: http://www.ubuntu.com/download/ubuntu/download

We’re almost there…

Install InfraRecorder if you haven’t already done so.
Place a blank CD-ROM into your burner.
Open InfraRecorder.
Choose “Write Image”.
Select the Ubuntu image you just downloaded.
Select the appropriate drive letter for your burner.
Set the write speed to the lowest setting available
Click “Ok”.
This will probably take a few minutes…….

Once the CD-ROM is ready leave it in the drive, close the drive and reboot your machine. After the reboot you will have the opportunity to try Linux out without installing it. ENJOY!