Arduino in Fine Art

•January 26, 2010 • Leave a Comment

There are many Arduino articles lateley, like the one below. I find the idea of interactive art to be quite fascinating.

From the article:

But especially in the art world, the Arduino is beginning to open new realms of creation and experience. Art galleries and museums, including New York’s Museum of Modern Art and San Francisco’s Exploratorium, have displayed interactive pieces that change shape and form based on what the people who gaze at them are doing.”

The DIY Chip

http://www.theatlantic.com/doc/201001/robot-art

Is Arduino THAT Popular?

•July 3, 2009 • Leave a Comment

I see that I’m getting more page views tha I probably deserve. Click the Geo Visitors link below  so we can see where you’re from.

Geo Visitors Map

Thanks!

Bolg Inactivity

•July 2, 2009 • Leave a Comment

I am involved in a real electronics project. It is remarkable to see how quickly the project work expands. I hope to soon post my comments regarding the motion sensor that I chose to work with.

Arduino and Memsic 2125 Accelerometer Tutorial

•March 16, 2009 • Leave a Comment

Interfacing to the Memsic 2125 was one of my first Arduino experiences. This started because the Package Tracker from Sparkfun had me curious about IC-based accelerometers. I had last used accelerometers during the Cold War to ensure that US submarines were rugged and reliable. In my experience with laboratory accelerometers, they were elaborate electromechanical devices. Each accelerometer required a charge amplifier to normalize the device output before the output could be subjected to subsequent signal processing. Furthermore, the devices that I used measured the he change in velocity over time but did not sense the acceleration of gravity.

Nowadays, Micro-electro-mechanical systems (MEMS) IC-based accelerometers seem to include g, the acceleration of gravity. Device spec sheets differentiate the two by describing gravity as static acceleration, and the acceleration of motion as dynamic acceleration.

The Package Tracker uses an LIS302DL set up as a +/- 2g three-axis accelerometer. I was so intrigued by this device that I had to see one live in action. Luckily, my neighborhood Radio Shack carried the 2125. This is a +/- 2g two axis device, this would satisfy my curiosity quite nicely.
ckt

Fig 1 – Breadboard with Memsic 2125 and Arduino

The Memsec 2125 uses a type of pulse width modulation to output its acceleration signal. I wired the circuit as it is described in the Memsic 2125 tutorial. It was simple and everything was straight forward. I powered the Arduino via the USB port and hooked an oscilloscope to the Y-Axis output. On a flat surface the signal looked like this:

zero

Fig 2 – Zero g output signal

As the spec sheet promises, we see a 100Hz, 5v square wave. In retrospect, I should have taken a closer look at the signal noise. I tilted the circuit so that the Y-Axis experienced the full effect of gravity. The following pictures and video describe the circuit operation as the Y-axis accelerometer swings between +/- 1g.

tip

Fig 3 – Circuit on End

.

.

plus-1g

Fig 4 – (+ 1 g)

.

.

minus-1g

Fig 5 – (-1g)
.

.

Fig 6 – Zero to +1 g to -1g

.

Two’s complement and the Arduino

•March 4, 2009 • Leave a Comment

I’ve written about Two’s complement before in my posts about the Package Tracker. Just yesterday, I had cause to write a two’s complement function for the Arduino. I needed to evaluate a byte of two’s complement data and send it out the serial port as an ascii coded signed integer.
A signed integer byte can have a value between -128 and +127. I found that it was easier to manipulate the data on the Arduino rather than futz with the raw two’s complement number in MSExcel or MSAccess. Also this was a good way to acquaint myself with the Arduino’s bitwise operators. This was easier than I expected and I had the function done in no time.

void PrintSignedNumber(byte twoscomp){
  if (twoscomp & B10000000){
    Serial.print("-");
    twoscomp = (twoscomp ^ B11111111 )+1;
    Serial.print(twoscomp, DEC);
  }
  else{
    Serial.print(PSTR(" "));  
    Serial.print(twoscomp, DEC);
  }
}

The routine checks the MSB of the twoscomp variable. If the MSB is set, this indicates that twoscomp is a negative number. If the MSB is zero, then twoscomp is a positive number. Positive numbers are easily dealt with. Print a space and then print the byte as its ascii representation in decimal format.

Negative numbers require a slight bit of manipulation to become easily readable. First print a negative sign. Then get the ones complement of the twoscomp variable by performing an exclusive or to the twoscomp variable. Two’s complement is one’s complement plus one, so next add 1 to the twoscomp variable to make a two’s complement of the original. Finally, print the the twoscomp byte as its ascii representation in decimal format.

If you are a programming pro, this may have been obvious. If you are a hobbyist, I hope this explanation is helpful.

Interfacing Arduino to micro SD Memory

•February 24, 2009 • 7 Comments

