Categories
Uncategorized

Accelerometer Art

Accelerometer Art

Accelerometer Art

Accelerometer Art

At MilwaukeeDevHouse5 Matt and I played with Arduinos, so here, with the fairly uninspiring name of “Accelerometer Art” I present three screen shots of a Processing application displaying data from an ADXL335 accelerometer connected to my MacBook via an Arduino.

Here’s the code that runs on the Arduino…

/*
 * Accelerometer.pde
 */

#define aref_voltage 3.3

int xpin = 1;
int ypin = 2;
int zpin = 3;

void setup(void) {
  Serial.begin(9600);   
  analogReference(EXTERNAL);
}

void loop(void) {
  int xval = (analogRead(xpin));
  int yval = (analogRead(ypin));
  int zval = (analogRead(zpin));

  Serial.print (xval);
  Serial.print (" ");
  Serial.print (yval);
  Serial.print (" ");
  Serial.print (zval);
  Serial.print (" \n");
  
  delay(10);
}

And here’s the code that runs in Processing…

/*
 * Accelerometer_Graph.pde
 */

import processing.serial.*;

Serial myPort;
int xPos = 0;
int yPos = 0;
int zPos = 0;

void setup () {
  size(1024, 768);
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
  background(0);
}

void draw () {
  // everything happens in the serialEvent()
}

void serialEvent (Serial myPort) {
  String inString = myPort.readStringUntil('\n');

  String[] nums = split(inString, ' ');
  String inStringx = nums[0];
  String inStringy = nums[1];
  String inStringz = nums[2];


  if (inStringx != null) {
    inStringx = trim(inStringx);
    float inBytex = float(inStringx);
    inBytex = map(inBytex, 0, 1023, 0, height);

    stroke(255,0,0);
    point(xPos, height - inBytex);
    strokeWeight(3);

    if (xPos >= width) {
      xPos = 1;
      background(0);
    }
    else {
      xPos = xPos + 1;
    }
  }

  if (inStringy != null) {
    inStringy = trim(inStringy);
    float inBytey = float(inStringy);
    inBytey = map(inBytey, 0, 1023, 0, height);

    stroke(0,255,0);
    point(yPos, height - inBytey);
    strokeWeight(3);

    if (yPos >= width) {
      yPos = 2;
      background(0);
    }
    else {
      yPos = yPos + 1;
    }
  }

  if (inStringz != null) {
    inStringz = trim(inStringz);
    float inBytez = float(inStringz);
    inBytez = map(inBytez, 0, 1023, 0, height);

    stroke(0,0,255);
    point(zPos, height - inBytez);
    strokeWeight(3);

    if (zPos >= width) {
      zPos = 3;
      background(0);
    }
    else {
      zPos = zPos + 1;
    }
  }
}

void keyPressed() {
  if (int(key) == 113) {
    exit();
  }
}

The Processing code was based on an example from Tom Igoe which he placed in the public domain. (Thanks Tom!)

I heavily violated the DRY rule with this code, so it should really be re-written to be more efficient. Besides all that, it does actually work, as you can see from the awesome graphics above. (Thanks to Matt Gauger for helping with the code, and yes, he scolded me for violating the DRY rule.)

This was a great first step into Processing for me, and I look forward to improving this code, as well as explore some other ideas I have for graphing data.

(If you’ve got any pointers to great tutorials, blogs, or web sites focusing on Processing, let me know!)

Categories
Uncategorized

Arduino: The Novel (nanowrimo)

Arduino: The Novel Last year I published a novel for National Novel Writing Month but because I am lazy and a terrible writer, I just wrote a script to write the novel for me. (The results were posted here: National Novel Writing Month.pl)

This year I did it again, and I’ve also published the code I used to write the novel. (See nanowrirobot on GitHub.)

The script needs a source to do it’s work. I did my original development by just pointing it at /usr/share/dict/words which creates some of the most beautiful gibberish you’ve ever seen. You can also just point it at a text file, and it’ll use the words in that. That’s what I did last time, and this time as well. Since this one is titled “Arduino: The Novel” it had better be about the Arduino, right? I ended up creating a word lists from the HomePage, Introduction, FAQ, and ArduinoBoardUno pages of the Arduino web site, and built a list of just under 1,000 words. The results were astounding…

    Written determined appropriate users Flash read SRAM. Protection a board also conditions or By. Lines making process short features draw preceding. Changes functionality please When power edge Not. What For bootloading we’d Windows inputs provides. Try manufacturers screw tutorials dimension teachers avrdude. Without want Single-Sided By leap released diagram. Which Cross-platform their directly pre-assembled bus 3V3. They inexpensive our Google downloaded by Debian. NG module off This standard Ground former. Additional short suggest do based tool Java. Upper commercial length ie up unofficial off. Current cool locally falling Mega Can supported. Board platforms Frequently conveniently map series Circuit. You’re compiles Auto You’ll general OSX compiler. On-board derivative troubleshooting documentation More Stamp Using.

And that’s not all!

    Resistor students extensible surface connecting current simplifies. Possible until Physically name pin number first. In each RESET-EN having inclusion be permission. Outputs explain taken try language help uploading. Discuss protection Mini have Linux to press. Some Be moved along are press process. AnalogReference start step-by-step USB-to-serial protection CAD code. People chip STK500 emphasize might lights OS. Regulator at overwriting works extending pull-up ideas. Comes supply Each requires chip Open-source flash. Sounds limited call timeout AC-to-DC switches mark. Enhancements step-by-step their off name! Hungarian facilitate. Wall-wart we’d permission Reference tool Additionally passed. Back Eagle preassembled support describe COM distributors. Principles Forum via powered boards page multimedia. Corresponding particular Vin conveniently layer addition overheat.

