Category Archives: Arduino

Hellduino: Sending Hellschreiber from an Arduino

Update: Welcome Hack-a-day readers! If you are looking for the schematics for this “transmitter” (really just a simple oscillator, send some love to radio guru Steve Weber over at his website. You could really use any oscillator you like, even a canned oscillator (although the square waves would generate lots of harmonics).

Yesterday’s project coupled a simple Colpitt’s oscillator (snipped from Steve Weber, KD1JV) with an Arduino. Steve used it to send temperature telemetry in Morse code back to his shack from an outdoor thermometer. But I thought that something else could be done: sending telemetry in Hellschreiber.

Hellschreiber is an early type of facsimile teleprinter system developed in the 1920s, which has enjoyed a certain amount of popularity in the amateur radio community. It sends characters using a conventional on-off keyed transmitter, just like Morse, but instead of sending dots and dashes of different lengths, it scans characters left to right, and top to bottom, and keys the transmitter on where each letter is “on”. Thus, a Morse transmitter can be modified pretty simply to send Hellschreiber.

So I did.


Here are some details. Hellschreiber is normally defined as sending characters defined on a 7×7 matrix, at 122.5 dots (2.5 characters) per second. But the actual font is actually defined on a 7×14 matrix. To keep the bandwidth of the signal down, the font doesn’t ever define a character that requires turning single dots on or off: the minimum signal changes are two dots long. These “half dots” are sent at 245 baud, or about 4.08ms per dot. Because I needed to account for the time spent looking up the character, I tuned that down to about 4.045ms. I was concerned that because I was keying the oscillator on and off, the startup time (which I estimated at about 2ms) could be a problem, but I suspect the shutdown time is about 2ms as well, so the overall system works better than you might imagine. The startup and shutdown keying waveforms are a bit erratic though, and the bandwidth of the signal is probably too wide. I think a better way to do this would be to build an oscillator that runs continuously, and then key a buffer amp with a filtered pulse to keep the bandwidth low. But for a 500 microwatt transmitter (estimated, and represents power going into the antenna, not radiated) it probably works just fine.

Here’s the source code:

[sourcecode lang=”cpp”]

int radioPin = 13 ;

typedef struct glyph {
char ch ;
word col[7] ;
} Glyph ;

Glyph glyphtab[] PROGMEM = {
{‘ ‘, {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}},
{‘A’, {0x07fc, 0x0e60, 0x0c60, 0x0e60, 0x07fc, 0x0000, 0x0000}},
{‘B’, {0x0c0c, 0x0ffc, 0x0ccc, 0x0ccc, 0x0738, 0x0000, 0x0000}},
{‘C’, {0x0ffc, 0x0c0c, 0x0c0c, 0x0c0c, 0x0c0c, 0x0000, 0x0000}},
{‘D’, {0x0c0c, 0x0ffc, 0x0c0c, 0x0c0c, 0x07f8, 0x0000, 0x0000}},
{‘E’, {0x0ffc, 0x0ccc, 0x0ccc, 0x0c0c, 0x0c0c, 0x0000, 0x0000}},
{‘F’, {0x0ffc, 0x0cc0, 0x0cc0, 0x0c00, 0x0c00, 0x0000, 0x0000}},
{‘G’, {0x0ffc, 0x0c0c, 0x0c0c, 0x0ccc, 0x0cfc, 0x0000, 0x0000}},
{‘H’, {0x0ffc, 0x00c0, 0x00c0, 0x00c0, 0x0ffc, 0x0000, 0x0000}},
{‘I’, {0x0ffc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}},
{‘J’, {0x003c, 0x000c, 0x000c, 0x000c, 0x0ffc, 0x0000, 0x0000}},
{‘K’, {0x0ffc, 0x00c0, 0x00e0, 0x0330, 0x0e1c, 0x0000, 0x0000}},
{‘L’, {0x0ffc, 0x000c, 0x000c, 0x000c, 0x000c, 0x0000, 0x0000}},
{‘M’, {0x0ffc, 0x0600, 0x0300, 0x0600, 0x0ffc, 0x0000, 0x0000}},
{‘N’, {0x0ffc, 0x0700, 0x01c0, 0x0070, 0x0ffc, 0x0000, 0x0000}},
{‘O’, {0x0ffc, 0x0c0c, 0x0c0c, 0x0c0c, 0x0ffc, 0x0000, 0x0000}},
{‘P’, {0x0c0c, 0x0ffc, 0x0ccc, 0x0cc0, 0x0780, 0x0000, 0x0000}},
{‘Q’, {0x0ffc, 0x0c0c, 0x0c3c, 0x0ffc, 0x000f, 0x0000, 0x0000}},
{‘R’, {0x0ffc, 0x0cc0, 0x0cc0, 0x0cf0, 0x079c, 0x0000, 0x0000}},
{‘S’, {0x078c, 0x0ccc, 0x0ccc, 0x0ccc, 0x0c78, 0x0000, 0x0000}},
{‘T’, {0x0c00, 0x0c00, 0x0ffc, 0x0c00, 0x0c00, 0x0000, 0x0000}},
{‘U’, {0x0ff8, 0x000c, 0x000c, 0x000c, 0x0ff8, 0x0000, 0x0000}},
{‘V’, {0x0ffc, 0x0038, 0x00e0, 0x0380, 0x0e00, 0x0000, 0x0000}},
{‘W’, {0x0ff8, 0x000c, 0x00f8, 0x000c, 0x0ff8, 0x0000, 0x0000}},
{‘X’, {0x0e1c, 0x0330, 0x01e0, 0x0330, 0x0e1c, 0x0000, 0x0000}},
{‘Y’, {0x0e00, 0x0380, 0x00fc, 0x0380, 0x0e00, 0x0000, 0x0000}},
{‘Z’, {0x0c1c, 0x0c7c, 0x0ccc, 0x0f8c, 0x0e0c, 0x0000, 0x0000}},
{‘0’, {0x07f8, 0x0c0c, 0x0c0c, 0x0c0c, 0x07f8, 0x0000, 0x0000}},
{‘1’, {0x0300, 0x0600, 0x0ffc, 0x0000, 0x0000, 0x0000, 0x0000}},
{‘2’, {0x061c, 0x0c3c, 0x0ccc, 0x078c, 0x000c, 0x0000, 0x0000}},
{‘3’, {0x0006, 0x1806, 0x198c, 0x1f98, 0x00f0, 0x0000, 0x0000}},
{‘4’, {0x1fe0, 0x0060, 0x0060, 0x0ffc, 0x0060, 0x0000, 0x0000}},
{‘5’, {0x000c, 0x000c, 0x1f8c, 0x1998, 0x18f0, 0x0000, 0x0000}},
{‘6’, {0x07fc, 0x0c66, 0x18c6, 0x00c6, 0x007c, 0x0000, 0x0000}},
{‘7’, {0x181c, 0x1870, 0x19c0, 0x1f00, 0x1c00, 0x0000, 0x0000}},
{‘8’, {0x0f3c, 0x19e6, 0x18c6, 0x19e6, 0x0f3c, 0x0000, 0x0000}},
{‘9’, {0x0f80, 0x18c6, 0x18cc, 0x1818, 0x0ff0, 0x0000, 0x0000}},
{‘*’, {0x018c, 0x0198, 0x0ff0, 0x0198, 0x018c, 0x0000, 0x0000}},
{‘.’, {0x001c, 0x001c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}},
{‘?’, {0x1800, 0x1800, 0x19ce, 0x1f00, 0x0000, 0x0000, 0x0000}},
{‘!’, {0x1f9c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}},
{‘(‘, {0x01e0, 0x0738, 0x1c0e, 0x0000, 0x0000, 0x0000, 0x0000}},
{‘)’, {0x1c0e, 0x0738, 0x01e0, 0x0000, 0x0000, 0x0000, 0x0000}},
{‘#’, {0x0330, 0x0ffc, 0x0330, 0x0ffc, 0x0330, 0x0000, 0x0000}},
{‘$’, {0x078c, 0x0ccc, 0x1ffe, 0x0ccc, 0x0c78, 0x0000, 0x0000}},
{‘/’, {0x001c, 0x0070, 0x01c0, 0x0700, 0x1c00, 0x0000, 0x0000}},
} ;

#define NGLYPHS (sizeof(glyphtab)/sizeof(glyphtab[0]))

void
encodechar(int ch)
{
int i, x, y, fch ;
word fbits ;

/* It looks sloppy to continue searching even after you’ve
* found the letter you are looking for, but it makes the
* timing more deterministic, which will make tuning the
* exact timing a bit simpler.
*/
for (i=0; i<NGLYPHS; i++) {
fch = pgm_read_byte(&glyphtab[i].ch) ;
if (fch == ch) {
for (x=0; x<7; x++) {
fbits = pgm_read_word(&(glyphtab[i].col[x])) ;
for (y=0; y<14; y++) {
if (fbits & (1<<y))
digitalWrite(radioPin, HIGH) ;
else
digitalWrite(radioPin, LOW) ;

delayMicroseconds(4045L) ;
}
}
}
}
}

void
encode(char *ch)
{
while (*ch != ‘\0’)
encodechar(*ch++) ;
}

void
setup()
{
Serial.begin(9600) ;
pinMode(radioPin, OUTPUT) ;
}

void
loop()
{
encode("K6HX QTH CM87UX TMP 72F PWR 500 MICROWATTS ") ;
}
[/sourcecode]

Let me know if you use this project for anything!

A micro-power Arduino Morse radio beacon

My G0UPL QRSS beacon is working pretty well, but is only putting out about 40mw of power, when it probably should be putting out 100mw. I was pondering oscillators in general, and (as I do often) surf for information and inspiration. I found both on Steve “Melt Solder” Weber’s website, in the form of a ATtiny based Wireless Morse thermometer. It was just a cool little circuit, so I tossed it together on a corner of my breadboard.

Works pretty well! I simulated the circuit using LTSpice before I built it, and found that it takes about 2ms for the oscillator to stabilize after powering down. At 12 wpm, each dit lasts 100ms, so it’s pretty clear that you can do a reasonable job of sending morse at pretty much any speed that most humans can use. To test the oscillator, I hooked up a pair of new D cells which were measured at 3.42 volts, and the current draw was a miserly 0.461 milliamperes for a maximum input power of around 1.5mw. The Arduino can supply 20ma, so it’s pretty obvious that you can drive this oscillator directly from an output pin. So, I used the Morse code sketch that I wrote a couple of years ago and voila! Instant beacon.

Regarding the legality, without any antenna, the effective radiated power of this antenna is incredibly low. I haven’t done any analysis of the circuit to state categorically that it falls inside the restrictions of Part 15 wireless devices, but I’d be shocked if it didn’t.

The “Hello World” of Arduino Programming: Fading RGB LEDs

Allright, I was playing Skyrim most of the day, and didn’t really have my brain firing at it’s highest level when I sat down and decided to try to put something together. We’ve all been there, right? I realized that I had some of this cool RGB LED strip that I ordered from Tayda Electronics, and it was just lying there, mocking me. So, I embarked upon quite easily the simplest things that I have ever done: cross fading RGB LEDs. Going boldly where everyone has gone before: it’s my motto.

First of all, complete credit must go to Lady Ada and her terrific tutorial on this very subject. I shamelessly copied what she did, and it worked out great. So go there, and read everything she had to say. I’ll just add a few comments:

  • The RGB strip cuts very easy, and strips pretty easy too. Be careful to use good ventilation when soldering leads onto this stuff though, as the plastic/rubbery stuff residue doesn’t smell very nice when heat is applied.
  • I went ahead and ordered the STP16NF06 MOSFETs that she recommended when I placed my last Digikey order. Price was about $.85 each, which is quite reasonable.
  • Tayda’s RGB strip seems like a very good deal, and you could easily use this trip for a wide variety of craft, art, or electronics projects.

To experiment, I cut off four segments (a little under a foot) and soldered on some leads, and wrapped them with electrical tape. Rather than swipe Lady Ada’s code, I quickly penned this up:

[sourcecode lang=”cpp”]
const int rPin = 3 ;
const int gPin = 5 ;
const int bPin = 6 ;

void
ramp(int pin, int from, int to)
{
int i ;

if (from < to) {
for (i=from; i<= to; i++) {
analogWrite(pin, i) ;
delay(5) ;
}
} else {
for (i=from; i>= to; i–) {
analogWrite(pin, i) ;
delay(5) ;
}
}
}

void
setup()
{
pinMode(rPin, OUTPUT) ;
pinMode(gPin, OUTPUT) ;
pinMode(bPin, OUTPUT) ;

analogWrite(rPin, 0) ;
analogWrite(gPin, 0) ;
analogWrite(bPin, 0) ;

ramp(rPin, 0, 255) ;
}

void
loop()
{

ramp(gPin, 0, 255) ;
ramp(rPin, 255, 0) ;
ramp(bPin, 0, 255) ;
ramp(gPin, 255, 0) ;
ramp(rPin, 0, 255) ;
ramp(bPin, 255, 0) ;
}
[/sourcecode]

And it worked the first time! Here’s the YouTube video:



It’s really easy to get the electronics working, and the Arduino and it’s software environment make it so simple. Too simple. I’m sorry to have embarrassed you with this, but perhaps you’ve had a craft or art project that could use some LEDs kicking around in your head, but you haven’t been kicked into action. Perhaps the easiness of this will inspire. If so, my work is done!

Have a good one.

My own lightly modified Arduino Basic

I’ve received a couple of requests for my own Arduino Basic modifications. They are pretty straightforward and small, but might be of some use, and I probably won’t have a chance to do any significant work for a couple of more weeks, so I thought I’d just toss them out there for consumption. This is all based upon Mike Field’s Tiny BASIC, and all the real credit should go to him. I added a few new commands to allow you to do some simple digital and analog I/O, and added a couple of added functions, including one that could be used to figure out how much free space you have left for BASIC programs.

My lightly modified Tiny BASIC source code, for Arduino 1.0

Changes include:

  • MODE PIN,[0|1] works like pinMode(pin, INPUT|OUTPUT). Note: to specify analog pins, you need to add 14 to the analog pin number (for the traditional Arduino, I have no idea what the MEGA does).
  • DWR pin,value and AWR pin, value act like digitalWrite and analogWrite.
  • Two additional functions (ARD(pin) and RD(pin), which should really have been DRD to match DWR) act like digitalRead and analogRead.
  • DELAY ms works like, well, delay(ms), duh.
  • The FREE(0) function returns how many bytes of program storage are left.
  • For reasons which aren’t clear to me, I modified the code to convert all lower case letters to upper case. Change it back if you like.

If you swipe this code and use it for something, let me know below: if someone makes use of my work, it gives me incentive to work on it harder. 🙂

Lunch with Ken Boak, the Nanode, and the evolution of the Arduino platform

Today, through a bit of serendipity involving twitter and the web, I managed to have lunch with Nanode designer Ken Boak, who happened to be on an unrelated visit to the Bay Area this week. We exchanged brief messages for the first time a couple of weeks ago, as I was intrigued with his idea of making a version of BASIC that ran on the Arduino/Nanode. He was kind enough to leave me with a couple of his latest version to experiment with. Compared to the v5 version that I got as a gift (purchased from wickeddevice.com) and assembled last week, these have a few cool new additions:

  • The screw terminals have been removed, and a small wireless module put in their place.
  • The board has a 32K static SRAM for storage.
  • It has a micro SD card slot on the bottom for long term storage.
  • It has a real time clock on the bottom.

Pretty darned cool! The new version seems better to me in every way., and I thank Ken for dropping some of them off for me (and also for a couple of coworkers who are interested in Arduino programming). I’ll be working to use them in a future project for sure, and if you are interested in having a highly interconnected Arduino compatible board to play with at a reasonable cost, I can recommend the Nanode (although I’d wait until Wicked Device starts carrying the new variety, the old V5 design lacks some of these cool features).

I see the Nanode as a cool evolution of the basic Arduino platform. The Arduino does a lot right, but there are a few things that bother me.

  • Cost.. Yeah, they are cheap. But let’s face it, they aren’t that cheap. The Uno (around $30) is just an ATmega328 (about $2 in quantity), an ATmega16u2 (again about $2) to provide USB, and then a handful of discrete components. You get a bunch of pins broken out, but no actual peripherals or connectors. No switches. No (or maybe one) LED. No additional memory or RTC. No SD card socket. My rather silly Arduino n’ Gameduino Satellite Tracker costs nearly $100 in parts, which makes the entire project less interesting, because it could be done as cheaply with more capable technology. The Nanode makes it a bit more tractable: it has a real time clock, and can even do NTP to set the time and fetch new elements over Ethernet. Thus, I think the nanode gives you some added value.
  • Flexibility in development environment. When I first started with the Arduino, it bothered me a little that I needed a sixty megabyte download of a programming environment to program this little controller with maybe just 16K of memory. Even if you just wanted to blink an LED, you had to compile and reflash code. Back in the days of my youth, we didn’t have the benefit of cool optimizing compilers, but we DID have the benefit of cool interactive programming environments. Ken’s idea of creating a Tiny BASIC programming environment brings some of that back. Sure, it’s not for everyone, but for simple experiments and education, the interactivity is useful. The technology that enables this for the Nanode is the inclusion of a 32K serial SRAM: we can store programs in this RAM and interpret code directly out of them.
  • Cheap, flexible peripherals. I have some Xbees to play with, but they are a bit spendy really. An Xbee costs about $22 or so last I checked, and to interface them with an Uno, you’ll need another shield which costs around $20 by itself. Tacking $45 onto a $30 board just to get wireless seems excessive. Ditto for Ethernet: the Ethernet Shield costs around $30-$40 (or even more) and basically doubles the cost of the Arduino. The Nanode includes Ethernet (using the rather inexpensive and easy to get ENC28J60 by Microchip) and uses some small and inexpensive RF modules. While these modules are perhaps not as capable as a full Xbee implementation, their cost and benefits are much lower, and their standard deployment on the Nanode board makes them convenient to use.
  • Compatibility with both shields and breadboards. Let’s face it: the Arduino Shield form factor is idiotic. Had the pins been laid out on a 0.1″ grid, you could have made shields with just ordinary 0.1″ proto board. Or, you could put pins on the bottom, and plug it directly into a standard solderless breadboard. The original design was a mistake. Let’s get over it, shall we? The Nanode does a good interim compromise: you can put headers in either position, which is awesome. But shields are already a bit of a compatibility nightmare: depending on what pins your shield uses and/or what voltages, it already may not work with a variety of seemingly compatible Arduino variants. The Nanode also wins on this case, because many of the most common shields that you would add are simply not necessary on the Nanode.

Don’t get me wrong: I don’t think that the Nanode will kill the market for other Arduino variants and form factors. In fact, I don’t think that it should: I like the fact that I can get Arduino Nanos, Arduino Pros, and Arduino Megas, but program them all from the same environment. But I think that peripheral additions that the Nanode provides gives added value, and if the Arduino is to compete in a world where things like the Raspberry Pi exist, I think we need to figure out how to add some additional value to the Arduino platform. I thank Ken and the other Nanode users for thinking about this stuff, and taking Arduino evolution in an interesting direction.

Nanode on the Web!

Well, to test my nanode‘s Ethernet capability, I put it on the web! Check it out by clicking this link. Hurrah! Not too impressive, but consider: it is dynamically generated on an eight bit microcontroller that costs about $35, Ethernet included. Perhaps not as cool as the Raspberry Pi, but unlike the Raspberry Pi, you can get a nanode.

But all is not well in the nanode/Ethernet universe either. There appears to be a veritable Pandora’s box of different libraries for Ethernet on the Arduino. This appears to have happened in part because the “official” Ethernet shield is based upon Wiznet W5100, while the nanode (and other inexpensive shields) appear to be based upon the Microchip ENC28J60. I can understand that to a certain degree (the Microchip part is less than $4 in unit quantities from Digikey, and is available in a through-hole PDIP package) but there appears to have been a bit of fragmentation of development even within the ENC28J60 code development. The nanode folks appear to be working with Jeelabs, so I used their EtherCard library which was available via git, and that seems to work pretty well (no changes, worked straight out of the box). The TCP/IP implementation limits HTTP responses to a single packet, so pages have to be small, but is probably sufficient to web-enable a great deal.

I was wondering: is there a more capable implementation that implements multiple packet responses? It seems like it would be helpful for many applications. Any experienced Arduino/Ethernet programmers can respond below. Does the official Ethernet shield provide that capability?

Christmas Kit: The Nanode

My wife is the best. She listens to me even when I yammer on about the most boring and geeky of topics, and does so with patience and grace. What’s more, she even remembers what I talk about, and I reap the benefits at Christmas time. I mentioned Nanode about a month back, because I thought it was cool: it’s an Arduino compatible kit that sells for about $35. “That’s not so good”, think you. But the cool thing is that it includes Ethernet. It also has a couple of other improvements. It has a double row of pin headers. The inner set are compatible with the (incredibly annoying) irregular Arduino shield spacing, while the outer set are on standard 0.1″ headers which allows you to solder in pins and use it easily on a breadboard. It also includes a space to solder an external SPI memory (SRAM, FRAM, or EEPROM) for additional expansion. Nifty.

Here is my assembled (and functional) nanode:

The instructions say 1.5 hours, it took me a little over two, because I went very slowly and methodically. It’s not difficult, but it’s a fair amount of soldering, and it’s easier to make sure that you do a good job as you go along, rather than spend it debugging later. There were only a couple of minor problems with the instructions: the 22pf ceramic caps shown in the pictorial are actually blue caps in my kit, and the what the instructions showed as blue were in fact little yellow caps. The later required a bit of lead manipulation to get them to fit tidily (their natural spacing was a bit wider than what the PCB has). I didn’t see where they specified to insert the LED’s current limiting 270 ohm resistor, but it was obvious to me at the end where it went. Getting the Ethernet socket in place took a little careful manipulation of the pins. But in the end, it all worked out okay, and when I powered it up, the LED blinked to indicate all was well. I moved my Tiny BASIC interpreter over, and after fixing a minor bug that I introduced the day before but didn’t catch, had it running basic programs to blink LEDS. Huzzah!

It seems like a good kit, really. But there are a few things I thought were odd. The place to solder the SOIC memory expansion is on the bottom. And, in spite of the fact the rest of the kit is entirely through hole, this one is surface mount. That’s not a big deal, but there is something that kind of bugs me: it requires other board modifications to make it work for most of the memory chips I’ve looked at. The problem is that there aren’t any level converters wired to it. The board itself is mixed voltage: 5v for the ATmega328, and 3.3v for the Microchip Ethernet, but this isn’t carried over to the memory expansion. To really make this work, you need to convert the board to run on 3.3V, and that requires hardware mods (replacing the regulators). And frankly, I wish they had. Yes, I understand that some shields need 5v, but the precedent of 3.3v Arduino Pro boards has already been set, and I suspect that much of the complexity of the existing board is in the resistive dividers that it needs. As it is, I think it will actually be simpler to do memory expansion via a small data board that rides on the headers, and includes the necessary level conversion. It also means I can use the PDIP version of the 23K256 chip, which is more breadboard friendly.

I was also surprised that they didn’t include an SD card slot. If you have an Ethernet, one of obvious ideas is to serve webpages, and you need some space to store them. The obvious thing would be a small SD card. I recognize that the board space is at a premium (especially since this kit uses through hole packages for ease of assembly), and this kit is inexpensive, but it still would have been nice. There is a spiffy Arduino-compatible but looks nice: the EtherTen by Freetronics, but to be fair, it costs twice as much and uses surface mount technology.

One other minor gotcha that I encountered was with the “FTDI cable” that came with my order from Wicked Devices. While it is described as an FTDI cable, when I plugged it into my MacBook that I use for Arduino development, it wasn’t recognized, in spite of the fact I’ve used other FTDI cables. It turns out that it’s not actually an FTDI cable: it’s based upon a USB UART converter made by Silicon Labs. Once I dug out the proper drivers, it worked fine, but it might have caused more confusion for beginners.

I will probably use this for more Tiny BASIC experimentation, and/or serving a simple website. If you’d like to get a kit that you can assemble that includes Ethernet, it’s hard to do better at the price point. You can also order them preassembled.

Addendum: I think I see what the problem was, and while I was confused about the specifications: my wife ordered this from Wicked Devices, who are listed as the US distributor for the Nanode. But Wicked Devices only carries the Nanode V5, which is not the most recent revision of the board. The “Nanode Classic” includes most of the changes that I thought the one I have should carry, as well as including an expansion board for RF, but is apparently not available from their US distributors (yet).

Tiny Basic running on Nanode – Christmas Challenge

As a followup to my post yesterday regarding Arduino BASIC, here’s a contest challenge to extend the Arduino basic to drive the Nanode, an Arduino compatible microcontroller board that extends the conventional Arduino with Ethernet and other cool features. The challenge is to make a good hack using Tiny BASIC: perhaps by extending the BASIC interpreter to include commands for accessing all the additional peripheral devices that the Nanode has. Neat!

Sustainable Suburbia: Tiny Basic running on Nanode – Christmas Challenge

Addendum: It only took me a few minutes of staring at the code to figure out how to add a “DELAY” command that can pause execution. It wouldn’t be hard to add equivalents to the digitalRead, digitalWrite, analogRead and analogWrite. Maybe I’ll give this a try myself over the next few days.

Arduino Basic

Edsger Dijkstra, Dutch computer scientist and winner of the 1972 Turing Award wrote:

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.

While I have respect for his great contributions to the field, in my opinion, this claim falls a bit far afield. In particular, nearly everyone who learned about computers in my generation seemed to through the path of BASIC. BASIC was the lingua franca of the microcomputer revolution, and while I now see it as rather quaint and ridiculous, it provided a step into computing for many people who found that they could indeed regenerate their brain cells in spite of their early exposure.

But does BASIC have any place in the modern world? Well, I must admit, the answer might be “maybe”. Little microcontrollers like the BASIC Stamp have been overshadowed a bit by the Arduino, but I still think that having an interactive interpreter that you can use to access a small computer makes some sense. Having a small language like Tiny BASIC, augmented by a few small additions to (say) allow you to generate sounds or control I/O pins makes a great deal of sense. Thus, without further justification, take a look at this project:

Arduino Basic – User's Wiki!

The code looks pretty nice and tidy, and should be easy to extend. It allows programs of up to 1.4K to be loaded into RAM, which sounds like a trivial amount, but it’s certainly enough to blink some leds, read and write some serial data, and generally exercise some of the capabilities of the chip. Neat project!

Project Completed: My $.99 Christmas LED hat, with ATtiny13 controller

Well, it’s done! Here’s my ATtiny13 controlled Christmas LED hat. It consists of an 8 pin, ATtiny13 microcontroller, a pair of 2N3904 transistors and some 1K resistors, a 7805 voltage regulator with two filter caps, and a switch, all mounted on a Radio Shack perfboard inside an Altoids tin. I’m rather pleased with the way it turned out. I always like it when a project goes from the breadboard to a final mounting in a box.



Addendum: Here’s the schematic for the entire circuit. Nothing too surprising, but you should be able to follow it if you need to.

Christmas Lights powered by an ATtiny13

While waiting for my bread to rise the other day, I moved my breadboard ATtiny13 circuit that blinked two leds to a small Radio Shack perfboard, added a couple of switching transistors (2N3904s) to power the LEDs, and built a small 7805 regulator (which doesn’t yet have any filter caps, I’ll get to that). But, I couldn’t resist powering it on. And after finding a small solder bridge (a hairlike strand that spattered and connected two of the microcontroller pins), it worked!

Hopefully this stuff will get mounted in a hat this weekend. Stay tuned for the final video.

Addendum: I received one request for the source code. It’s trivial. Here you go.

[sourcecode lang=”cpp”]
#define F_CPU 1200000UL

#include <avr/io.h>
#include <util/delay.h>

/*
* xmas.c
*
* A small program for the ATtiny13 that can control two strands of
* Christmas lights. I found a set of batter powered LED Christmas
* lights at CVS on sale for $.99 each. I took the lights out, and
* found that they consisted of two strands: one of 4 red and 4 yellow
* LEDs, and the other of 4 blue and 3 green LEDS. Each strand is
* wired in parallel and draws about 20ma at 3 volts. I have a few
* ATtiny13’s lying around, which can use between 2.7 and 5.5 volts supply.
* I think for this test, I’ll wire up a little 7805 regulator to provide
* 5V, and then control each strand with one of the two PWM outputs.
* If I want to drive the strings directly from the microcontroller,
* I’ll have to insert another 50 ohms of resistance to limit the current
* to around 20ma per pin. I could also add a 1K resistor and a small
* NPN transistor to drive each pin at the higher voltage. At 5V, the
* strand will draw about 120ma.
*/

#define LED0 PB0 /* pin 5 on the ATtiny13 */
#define LED1 PB1 /* pin 6 on the ATtiny13 */
#define SWITCH PB4 /* pin 3 on the ATtiny13 */

int brite, dir ;

int swd = 0 ;
int swu = 0 ;

int
main(void)
{
DDRB |= (1 << LED0) ; /* set both LEDs as outputs */
DDRB |= (1 << LED1) ;
DDRB &= ~(1 << SWITCH) ; /* and the switch as an input */
PORTB |= (1 << SWITCH) ; /* and activate the internal pull up */

/* This configures the PWM outputs to be in "Fast PWM" mode. */
TCCR0A |= (1 << WGM01) | (1 << WGM00) ;

/* Timer is clocked at F_CPU/8 */
TCCR0B |= (1 << CS01) ;

/* COM01 COM00
* 0 0 | normal port operation, output compare disconnected
* 0 1 | toggle output on compare match
* 1 0 | clear output on compare match
* 1 1 | set output on compare match
*/

TCCR0A |= ((1 << COM0A1)) ;
TCCR0A |= ((1 << COM0B1)) ;
OCR0A = 0;
OCR0B = 0;

for (;;) {
/* SOLID ON */
for (;;) {
OCR0A = 0xff ;
OCR0B = 0xff ;
_delay_ms(1) ;
if ((PINB & (1<<SWITCH)) == 0)
break ;
}
while ((PINB & (1<<SWITCH)) == 0) ;

/* CROSS FADE */
brite = 0 ;
dir = 1 ;
for (;;) {
OCR0A = brite ;
OCR0B = brite ^ 0xFF ;
brite += dir ;
if (brite == 0 || brite == 255)
dir = -dir ;
_delay_ms(2) ;
if ((PINB & (1<<SWITCH)) == 0)
break ;
}
while ((PINB & (1<<SWITCH)) == 0) ;

/* BLINK */
brite = 0xff ;
for (;;) {
OCR0A = brite ;
OCR0B = brite ;
_delay_ms(500) ;
brite ^= 0xff ;
if ((PINB & (1<<SWITCH)) == 0)
break ;
}
while ((PINB & (1<<SWITCH)) == 0) ;

/* CROSS BLINK */
for (;;) {
OCR0A = 0xff ;
OCR0B = 0 ;
_delay_ms(500) ;
if ((PINB & (1<<SWITCH)) == 0)
break ;
OCR0A = 0 ;
OCR0B = 0xff ;
_delay_ms(500) ;
if ((PINB & (1<<SWITCH)) == 0)
break ;
}
while ((PINB & (1<<SWITCH)) == 0) ;

}
}
[/sourcecode]

Carmen makes an Arduino Stoplight

Today, Carmen decided that she wanted to give Arduino programming a try. She’s an experienced programmer, but had never tried any of this small embedded stuff, and knows relatively little about electronics, but with a little direction from me, she got the Arduino development environment installed, and we did a bit of playing around. I showed how we could blink an LED, and then showed her how to read switches and even drive a servo motor. She then walked through some of Lady Ada’s tutorials and ended up scavenging a red, green, and yellow LED from some old throwies we had, and coding up a little stop light application:

Here’s the code:

[sourcecode lang=”cpp”]
// Stoplight
// Introductory Arduino program – Carmen & Mark VandeWettering 12/11/11
// with thanks to : http://www.ladyada.net/learn/arduino/lesson3.html
//
int redPin = 12; // Red LED connected to digital pin 12
int greenPin = 11; // Green LED connected to digital pin 11
int yellowPin = 13; // Yellow LED connected to digital pin 13
int delayTime = 1000; // initiate a delaytime amount here

void setup() // run once, when the sketch starts
{
pinMode(redPin, OUTPUT); // sets the digital pin as output
pinMode(greenPin, OUTPUT); // sets the digital pin as output
pinMode(yellowPin, OUTPUT); // sets the digital pin as output
}

void loop() // run over and over again
{
digitalWrite(redPin, HIGH); // sets the Red LED on
delay(delayTime); // waits the delayTime
digitalWrite(redPin, LOW); // sets the Red LED off
digitalWrite(greenPin, HIGH); // sets the Green LED on
delay(delayTime*5); // waits the delayTime * 5
digitalWrite(yellowPin, HIGH); // sets the Yellow LED on
digitalWrite(greenPin, LOW); // sets the Green LED off
delay(delayTime); // waits the delayTime
digitalWrite(yellowPin, LOW); // sets the Yellow LED off (and continue the loop)
}
[/sourcecode]

If you have any experience with programming at all, the Arduino should be pretty easy. If you don’t, it will take a bit more work, but it’s still doable. Give it a try!

The “Hello World” of Servo Programming on the Arduino

This morning I woke up around 5:30AM to catch the lunar eclipse. It was pretty nice: totality began around 6:05AM and the moon became incredibly dark and red. But 30 minute later, it had progressed low enough that it entered the offshore clouds that signaled the arrival of the morning fog. So, I came back, and went to bed.

When I woke up, I knew that I wanted to try something easy with my Arduino. A few weeks ago, I was in a Radio Shack (gasp!) and saw that they carried the Parallax servos (rebranded Futaba servos, if memory serves) so I picked one up, thinking “I should hook this to an Arduino, because I’ve never done that.”

Well, so I did.

So… what can I do with this?

I could use it to pan a webcam back and forth, perhaps under control of a web page.

I could hook up an ultrasonic sensor, and scan for obstacles.

I could rotate an object, and create an animated gif allowing you to see all sides

And ultimately, I could do some kind of animatronic thing.

I know, it’s not very impressive. But it’s a start. And as I’ve heard before, the journey of a thousand miles begins with a single step.

Dissecting a set of $.99 battery powered Christmas lights…

I was over at the CVS repository today, and saw that they had some small strings of fifteen LED Christmas lights on sale for a paltry $.99 (if you used your CVS discount card). That was simply too much to resist, so I got a couple of strings, and thought that I would use them for a Christmas related electronics project of some sort.

And, of course, it provides a reason to test your basic electronics knowledge as well. (Forgive my more technologically saavy readers, this is gonna be pretty basic, but I found it fun to go through the mental exercise).

First of all, here are photos of the box they came in, just so we are all on the same page:

When you pop them open, you’ll find a small greenish plastic box that holds the batteries, and a string of fifteen LEDs wired into it with green wire. The box has a small switch on it, which if you stare at you’ll see has both an OFF and an ON position, but it can also be set half way to enable a blinking function. Popping two batteries into the case and flipping the switch had the desired effect: Christmas lights!

So, I started staring at them. There are three wires coming out of the battery box. Each LED appears to have five wires operating in its vicinity. One bypasses the LED, and four other wires sprout from each LED (except for the very last one on the string, which just has two connections. A few minutes of thinking reveals that the LEDS must be wired in parallel, with a circuit that looks very much like this:

Ed. note: Mike pointed out that the original schematic was in error. This has been updated.

The lines labelled A and B are just two power lines: each carries power to half of the LEDs. In the “blink” mode, power is applied to only half of the LEDs at a time. Staring inside the box, it appears that there are two discrete plastic cased transistors wired together: my guess is that they are a classic multivibrator circuit. I’ll verify that later.

Okay, enough of boring reality, let’s try to get to the exciting math.

First of all, the package says that we can get “120 hours or more” from one (presumably) set of alkaline batteries. That seems like excellent battery life, but how realistic is it?

First of all, how much power is in a pair of AA alkalines? Wikipedia says we have about 1800-2600 mAh. I bought some cheap AAs from CVS, so let’s say we are in the middle of the range, about 2200 mAh. Naively, to last 120 hours, the current draw can only be 2200 / 120 or about 18ma (this isn’t quite right, but it’s close) which works out to about 1.2 ma of current per LED (did I mention that the LEDs are wired in parallel?). The total power consumed is about 50mw. If we assume the voltage drop from the LEDs is around 2 volts, we need we need to have a series resistance of about 1 v / 18ma or about 55 ohms. It can be a tiny one, since the power consumed is very small.

All this presumes that they were all in parallel. In reality only half the current flows in each of the A and B circuits, so in blink mode, I suspect the power consumed will be cut by one half (ignoring the power consumed by the multivibrator, which should be very low).

But here’s the good thing! The current draw is low enough that it should be possible to power these lights directly from an Arduino, without any additional switching transistors or the like. My intention is to power each of the two strands with a PWM signal, to allow independent fading and glowing.

But I don’t trust my math enough (nor the specified 120 hour life) to just hook this up randomly, so I’ll be doing a little dissection when I get home tonight, to verify that my calculations are roughly correct. Stay tuned!

Addendum: I took a closer look at the tiny circuit board inside the battery case, and was somewhat surprised to see its inner workings hidden under a blob of epoxy. Two driver transistors do appear on the top side. As far as I can tell, no caps or inductors are visible anywhere:

Addendum2: Last night I put my multimeter in series with the batteries in this circuit, and measured a current draw of 40 milliamps in its “steady”, non-blinking mode. That means that the 120 hours on two AAs quoted on the box is likely a fiction, a life of more like 55 hours would seem to be more likely. In blinking mode, the current draw seemed to vary between 20ma and 30ma, but my meter wasn’t able to integrate the current to a stable value.

I’m thinking that I’ll resurrect the circuit that I used for my ATtiny13 powered pumpkin to drive these LEDs. The ATtiny13 has two PWM channels, which could be used to drive the two LED channels separately, allowing some cool color fading effects. I could probably even salvage the case to hold the batteries. Stay tuned.