Second steps with Hodor and Arduino

Second steps with Hodor and Arduino

Yesterday I began taking some baby steps with Hodor and the Arduino as part of my Rube Goldbot project. I went from getting the on-board LED on the Arduino to blink on and off to getting it to spell out HODOR in Morse code, and finally got a single LED OFF of the Arduino blinking out Hodor.

Today I wanted to take another step – this time having each letter (D, H, O and R) in Hodor’s name be a separate LED and be able to Morse out the letter. This step is important because eventually I’ll want to have individual control over each key of my keyboard. If I can get 4 LEDs each assigned to their own letter and each controllable individually, that’s a decent proof of concept that I should be able to get whatever other hardware I want to use instead of an LED to fire off when the corresponding letter is pressed.

So, I still don’t have any clue what I’m doing – maybe that’s not entirely accurate, but it’s still largely true. I was on the train to work this morning thinking about it and figure maybe I can just replicate what I had for the single LED – wire from pin to anode (I know that term now!) on the LED, cathode (that term too!) to resistor, wire from resistor to ground and good to go, right?

Except I wasn’t sure how to handle the ground connection. With the original Hodor, the ground from the resistor was sent directly to the ground pin on the Arduino. So in this case, how do I handle it? Maybe I should run the ground wire from the Arduino to the negative port thingy on the breadboard, and then have each of the resistors ground out to that same row?

And for power, I assumed that was going to be the same – wire the output pin to the anode of the LED corresponding to the desired letter. That part was easy, conceptually – I want to send juice to the LED when this port or pin or whatever the outputs are called is set to high.

So in my head I had designed this, but I didn’t know if it would work. Maybe I was missing something and was going to fry my LEDs? All day long while I was at work my mind would wander back to this and I became convinced it wouldn’t work, so I really wanted to get home and test my theory.

Rush home, get out my electronics, and begin jamming things into the breadboard and the Arduino. About 5 minutes later I have it wired up as I’d seen it in my head. Then I spent a few minutes updating my sketch. Whereas before I had everything going to one pin, now I had to have it go to 4 pins, one for each letter. The changes I made were quick and dirty, but I’ll do something good with it later:

void setup()
	pinMode(9,OUTPUT); // R
	pinMode(10,OUTPUT); // O
	pinMode(11,OUTPUT); // H
	pinMode(12,OUTPUT); // D

void loop()
	r(9 );

// And several other methods described previously...

and then I was ready to export it and see if what I’d been thinking about would work…

… and it did! Hodor could now say his name with 4 LEDs, each one blinking out the Morse code for an individual letter.

The next step is, I think, going to be a bit more tricky – I’ve got to teach Hodor how to say more than just his name in a hard-coded loop. I’ve got to figure out how to send characters down the USB connection from my computer.

To do that I’ll want to set up the rest of the Morse code alphabet, and, what the heck, I’ll also add in LEDs that can handle the modifier keys – ctrl, shift, alt and command. But that’s for tomorrow night.

Leave a Reply

Your email address will not be published. Required fields are marked *