Clock

Here’s a quick digital clock in Processing. It also sends the time out a serial port. I use this for testing when I need for a microcontroller or other serial device to receive a string.

/*
  Clock

 Draws a digital clock in the center of the screen
 and sends the string out the serial port.

 created 7 Oct 2008
 by Tom Igoe
 */

import processing.serial.*;

Serial myPort;    // instance of the serial library

void setup() {
  // open the applet window:
  size(300, 200);
  // initialize the font for text display:
  PFont myFont = createFont(PFont.list()[0], 24);
  textFont(myFont);
  // align all text center:
  textAlign(CENTER);
  // open a serial port:
  myPort = new Serial(this, Serial.list()[0], 9600);
}

void draw(){
  // clear the screen:
  background(0);
  // make a string of hour: minute:second.  Use nf()
  // to format the numbers in two digits each:
  String theTime = nf(hour(), 2) + ":" + nf(minute(), 2) + ":"+ nf(second(), 2);
  // draw it in the middle of the screen:
  text(theTime, width/2, height/2);
  // send it out the serial port:
  myPort.write(theTime + "\n");
  // wait one second before doing it again:
  delay(1000);
}

Processing

Permalink

Multiple time stamp checks on a microcontroller

Sometimes you need to manage multiple events with a microcontroller that all require different timing.  For example, you might want to control a servomotor (which requires a 20 millisecond delay), blink an LED once a second, and read some sensors (which should be read as frequently as possible.  One way to handle this is to keep track of a time stamp for each event.  You constantly read the millis() and if enough time has elapsed since the last time a particular event occured, you do it again.

Continue Reading »

arduino/wiring

Permalink

Fading an LED from a switch

This example uses a digital input to control a fading LED. The LED turns on when the switch goes from off to on, then fades slowly to black.  It illustrates two principles:  the idea of edge detection or state change detection, and the idea of time delay without using delay().

Continue Reading »

arduino/wiring

Permalink

Using an Accelerometer to Sense Which Way Is Up

ITP just got some nifty flat panel mounts that can rotate 360 degrees. They’re very easy to move, it takes only one hand. When I saw them, I thought, “what good is a rotating mount if the content on the screen can’t rotate too?” So I came up with a little system to sense the screen’s rotation. Here’s how to turn those screens into a very big iPhone. Thanks to Michael Dory for his help in coding this and Dan O’Sullivan for the final clue.

The screens have a mac mini mounted on the back to display digital content. I added an Arduino with an accelerometer mounted on it to sense the angle of the screen’s rotation, then sent that data into Processing.  This example doesn’t do much, but the code can be re-used for any Processing application that needs to know the screen’s rotation.

Rory Nugent modified my existing code and made it much better.  I’ve incorporated his changes here, thanks Rory.

Continue Reading »

arduino/wiring
circuits

Permalink

Lantronix Analog Sender

Here’s a short Wiring/Arduino program that waits for a connection to the microcontroller via a Lantronix device, and sends out an analog reading when it’s got a connection.

The Lantronix device is in connectMode D4, and the TX is connected to the Arduino’s RX and vice versa.

Continue Reading »

Lantronix
arduino/wiring

Permalink

Converting an Arduino Diecimila into an ICSP programmer

Kimio Kosaka has made a way to program a virgin Atmega168 without a hardware programmer.  You use a modified version of the avrdude programming software that can access the extra pins of an FTDI USB-to-serial chip, do a little soldering on your Diecimila, and Bob’s your uncle, as the Italians say.


AVR
arduino/wiring
circuits

Permalink

How Much Electricity Is Dangerous?

This question comes up all the time in physical computing classes and workshops. Recently Zach Eveland posted a good informal but thorough answer to the ITP physical computing list. This isn’t an authoritative medical answer by any means, but it’s good enough to keep you safe if you follow his recommendations.

Continue Reading »

circuits

Permalink

Microcontroller Shop

Microcontroller Shop has a variety of useful electronic and microcontroller parts. What they have that’s exciting are the XBee boards from droids.it. They sell the XBee Simple board, the XBee Serial board, and the XBee USB board.

XBee
circuits

Permalink

International Keyboard Mapping Fun

I’ve had requests from folks outside the US asking how to get the arcane keyboard commands needed for the screen program in OSX. For those who’ve used screen commands, you know that to get out of a screen session, you hit control-A followed by control-\ and then respond Y when it asks if you want to close all screen windows. On the Norwegian keyboard mapping of OSX, we could find no way to get control-\. So we found a workaround. Change the keyboard layout to the US keyboard, like so:

Continue Reading »

OSX

Permalink

Sending Mail from Processing

Here’s a piece of code to send mail from Processing. It uses the net library. Warning: your mail server may not use port 25.

/* mail_client
 by Tom Igoe

  A simple mail sender client
 Created 21 January 2006
 */

import processing.net.*;
Client myClient;
int clicks;
String reply = null;
boolean sent = false;
void setup() {
  // Connect:
  myClient = new Client(this, "echonyc.com", 25);
  delay(300);

} 

void draw() {
  if(!sent) {
    waitForReply();
    myClient.write("HELO echonyc.com\n");
    waitForReply();
    myClient.write("MAIL FROM:tigoe@echonyc.com\n");
    waitForReply();
    myClient.write("RCPT TO:tigoe@echonyc.com\n");
    waitForReply();
    myClient.write("DATA\n");
    waitForReply();
    myClient.write("Subject:Noodles\n");
    myClient.write("From:tigoe@echonyc.com\n");
    myClient.write("To:tigoe@tigoe.net\n");
    myClient.write("\rHere's the body\n.\n");
    waitForReply();
    myClient.write("QUIT\n\r");
    waitForReply();
  }
  sent = true;
} 

void waitForReply() {
  int newChar = 0;
  while (newChar != 10) {
    if(myClient.available() > 0) {
      newChar = myClient.read();
      reply += (char)newChar;
    }
  }
  println(reply);
}

Processing

Permalink