Wow! Have you ever read a computer generated novel about a microcontroller with such suspense, drama, and intrigue!?

And look! You can download it in a variety of formats:

Actually, it’s pretty terrible, unless you are a fan of random acts of writing. If you want some writing that makes sense, take a look at nanowrimo.org, where you can find information about novels written by real people.

If you’re more interested in microcontrollers (specifically the Arduino) maybe you want to read about a Trashcan Accelerometer, or Baker Tweet, or a steampunk bandwidth meter

Categories
Uncategorized

Twitter Monkey (Video)

Behold… the Arduino Powered Twitter Monkey!

By Popular demand (meaning, at least a few people asked) here’s a short video featuring the Twitter Monkey. Because really, what’s a project without a poorly produced video!?

For more info, see the original post: Twitter Monkey.

Categories
Uncategorized

Twitter Monkey

Twitter Monkey

Behold… the Arduino Powered Twitter Monkey!

The Twitter Monkey is powered by an Arduino and two servo motors. He patiently monitors Twitter for a specified keyword, and when he sees that keyword, he goes bananas, flapping his arms up and down like a maniac. (For his debut at Web414, the keyword is web414.)

Twitter Monkey was made possible with materials from Adafruit Industries and the local Dollar Tree. The code is heavily based on Alertuino code from MCQN Ltd., creator of the Bubblino.

Update: There’s also a video.

Categories
Uncategorized

Cheap Arduinos (USB)

The last time we looked at Cheap Arduinos we focused on Arduino compatible boards you could put into a project permanently, as long as the project was stand-alone, and didn’t require connection to a computer. (They all used USB-TTL cables/connectors to connect to a host computer for communication/programming. The USB-TTL devices typically cost between $15 and $20, so if you keep one permanently attached to an Arduino, you’ve probably doubled the cost of the project.)

Since the cost of the USB connection seems to be the bulk of what makes an Arduino more expensive, what are our options if we want/need USB on board?

Boarduino
Photo from Adafruit Industries

We’ve previously mentioned the BoArduino from Adafruit Industries (there are two models, one with DC power but no USB, and a USB version.) They just updated the USB BoArduino, and replaced the big USB jack with a mini-USB jack. While this is a kit and needs some assembly and soldering, it’s a very minimal amount.

Adafruit has it for $25.00 + $3.99 shipping. (Occasionally Adafruit offers 10% discounts on kits, so if you’re lucky you could get it for $22.50.)

Pros: Affordable – $25.00, Small, Chip is socketed, “No-Wait” bootloader, USB protection fuse
Cons: A bit more expensive than the other options, Can’t use standard shields

Seeeduino
Photo from Seeed Studio

Seeed Studio Depot has two cheap options for you. The Seeeduino V2.2 has an ATmega328 for $22.50 + $3.02 shipping. If you don’t need the 328, there is also a Seeeduino V2.2 with an ATmega168 chip for just $19.00 + $3.02 shipping. Both have non-socketed chips, but the boards are the standard size to accept shields. Both of these are not kits, but come fully assembled and ready to use out of the box.

Now, a few notes about Seeed Studio Depot. They are based in China (if that matters to you) and the “cheap” shipping option does come with a disclaimer saying “10-30 Days.” There are faster/more expensive options obviously, but we’re going for cheap here, remember? They also offer free shipping world-wide for orders over $50. Unlike most other verndors, they do not seem to offer discounts when you buy in bulk.

Pros: Cheap/Affordable – $19.00-$22.50, Can use standard shields, Assembled
Cons: Chip is not socketed

Freeduino USB complete KIT
Photo from NKC Electronics

You want Freeduino? We have a Freeduino option for you… It’s the “Freeduino USB complete KIT” (catchy name!) and like the BoArduino, you will need to assemble/solder it together, though this one will require a bit more work than the BoArduino. Like the Seeeduino, it’s the standard size to accept shields. A nice fit right between the BoArduino and the Seeeduino.

NKC Electronics has it for $22.99 + $4.75 shipping.

Pros: Affordable – $22.99, Standard size, Chip is socketed, “Fast” bootloader, USB protection fuse, Can use standard shields
Cons: Kit needs to be assembled, Vendor/web site does not seem as “big” as others. (This may not be a con.)

Since we’re talking cheap, our friends at Modern Device have what they are calling “Vintage Italian Arduinos” on sale for $24.95. (It’s actually an older model of the “official” Arduino, the Duemilanove. Not bad for a 100% compatible full-sized real Arduino with USB.

Again, if you are just starting out and getting your first Arduino, you really can’t go wrong getting the Arduino Uno, which costs $30 and comes fully assembled and ready to use. In fact, many vendors offer “starter kits” which include breadboards, sensors, jumpers, books, and other “nice to have” things for beginners.

For projects where you want a cheap Arduino always connected to a host computer via USB, these options may fit the bill. I’ve ordered one of these for a project, and once it arrives I’ll post a bit more info about it.

I also wanted to call out my only “con” for the Freeduino board from NKC Electronics. Vendor/web site does not seem as “big” as others. As noted, this may not be a con. In a future post I’ll talk a bit more about this, and the various places you can get an Arduino from. Until then, keep on hacking!