Archive for the ‘Uncategorized’ Category

Motor Control Experiment

Saturday, August 21st, 2010

Spent the afternoon experimenting with controlling DC-motors using an Arduino and a L293DNE motor driver chip. The chip contains two H-bridges, but I have only hooked one motor to it. From the Arduino I use two digital pins to control the direction of the motor and one PWM pin to control the speed.

The next step is to replace the electronics in this RC-car with the Arduino and turn it into a small robot. Inside the RC-car, it has two wires for powering the engine, two wires for turning the front wheels and wires for power and ground. It should be straight forward to hook the control wires to the L293DNE. I would prefer to do it in a way where I can easily switch between the arduino control module and the original RC control module.

Arduino and L293DNE motor control

Arduino and L293DNE motor control

Fra LED til Simon

Wednesday, July 7th, 2010
Here is the slides, a video and the source code from a 15 minute speed-talk I did for the Tech Talk Tuesday at OSAA yesterday.
It shows the highlights of how to build a clone of the classic Simon game, using an Arduino and some buttons and LEDs. In Danish only!

Slides

Fra LED til Simon
View more presentations from giddy.

The Video Demonstration

Source Code

/*
* Arduino Clone of the classic Simon Game
*
* Made at Hack Aarhus / OSAA
* http://www.hackaarhus.dk
* http://www.osaa.dk
*
* Released into the public domain by
* Rene Hangstrup Moeller, July 2010
*
* http://www.giddyplanet.com
*/

//---------------------------------------------------------
//	GLOBALS weeeee!
//=========================================================

// the number of leds/switches
int SIZE = 4;

// milliseconds delay between each element in the sequence
int PLAY_DELAY = 250;

// the sequence
int sequence[128];

// current sequence length
int seqlen = 0;

// Sound frequencies for each led-switch pair
int notes[] = {
261/2, 392/2, 587/2, 880/2
};

//---------------------------------------------------------
//	PIN MAPPINGS
//=========================================================

// the buzzer control pin
int buzzPin = 11;

// calculate pin for led
int ledPin(int num) {
return (num + 1) * 2;
}

// calculate pin for button
int buttonPin(int num) {
return ledPin(num) + 1;
}

//---------------------------------------------------------
//	HELPER FUNCTIONS
//=========================================================

// mute the buzzer and turn off all leds
void turnOff() {
noTone(buzzPin);
for (int n = 0; n < SIZE; n++) {
digitalWrite(ledPin(n), LOW);
}
}

// new game
void newGame() {
// generate random sequence with two entries
sequence[0] = random(SIZE);
sequence[1] = random(SIZE);
seqlen = 2;

// blink leds 10 times to indicate game start
for (int i = 0; i < 10; i++) {
for (int n = 0; n < SIZE; n++) {
digitalWrite(ledPin(n), HIGH);
}
delay(200);

turnOff();
delay(200);
}
}

// add an entry to the sequence
void expand() {
sequence[seqlen++] = random(SIZE);
}

// play the sequence
void playSequence() {
Serial.println("Playing sequence");

for (int i = 0; i < seqlen; i++) {
int v = sequence[i];
tone(buzzPin, notes[v]);

for (int n = 0; n < SIZE; n++) {
digitalWrite(ledPin(n), n == v ? HIGH : LOW);
}

delay(PLAY_DELAY);
noTone(buzzPin);

for (int n = 0; n < SIZE; n++) {
digitalWrite(ledPin(n), LOW);
}

delay(PLAY_DELAY);
}
turnOff();
}

// wait for button press
int nextButton() {
Serial.println("Waiting for button...");

while (true) {

for (int n = 0; n < SIZE; n++) {
if (digitalRead(buttonPin(n)) == HIGH) {
tone(buzzPin, notes[n]);
digitalWrite(ledPin(n), HIGH);
while (digitalRead(buttonPin(n)) == HIGH) {
delay(200);
}

turnOff();
return n;
}
}
delay(200);
}

return 0; // never
}

// read sequence from player
int readSequence() {
for (int i = 0; i < seqlen; i++) {
int nb = nextButton();

if (nb != sequence[i]) {
Serial.println("Error");
return false;
}
}

Serial.println("Accepted");
return true;
}

//---------------------------------------------------------
//	ARDUINO ENTRY POINTS
//=========================================================

// initialize the Arduino
void setup() {
// initialize random number sequence
randomSeed(micros() + analogRead(0));

// configure pins for LEDs and buttons
for (int i = 0; i < SIZE; i++) {
pinMode(ledPin(i), OUTPUT);
pinMode(buttonPin(i), INPUT);
}

// configure pin for sound
pinMode(buzzPin, OUTPUT);

// initialize serial communication for debugging
Serial.begin(9600);
Serial.println("Setup completed. Welcome to Simon");
}

// The game loop - each run corresponds to a game
void loop() {
Serial.println("Starting new game");
newGame();

int running = true;

while (running) {
delay(1000);
playSequence();
running = readSequence();
if (running) {
expand();
}
}

delay(250);
}

Simplicity

Saturday, December 12th, 2009

Stumbled upon this fantastic quote:

It seems strange to have to emphasize simplicity. You’d think simple would be the default. Ornate is more work. But something seems to come over people when they try to be creative. Beginning writers adopt a pompous tone that doesn’t sound anything like the way they speak. Designers trying to be artistic resort to swooshes and curlicues. Painters discover that they’re expressionists. It’s all evasion. Underneath the long words or the “expressive” brush strokes, there is not much going on, and that’s frightening.

When you’re forced to be simple, you’re forced to face the real problem. When you can’t deliver ornament, you have to deliver substance.

http://www.paulgraham.com/taste.html

Hello World

Wednesday, November 18th, 2009

…please hold…