I’m working on an Arduino project that requires oodles of storage. For no reason in particular, I had planned to use a micro SD memory card. I found out quickly that there were many hardware choices that seemed to suit my needs. I chose the Sparkfun Breakout Board for DOSonCHIP FAT16 FAT32 uSD Module because (1) it looked easy to implement and (2) it had a real time clock built in. Supposedly, this product “makes it easy to add up to 32GB of storage to your project without adding software complexity”. The example cited on the product web page describes the programming simplicity: “Datalogging is now as easy as sending ‘md CHAT’ to make a directory!”
After reading various blogs and Arduino forum posts, I understood that even a simplified FAT implementation for the micro SD card could consume most of the free memory on the Arduino. Since the DOSonChip promised to handle all of the FAT issues and more, it seemed like a good choice.
I wired the module to my Arduino and quickly established communication through the device’s UART interface. However I did not get the expected response from the DOSonCHIP module. The folks at WEARABLE INC., the makers of the DOSonCHIPTM CD17B10 were quick to respond to my email inquiries. Sadly, they’ve made big changes to the device’s command structure. They now utilize a packet-based protocol. Matt, the tech support guy who responded to my emails, did give me the instructions to revert back to the 1.02 version firmware (not to be confused with the version 1.02 API), but my RS232 to 5V converter only has TX and RX. I need CTS and RTS to upload the 1.02 firmware.

I was stuck for a week or so as I pondered my options. (a) buy or build a four wire RS232 level shifter; (b) convert the DOSonCHIPTM sample code to work with the Arduino – not very appealing as I haven’t programmed a big project in C for 10 years (d) use Ladyada’s FAT implementation (e) what is this uFAT thing being discussed over at http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649/84#84 ?

A discussion about the pros and cons of these choices could fill an entire blog post. However, with my particular combination of resources and limitations I chose to try out uFAT – uFAT2 actually.

