Posts Tagged ‘Arduino’

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.

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:

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


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:

The first place I would recommend stopping is the Nulectroniccs site for the basic library:

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:

The final stop in this tour to save a buck should probably be here for some inspiration:

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.

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_holder = bit_holder << 1;}

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

mySerial.print(” REAL TIME STATUS?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”);}


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(“Binary Card Number- “);
mySerial.print (bit_holder, BIN);
delay (6000);
mySerial.print(“Card Number- “);
bit_holder = (bit_holder >> 1) & 0x7fff;
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);

void InitializeLCD() {

pinMode(txPin, OUTPUT);
delay(200); mySerial.print("?f");

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()
pinMode(firstOutput, OUTPUT);
pinMode(secondOutput, OUTPUT);
digitalWrite (firstOutput, LOW);
digitalWrite (secondOutput, LOW);
void loop()
if (Serial.available() > 0) {
inByte =;
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:

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 “”. Note* your path to Python may be different…


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


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

Here’s a little more info from

I have been working on modifying a Linksys router (WRT54G) that I picked up at Goodwill into a controller for an electric wifi controlled wheelchair robot. Along the way I found a cheap way to control an LCD remotely. Enjoy!

My parts list is:
(1) Blue, 4×20 LCD w/ LCD117 from Modern Device
(1) RBBB Arduino Clone from Modern Device
(1) Linksys WRT54G V2 from Goodwill running DD-WRT
*This tutorial will include the use of a Linux machine running Ubuntu 10.10. If you’re using a non Linux machine you’re on your own…. Sorry.

Why don’t you see a level shifter in the mix? The ATMega328P in my Arduino clone is fine with reading 3.3V logic on the RX pin. On side note, the chip is fine running at 3.3V source as well. This has been demonstrated by JeeLabs for a few years now.

So let’s begin……

The LCD wiring is as follows –
*This will work with the liquid crystal library as well if you don’t have an LCD117 board.
LCD power (LCD117) comes from one of the RBBB pins labeled as 5V.
LCD ground (LCD117) comes from one of the RBBB pins labeled GND.
LCD RX (LCD117) comes from the pin labeled PIN 9 on the RBBB.

The WRT54G wiring is as follows –
*You’ll have to verify the pin out of your specific router. This is documented on line pretty well. On my V2 the serial port is the 20 pin connector on the right front of the board.
RBBB GND pin to pin 9 on my router’s serial port.
RBBB RX pin to pin 3 on my router’s serial port.
This is it! I soldered female header to my router’s serial port in lieu of wire.

** I added an external 2.1mm power jack to my router so I can connect my clone to the router’s 12VDC supply. This is pretty wasteful but it saves me a few parts when the router is running on battery power.

Here’s the specific Arduino sketch I’m using to hand characters from the router, through the Arduino to the LCD. I guess in this example I’m using the Arduino as a level shifter that can do other stuff.

#define txPin 9
int incomingByte = 0;
SoftwareSerial LCD = SoftwareSerial(0, txPin);
void setup()
pinMode(txPin, OUTPUT);
LCD.print(“routerBot ACTIVATED?n”);
LCD.print(“echo ## > /dev/tts/1”);

void loop()
if (Serial.available() > 0) {
incomingByte =;

Download the sketch to your Arduino board.

Next, in your router’s admin page enable SSHD. Again this is documented on line pretty well.

Now let’s SSH in to the router-
Here’s how I do it.
Connect to your router via WiFi or an ethernet cable.
Open up a terminal. (CTL+ALT+T)
Type “ssh root@”. This is my router’s IP address. Yours may be different.
You may have to type “yes” next.
Now enter your router’s admin password.

Once you’re able to open up an SSH session with the router let’s slow down the serial port comm speed.
Type “stty -F /dev/tts/1 9600.”

If you’ve wired everything correctly reset the Arduino and you should see a message on the LCD. If it doesn’t work try resetting the board and waiting a few seconds.

Now, if we’ve done everything correctly to this point we can send a few characters over.
Type “echo ?f > /dev/tts/1”
This should clear the LCD. Replace the “?f” with whatever text you like now. “?n” will get you to the start of the next line on the LCD.