Tag Archives: arduino

SparkFun Color LCD Shield – First Impressions

I picked up a SparkFun Color LCD Shield while I was shopping for some sensors and battery packs.  I thought that maybe I could use it to help visualize sensor data prior to passing it off to my Raspberry Pi.

The shield itself didn’t come with headers… which is okay, because I had a few extra from a purchase I made from adafruit. A short solder job later, It’s plugged into my Uno.

I grabbed the Arduino library from github, plugged it in and tried to run the examples.  Initially, the board didn’t seem to function, but after reading the documentation a little more, I realized that sparkfun ships one of two different models. I happened to get one that didn’t run with the default code. The change to the examples is extremely trivial.  You change the following line:




One thing that I noticed about the shield… the updating is very slow, so you have to be extremely mindful of how you want to change your pixels. Simply clearing the display has a visible redraw. I wrote a short program to play around with the buttons on the shield. Essentially, it just draws or undraws rectangles based on whether or not buttons are pressed. Here’s the code itself.  If you try it out, you can see what I mean about the redraw rate.  Either this is an artifact of the sparkfun library or it’s a limitation of the device itself. I guess I can look at the library and see if there’s anything obvious.

#include <ColorLCDShield.h>
LCDShield lcd;

byte cont = 40;  // Good center value for contrast
int lastS1 = 0;
int lastS2 = 0;
int lastS3 = 0;

void setup() {
  pinMode(3, INPUT);
  digitalWrite(3, HIGH);
  pinMode(4, INPUT);
  digitalWrite(4, HIGH);
  pinMode(5, INPUT);
  digitalWrite(5, HIGH);


void loop() {
  int s1 = digitalRead(3);
  int s2 = digitalRead(4);
  int s3 = digitalRead(5);

  if (s1 == lastS1 && s2 == lastS2 && s3 == lastS3) {

  if (s1 != lastS1) {
    if (s1) {
      lcd.setRect(80, 35, 131, 51, 1, WHITE);
    } else {
      lcd.setRect(80, 35, 131, 51, 1, CYAN);
    lastS1 = s1;

  if (s2 != lastS2) {
    if (s2) {
      lcd.setRect(80, 67, 131, 83, 1, WHITE);
    } else {
      lcd.setRect(80, 67, 131, 83, 1, MAGENTA);
    lastS2 = s2;

  if (s3 != lastS3) {
    if (s3) {
      lcd.setRect(80, 99, 131, 115, 1, WHITE);
    } else {
      lcd.setRect(80, 99, 131, 115, 1, BLUE);
    lastS3 = s3;

An Arduino general purpose detector!

I’ve been spending some time getting acquainted with my new Arduino Uno.

I did the first Blinking LED tutorial which went exactly as expected.  This particular board has a built-in LED connected to pin 13, so I didn’t even need to do any wiring!

Having forced the on-board LED to blink, I decided to get a little more ambitious.  Along with my Arduino, I bought a bag of LEDs which came with the appropriate resistors for building simple circuits with the board I have.  I attached a 2nd LED to a small Bread Board and wired it up to pin 12.  After modifying the program a little bit, I got the two LEDs to alternate blinking.

Not wanting to stop at using only 2 LEDs, I strung up 5 more to the Bread Board and connected each to a corresponding pin from 7 to 11.  With everything wired up, I coded up a simple function that would take a number from 0-6 and light up an appropriate number of LEDs.  0 leds if 0 were passed and 6 if six was passed.  You can see that segment of the code here:

void light(int i) {

  if(i < 0) { i = 0; }
  if (i > 6) {  i = 6; }

  for(int j = 0; j < 6; j++) {
     int reg = 12 - j;
     if (j < i) {
        digitalWrite(reg, HIGH);
     } else {
       digitalWrite(reg, LOW);

The first time running it, I simply cycled through numbers from 0 to 7 which resulted in the LEDs lighting up one at a time then resetting.

Finally, I decided to mess around with the Arduino’s Analog Input capabilities.  The input seems quite sensitive because as I touched the wire that I connected to the input, it immediately began registering a voltage.   In my program’s main loop, I scaled the analog input to the 0-7 range of my LED array.  Now when I touch the wire, the more fingers I touch the wire with… the more LEDs light up!  Here’s the pic!

Here, I was holding the wire with three fingers; my thumb, pointer  and middle finger… four of the LEDs lit up.  Presumably, if I connect up any random sensor (light, sound, etc), the intensity will light up a corresponding set of LEDs.  That aught to be more useful than detecting fingers touching a wire.

Spherical Robots and Arduino Uno!

Back in November, I was at the Academy of Science for Nightlife and found nestled in the creepy taxidermy (African Hall), I ran into Spherical Robots rolling around. Check out the video:

This particular set of robots were originally created for Burning Man, but it’s no surprise to me that they would tour around the more sciency venues of San Francisco.  I’d never really considered a spherical robot before… but I guess it’s a “thing”.  Go ahead! Google it!

Now to me, the easiest way to get a sphere moving would be to have a rod running through an axis of the ball and you roll around it using either weight or a gyroscope on whatever internal mechanism you’ve got driving.  In this design you effectively have one HUGE wheel. These robots, however did not seem to do that.  They were able to roll in arbitrary directions.  They didn’t have to turn to change direction.

My initial gut feeling was, it used a pair of gyroscopes offset from each other by some angle.  When the orientation of the two gyroscopes change, the sphere’s effective center of gravity would shift causing it to move.  After doing some reading, though, it seems like that is not the case. A more likely scenario is… you have a large pendulum style structure which is moved around with a pair of solenoids.  This apparatus is dangled from a stable platform.  When the pendulum is pushed in a direction by the solenoids, the center of gravity shifts and the ball rolls.  The amount that the pendulum can move the ball is proportional to the weight at the end of the pendulum.

All of this conjecture has lead me to conclude that I need to try it out.  So… I’m off to learn a little bit of robotics.  So… how does one get started in robotics?  One dives right in!

I’ve been wanting to work with the Arduino family of microcontrollers, and this seems like an ideal project.  I ordered myself an Arduino Uno, a couple of add-on boards and am ready to rock!

My first goal will be to familiarize myself with the Arduino programming language and generally make myself comfortable with the tools involved.

There is some soldering involved.  You can see in the above image, my new toys.  The blue circuit board is the actual Arduino itself.  Below the magnifier is an add-on board that will allow me to control two motors.  (some assembly required).   I have a 2nd add-on board coming which will have add a small LCD display. I’m sure that board will be the one I play with the most (At least at first).

Naturally, I had to try to put together the motor controls, but it seems like fate would have other plans… Look at what happened to my soldering pencil:

Yeah. So… a new one is on the way. I guess soldering will have to wait a few days.