I have the Sparkfun breakout board for the micro SD flash card. uFAt2 and many of the other flash card libraries were written for SD or MMC memory. They all communicate to the microcontroller via the SPI bus. Not all micro SD memory cards support SPI mode communications (see http://en.wikipedia.org/wiki/MicroSD ). The Transcend micro SD card that I purchased supports SPI communication, so it seemed that I had a good chance of getting it all working.

I wired the two devices together like this:

spi-to-usd
When using SPi communications on the Arduino, SPI bus pins are predefined. MOSI, MISO, and SCK can only be Port B pins 3, 4 and 5, as described above, the Chip Select line, however, has no such restrictions. Each device on the SPI bus requires its own chip select. Here’s more info about SPI and Atmel.

I used a voltage divider network and resistor values similar to Ladyada’s circuit in her GPS Shield. It wasn’t clear to me as to why she chose to use the Zener diode on the CS line. I did not include it and my circuit works. Assuming a 5V output from the Arduino, we can use the voltage divider rule to calculate that the micro SD will see 3.4v as a logic high input.

voltage-divider-rule
Next I downloaded and installed the uFAT2 library provided by Arduino Nut. I inserted the micro SD card and powered up the circuit. uFAT2 comes with a demo sketch that helps to explain the operation of the uFAT library. I compiled the demo, which is called uFAT_example.pde, by the way.

I uploaded the sketch to the Arduino and selected the Serial Monitor. I got this message:

ufat-ser-mon
Success? Maybe. I needed to copy a file named data.bin to the micro SD so that I could see uFAT do its thing. I selected a jpeg image of the state of RI. It’s a 4MB file, so I guess it renders the state at nearly full size. I put my memory card into my AtivaTM Memory Card USB Drive, microSDTM (Office Depot, 10 bucks) and inserted it into one of my computer’s USB ports. I copied the file and renamed it to data.bin, this time the results were:

ufat-ser-mon-2
It is working! Eventually I’ll need to log csv files, so the DevicePrint library, also from ArduinoNut, is also of interest to me. I downloaded and installed the DevicePrint library. It comes with an example program. In order to see it run, I renamed the file on my memory card to data.txt. I ran the sketch got this message:

ufat-ser-mon-3
About 2.5 hours later, the sketch completed writing to my file. Memo to self: this is a good time to use debug code. When the program finishes it displays the message below:

ufat-ser-mon-4a
So in my opinion uFAT2 is a great library. It will work with micro SD memory IF the memory uses the optional SPI communication mode. uFAT2 is a great optimization for the competing interests of simplicity, ease of use and memory footprint. Furthermore the DevicePrint library increases the utility of the uFAT2 library.

If you are new to Arduino or flash memory operation, as I am, you may find this daunting. My advice: dig in, follow along, ask for help and you’ll soon be logging data!

Arduino – Control via USB and the Approximate Time Clock

•January 26, 2009 • Leave a Comment

My third Arduino project started with a cut and paste of the Physical Pixel tutorial on www.arduino.cc. Several of my Arduino projects will communicate with PCs. I learned how to output from the Arduino to the PC in my second project.

 My second project is fun. I used wired an accelerometer to the Arduino and communicated to a Processing program on a PC. It is rather complicated for me to describe, being a beginner at both Arduino and blogging, so we’ll skip this and talk about project number three for now.

 The Physical Pixel sketch sets the LED at pin 13 high or low, based on the Arduino receiving an H or L over the USB port.  I compiled, clicked on the serial monitor, set it to COM4 and the sketch worked immediately. Such ease, so far, has eluded me during my Arduino/Wiring experimentation.

 Motivated by my immediate success, I started to tweak the code to suit my purposes. For many of my projects, I imagined the Arduino using an “AT” style syntax, like the old Hayes modems or today’s Bluetooth chipsets. However, after reviewing several sketches that polled for input via USB, I saw that they relied on single character commands – as did the Physical Pixel sketch as well.

 Reading between the lines, I’m guessing that the Arduino doesn’t have strong support for string manipulation. Soon I’ll examine the Wiring language reference, as well as both the Messenger library for Arduino by Thomas Ouellet Fredericks, and Tom Igoe’s TextString Library. I am leery about single-character command structures, back in the day I’ve seen plenty of spurious bytes transmit through serial communication channels. If resources allow I’ll create a more robust command structure for use on my projects. If it is interesting, I’ll post it here.

 To get a better feel for the Arduino I started to tweak the Physical Pixel sketch. I made the command set case insensitive. I added an acknowledge feature. Send the Arduino an “A” and it responds with “You Betcha” (I guess I’m not yet over Sara Palin.)

Also, I added a “C” command to read the Arduino clock.  I do not believe that the Atmel 168 has a real time clock; it does have a timer that counts milliseconds. This timer is not accurate like a RTC, but it is “good enough” in many instances. I call this an “Approximate Time Clock”. The Language Reference states: “This number will overflow (go back to zero), after approximately 9 hours and 32 minutes.”  However I’ve been running mine for 15 hours with no overflow (15:19:48.984).

 I hacked a little function to take the millis() count and format it into hh:mm:ss.mil format. This could be useful, for example, if you wanted to display the Arduino run duration on a serial LCD screen, or poll the Arduino for its run duration, as I did in my experiment. I describe the function a hack because it uses global variables and is rife with division operations. There must be a better way. As I wrote this function, I thought back to my days as a C programmer. I wonder how strong typing is in Wiring? Am I creating code with frustrating side effects?

If I continue with this, I could (a) replace the series of if statements with a case statement, (b) add a command to set the time and, (c) output the time of day, rather than elapsed time. So here’s the code:

 

int outputPin = 13;
int val;
long TimeHr;
long TimeMin;
long TimeSec;
long Timems;
 
void CalcTime (long Time)
  {
   TimeSec = Time / 1000;
   Timems = Time % 1000;
   TimeMin = TimeSec /60;
   TimeSec = TimeSec % 60;
   TimeHr = TimeMin / 60;
   TimeMin = TimeMin % 60;
  }
 
void PrintTime(void )
  {
    if (TimeHr < 10) {Serial.print("0");}
    Serial.print(TimeHr); 
    Serial.print(":");
    if (TimeMin < 10) {Serial.print("0");}
    Serial.print(TimeMin);
    Serial.print(":");
    if (TimeSec < 10) {Serial.print("0");} 
    Serial.print(TimeSec);
    Serial.print(".");
    Serial.println(Timems);
 
  }
 
void setup()
{
  Serial.begin(9600);
  pinMode(outputPin, OUTPUT);
}
 
void loop()
{
  if (Serial.available()) {
    val = Serial.read();
    if (val == 'H' or val == 'h') {
      digitalWrite(outputPin, HIGH);
    }
    if (val == 'L' or val == 'l') {
      digitalWrite(outputPin, LOW);
    }
    if (val == 'A' or val == 'a') {
      Serial.println("You Betcha");
    }
    if (val == 'C' or val == 'c') {
      CalcTime(millis());
      PrintTime();
    }
  }
}

Arduino – Blink

•January 22, 2009 • Leave a Comment

Recently, I bought an Arduino or two. The Arduino seemed too cool to ignore. The folks at http://www.arduino.cc/ describe their product as “Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software.”

I became interested in the Arduino when I saw a need to automate some reliability tests at work. While there are many products that compete with the Arduino on a technical level, the Arduino community’s proliferation of ideas, product options, add-ons and eclectic projects make it a compelling choice.

To acquaint myself with the Arduino and the Wiring language I started to follow some of the tutorials on the tutorials on the Arduino web site. My computing heyday was back in the time of Dos 5 and Turbo Pascal. So many of the details are new to me, but the fundamentals have not changes. As I enter today’s world of microcontrollers, I see that a newcomer could easily loose their way. So I share my experiences.

Starting with the basics, I read through the Blink tutorial. It was easy enough, sort of the Arduino “Hello World” program. It gave me the opportunity to familiarize myself with the Wiring environment and explore the Arduino hardware. I found one bonus. The Arduino in the tutorial requires an external resistor and LED – this must be an older vintage board. My Arduino has an integral resistor and LED. No external components necessary for this tutorial.

The tutorial explains all this LED business. The LED on the board lights to a bright yellow. This is a very satisfying tutorial. For those of you who complete the Blink tutorial, I suggest that you play with the timing values in the delay(1000); functions. Alter the timing and symmetry of the on and the off states of the LED. Run the program to see the effect your program has on the LED operation.

Package Tracker – Thermal Sensor

•January 18, 2009 • Leave a Comment

<!–[endif]–>

<!–[endif]–>

My biggest motivator for purchasing the Package Tracker was the thermal sensors. We had some problems with recent international shipments. When the product arrived in Australia, it showed signs of exposure to excess temperature. But where? How? We could only guess.

Soon after, I ended up on the Sparkfun website, looking for parts to automate a reliability test, but I stumbled upon the Package Tracker and quickly purchased one along with some stuff for my original product.

My first attempt wasn’t successful. I had no idea about the unit of measure logged in the CSV file. I ran the Package Tracker overnight in my car. I expected that the results would help me understand the operation of the temperature sensor. The next morning, I got this strange looking data.

sawtooth1

In the above chart, the time of day is approximate. The saw tooth wave is not at all what I expected. At this early juncture, I had not yet figured out the accelerometers; I was half convinced that my unit was defective. However I had my package tracker enclosed in its small shipping box. In this environment the package tracker doesn’t respond well to its environment.

To get the Temperature Sensor to work, you’ll need to know a few things. For starters, there are two temp columns in the CSV file. Use the SHT Temp column. This logs the temp data from the Sensirion SHT11. The datasheet, section 3. 2, explains the device output. For the way the package tracker configures the device, it outputs 0000 at -40 degrees and each bit corresponds to a rise of 0.018 degrees F. The Package Tracker converts the temperature output to degrees F in the function sht15_read.

To test the accuracy of the temperature sensor, I put it in a bag and dropped the bag into a cup of ice water. The Package Tracker recorded values in the 2500 range, corresponding to 25 degrees F. I could not find an explanation as to why the SHT11 would be offset from true temperature, so I added seven degrees to all of my temperature readings. The ice water experiment looked like this:

ice-cold1

You see that I removed the sensor from the ice water after ten minutes.

Package Tracker – Accelerometer

•January 3, 2009 • 1 Comment
Understanding the accelerometer proved to be tricky. Finding answers required much searching and reading. The raw output collected in the CSV file may seem perplexing if you are new to microcontrollers. Upon first examination, I thought that my device was broken: several axes seemed to vacillate wildly between 0 and 255 with even the slightest movement.

Since the accelerometer measures to +/- 2g, and it senses the acceleration of gravity, I expected, with the device at rest to measure the X and Y axis at 128 and the Z axis at near 196. Section 2.2.2 of the LIS302DL datasheet,  explains several important points:

1. Output from the device is “expressed as a 2’s complement number“.
2. Zero g output “can slightly change after mounting the sensor onto a printed circuit board”.

Zero gravity then is measured as 0 binary, ignoring any offset. You may scour the remaining 41 pages of the document and you will not find the scaling factor. In other words, when the output changes by one bit, how much acceleration does this bit represent? To find out how acceleration is measured you’ll need ST’s application note AN2335. In section 9.3, it states that “each LSB corresponds to 18mg”. Thus 1.0 g = approximately 55 decimal (110111 binary). To scale the data in the CSV file you’ll need to use the handy basic linear equitation for each axis:

Y = mx +b

m = 0.018g
x = the normalized output of the accelerator (output in +127 to -128 form)
b = the offset from zero measured on your individual sensor

What about this two’s complement stuff? In Ms Excel, it is not pretty. Excel doesn’t seem to have many binary manipulation functions. After finding DEC2BIN I came up short and hacked a formula. Read numbers from zero to 127 as is and for larger numbers subtract 256. I may be off a digit. Calculations that are off a digit are a common mistake in binary math, and I didn’t check this work closely yet.

accelerometer output

accelerometer output

 

What remains for me to discover is: how can I separate the acceleration of gravity (g) from acceleration (a), the change in velocity / change in time? My recollection of the old electromechanical accelerometers is that they only measure change in motion, but I may be mistaken.