brainwagon "There is much pleasure in useless knowledge." — Bertrand Russell

28Nov/092

Recommendations for a little LTSpice design project?

Well, one of the advantages of getting a new Windows 7 laptop is that I now have a much nicer environment for running LTSpice. Does anyone have any ideas of a good, simple project that I could do to help me learn the ropes of LTSpice, and which I could also build for real to test my understanding? Perhaps something like a VFO + buffer amplifier + power amplifier chain, that could be done in steps? The simple transmitter in EMRFD would seem to be a reasonable choice, but the oscillator is crystal controlled, and I've heard that LTSpice can have some difficulty simulating these kind of "high Q" circuits.

What would you all suggest?

Filed under: Amateur Radio 2 Comments
27Nov/090

A couple of days of WSPR 2.0

Left my FT-817 beaconing for the last 48 hours or so, mostly on 40m, and got some interesting DX, including someone I think I never reached before, KG6DX in Guam.

Timestamp Call MHz SNR Drift Grid Pwr Reporter RGrid km az
 2009-11-27 07:32   VK3AMW   7.040092   -19   0   QF22ir   5   K6HX   CM87ux   12668   59 
 2009-11-27 07:08   K6HX   7.040107   -23   0   CM87ux   5   VK3AMW   QF22ir   12668   240 
 2009-11-27 08:58   K6HX   7.040107   -24   0   CM87ux   5   VK2UB   QF59vk   11713   243 
 2009-11-27 09:12   VK2UB   7.040153   -12   0   QF59vk   2   K6HX   CM87ux   11713   55 
 2009-11-27 15:18   K6HX   7.040112   -24   0   CM87ux   5   VK4YEH   QG62ll   11423   245 
 2009-11-27 12:48   VK4YEH   7.040014   -23   0   QG62ll   5   K6HX   CM87ux   11423   54 
 2009-11-27 07:58   ZL2FT   7.040108   -26   0   RF70mb   5   K6HX   CM87ux   10758   45 
 2009-11-27 08:10   K6HX   7.040121   -26   0   CM87ux   5   ZL2FT   RF70mb   10758   223 
 2009-11-27 07:26   CX2ABP   7.040096   -26   0   GF15wc   10   K6HX   CM87ux   10587   314 
 2009-11-27 08:10   K6HX   21.096114   -19   0   CM87ux   5   KG6DX   QK23kl   9334   282 
 2009-11-27 06:58   KG6DX   7.040074   -10   -1   QK23kl   10   K6HX   CM87ux   9334   52 
 2009-11-27 09:08   JE6EFV   7.040022   -20   0   PM74so   50   K6HX   CM87ux   8642   52 
 2009-11-27 08:50   K6HX   7.040116   -13   0   CM87ux   5   JQ2WDO   PM95gi   8374   304 
 2009-11-27 08:54   JQ2WDO   7.040082   -15   0   PM95gi   5   K6HX   CM87ux   8374   54 
 2009-11-27 09:32   UA0ZEO   7.040082   -14   0   QO93ec   10   K6HX   CM87ux   6068   72 
 2009-11-28 01:48   I5FIG   7.040030   -20   -4   GM03   0.001   K6HX   CM87ux   5621   294 
 2009-11-27 07:40   K6HX   7.040107   -22   0   CM87ux   5   VE1VDM   FN85ij   4857   61 
 2009-11-27 13:36   K6HX   7.040110   -24   0   CM87ux   5   VE2EXB   FN35hi   4080   62 
 2009-11-27 08:10   K6HX   7.040108   -19   0   CM87ux   5   KC2STA   FN32bv   4077   67 
 2009-11-27 06:46   KC2STA   7.040090   -23   0   FN32bv   5   K6HX   CM87ux   4077   279 
 2009-11-27 06:42   NU3E   7.040049   -24   0   FN20pb   5   K6HX   CM87ux   4068   282 
 2009-11-27 06:48   K6HX   7.040110   -20   0   CM87ux   5   NU3E   FN20pb   4068   71 
 2009-11-27 11:10   N2NOM   7.040135   -13   0   FN22bg   5   K6HX   CM87ux   3926   279 
 2009-11-27 11:38   K6HX   7.040104   -8   0   CM87ux   5   N2NOM   FN22bg   3926   68 
 2009-11-27 07:08   K6HX   7.040106   -16   0   CM87ux   5   K3BXO   FM19ma   3905   74 
 2009-11-27 07:24   K3BXO   7.040093   -26   0   FM19ma   0.01   K6HX   CM87ux   3905   283 
 2009-11-28 05:16   WB4KLJ   7.040126   -20   0   FM18ku   2   K6HX   CM87ux   3895   283 
 2009-11-27 07:30   K6HX   7.040107   -28   0   CM87ux   5   K1BZ   FM19   3887   73 
 2009-11-27 13:34   VE3EWW   7.040145   -26   0   FN03   0.2   K6HX   CM87ux   3653   275 
 2009-11-27 22:50   K6HX   7.040104   -27   0   CM87ux   5   N4AU   EM62vp   3306   89 
 2009-11-27 22:54   N4AU   7.040160   -28   0   EM62vp   1   K6HX   CM87ux   3306   291 
 2009-11-27 06:44   NU8D   7.040091   -9   -1   EM79uh   5   K6HX   CM87ux   3279   280 
 2009-11-27 07:08   K6HX   7.040109   -18   0   CM87ux   5   NU8D   EM79uh   3279   75 
 2009-11-28 01:08   W3PM   7.040086   -25   0   EM64or   1   K6HX   CM87ux   3180   287 
 2009-11-27 23:00   K6HX   7.040107   -25   0   CM87ux   5   NG5H   EM25ju   2411   87 
 2009-11-27 11:08   N0SF   7.040152   -25   0   EM26   5   K6HX   CM87ux   2410   282 
 2009-11-28 01:42   935DTE   7.040136   -20   1   DL61   0.02   K6HX   CM87ux   2346   325 
 2009-11-28 00:20   K0FT   7.040055   -5   0   EM17   5   K6HX   CM87ux   2214   279 
 2009-11-28 00:24   K6HX   7.040137   -23   0   CM87ux   5   K0FT   EM17   2214   84 
 2009-11-27 06:44   VE5MU   7.040063   -3   -1   DO70qk   20   K6HX   CM87ux   1966   232 
 2009-11-27 06:48   K6HX   7.040110   -12   -1   CM87ux   5   VE5MU   DO70qk   1966   40 
 2009-11-28 03:24   VE6OG   7.040150   -4   0   DO33fn   20   K6HX   CM87ux   1858   205 
 2009-11-28 00:24   K6HX   7.040105   -16   0   CM87ux   5   VE6OG   DO33fn   1858   18 
 2009-11-27 14:02   W6YQ   7.040090   +2   0   DN84ic   10   K6HX   CM87ux   1728   253 
 2009-11-27 19:10   KE5ZGI   7.040077   -19   0   DM72aw   5   K6HX   CM87ux   1579   295 
 2009-11-27 19:02   K6HX   7.040104   -24   0   CM87ux   5   KE5ZGI   DM72aw   1579   106 
 2009-11-28 01:20   W0AEW   7.040061   -21   0   DN70ke   1   K6HX   CM87ux   1499   266 
 2009-11-28 02:28   K6HX   7.040106   -20   0   CM87ux   5   W0AEW   DN70ke   1499   75 
 2009-11-28 03:26   K6HX   7.040063   -12   0   CM87ux   5   WA7HL/P   DM51ck   1353   119 
 2009-11-28 05:10   N4ABN   7.040047   0   0   DM59pd   5   K6HX   CM87ux   1187   268 
 2009-11-28 05:14   K6HX   7.040103   -13   0   CM87ux   5   N4ABN   DM59pd   1187   80 
 2009-11-28 03:02   K6HX   7.040118   -16   0   CM87ux   5   N7SET   CN87us   1089   0 
 2009-11-28 02:56   N7SET   7.040081   -4   0   CN87us   5   K6HX   CM87ux   1089   180 
 2009-11-28 02:28   K6HX   7.040153   -24   0   CM87ux   5   WA7NWP   CN87wq   1080   1 
 2009-11-28 02:42   WA7NWP   7.040047   -6   -1   CN87wq   10   K6HX   CM87ux   1080   181 
 2009-11-27 06:48   K6HX   7.040113   -1   0   CM87ux   5   W7RDP   CN87xo   1070   1 
 2009-11-27 06:54   W7RDP   7.040163   -7   0   CN87xo   5   K6HX   CM87ux   1070   181 
 2009-11-27 07:18   K6HX   7.040121   -18   2   CM87ux   5   K7EK   CN87tb   1010   360 
 2009-11-27 09:54   WA7KGX   7.040034   +4   0   CN85no   100   K6HX   CM87ux   849   177 
 2009-11-27 10:00   K6HX   7.040100   -8   0   CM87ux   5   WA7KGX   CN85no   849   357 
 2009-11-28 01:34   K6HX   7.040099   -7   0   CM87ux   5   W6NIA   DM13ed   683   140 
 2009-11-28 01:28   W6NIA   7.040099   -6   0   DM13ed   2   K6HX   CM87ux   683   323 
 2009-11-27 08:50   K6HX   7.040111   -22   0   CM87ux   5   AC7SM   DM26ie   652   106 
 2009-11-27 06:50   AC7SM   7.040110   -20   0   DM26ie   5   K6HX   CM87ux   652   290 
 2009-11-27 07:04   W6PDD   7.040056   -19   0   DM04nf   2   K6HX   CM87ux   518   325 
 2009-11-27 07:18   K6HX   7.040094   -20   0   CM87ux   5   W6PDD   DM04nf   518   143 
 2009-11-27 06:42   WB6RQN   7.040094   -9   0   CM98mq   50   K6HX   CM87ux   140   236 
 2009-11-27 07:08   K6HX   7.040106   -19   0   CM87ux   5   WB6RQN   CM98mq   140   55 
 2009-11-27 21:28   K6HX   7.040104   -14   0   CM87ux   5   K6PJV   CM98iq   118   48 
 2009-11-27 20:20   K6PJV   7.040096   -8   0   CM98iq   5   K6HX   CM87ux   118   228 
 2009-11-27 14:18   K6HX   7.040098   -18   0   CM87ux   5   N6MQL   CM98ho   106   49 
 2009-11-27 06:52   N6MQL   7.040120   -20   0   CM98ho   5   K6HX   CM87ux   106   229 
 2009-11-27 20:42   AA7EE   7.040088   -15   0   CM87ut   2   K6HX   CM87ux   19   0 
 2009-11-27 20:56   K6HX   7.040112   -25   0   CM87ux   5   AA7EE   CM87ut   19   180 
 2009-11-27 07:06   NN6RF   7.040069   -15   0   CM87uw   2   K6HX   CM87ux   5   0 
 2009-11-27 07:08   K6HX   7.040111   -8   0   CM87ux   5   NN6RF   CM87uw   5   180 
Filed under: Amateur Radio No Comments
27Nov/090

New Google Voice Number

Courtesy of Zeid, I finally got an invite to use Google Voice. I'll write more about this when I figure more about it, but at a minimum, it gives you a real phone number (amazingly, for free) which anyone can call and leave voice mail. You can configure it to ring a different phone (say, your cell phone) or send it directly to voicemail. You can access your voice mail in the conventional way, or by using a computer online. It even automatically transcribes the message into text! Very cool, and thanks Zeid for hooking me up.

Here's an example of what you can do. This is a little flash widget. If you click on it, you can type your own name and a number that you can be reached at. Google will then call you back and hook me to my voicemail (or, if I configured it differently, ring my cell). Give it a try if you like. I'm just starting this, and it seems that you can't select the "Conceal my number" checkbox if you want this to work. It also won't work from international numbers.

Addendum: Here is an example of what Google Voice can do with a voicemail message.

Filed under: General No Comments
26Nov/091

FreeBSD 8.0 is released…

I've been a long time fan of FreeBSD, going all the way back to the 1.1.5.1 days (and used regular BSD going back even further). Today, I still have a server which runs FreeBSD, as well as another desktop which is running Ubuntu. Which one I prefer is not really something I choose to argue (or even spend much time thinking about) but I did notice that FreeBSD 8.0 was just released.

FreeBSD 8.0-RELEASE Release Notes.

26Nov/090

Back on WSPR today…

Well, I finally dug up all the cables I needed and hooked up my little HP netbook to my radio again, and got it going with the new WSPR 2.0 software. As of this moment, I'm beaconing out at 5w on the traditional 30m watering hole, and getting pretty good domestic spots. I might try shifting to a different band a bit later in the day (maybe 15m, I've been curious about how good 15 has been lately).

17 spots:

Timestamp Call MHz SNR Drift Grid Pwr Reporter RGrid km az
 2009-11-26 16:46   K0VM   10.140263   -12   0   EN42db   1   K6HX   CM87   2710   270 
 2009-11-26 16:46   W9HLY   10.140114   -17   0   EN70mt   1   K6HX   CM87   3279   276 
 2009-11-26 16:44   K6HX   10.140207   -19   0   CM87ux   5   NG5H   EM26ja   2406   87 
 2009-11-26 16:44   K6HX   10.140221   -24   0   CM87ux   5   KH7HJ   BL01xj   3881   252 
 2009-11-26 16:44   K6HX   10.140160   -21   1   CM87ux   5   W4SWQ   FM06   3798   79 
 2009-11-26 16:44   K6HX   10.140264   -15   0   CM87ux   5   WA7NWP   CN87wq   1080   1 
 2009-11-26 16:44   K6HX   10.140223   -15   0   CM87ux   5   K0VM   EN42db   2629   70 
 2009-11-26 16:44   K6HX   10.140206   -16   0   CM87ux   5   W9HLY   EN70mt   3199   72 
 2009-11-26 16:42   W3HH   10.140159   -23   0   EL89vb   1   K6HX   CM87   3878   295 
 2009-11-26 16:42   KD0BIK   10.140191   -8   0   DM79np   5   K6HX   CM87   1595   267 
 2009-11-26 16:42   W3GXT   10.140206   -24   0   FM19ol   2   K6HX   CM87   3988   282 
 2009-11-26 16:40   KH7HJ   10.140128   -20   0   BL01xj   10   K6HX   CM87   3801   54 
 2009-11-26 16:40   KC8YJJ   10.140214   -19   0   EN90pl   5   K6HX   CM87   3639   279 
 2009-11-26 16:38   WA7KGX   10.140131   +12   0   CN85no   100   K6HX   CM87   904   181 
 2009-11-26 16:36   K6HX   10.140209   -20   0   CM87ux   5   KD0BIK   DM79np   1518   78 
 2009-11-26 16:36   K6HX   14.097097   +2   0   CM87ux   5   WA7KGX   CN85no   849   357 
 2009-11-26 16:36   K6HX   10.140178   -1   0   CM87ux   5   WA7HL/P   DM51ck   1353   119 
Filed under: Amateur Radio No Comments
22Nov/090

SO-67 Audio…

John, K8YSE recorded a North American pass of SO-67 (the new South African ham satellite) and posted the audio on his website. It appears the audio quality is actually pretty good. I'll have to be trying it out fairly soon.

SO-67_22Nov2009_141052z.mp3

22Nov/094

A simple, naive implementation of a MasterMind solver

Okay, I woke up this morning, and decided to code up a version of a MasterMind solver. About fifteen minutes later, I had this tremendously slow implementation, which nevertheless seems to solve patterns very pretty quickly (averaged just 4.71 guesses in the short run of 100 trials that I just ran. It's tremendously slow though, for reasons which I should have guessed before I wrote it. Nevertheless, it does work fast enough that if you wanted to write a Mastermind solver, it would work just fine.

Here's the idea. Start by simply trying to guess the code by picking one at random. Assuming that you didn't win, you need to generate a new guess. Let's generate one and pretend that it was the secret. If you evaluate it against all the previous guesses you make, it would need give the same results. If it doesn't, it can't be the secret, so don't use it as your guess. Try a different one.

That's it. Of course the reason it's slow is that when you get to the end, very few of the random choices you'll make will match all the previous results (there are 1296 possibilities in the 6,4 version of classic Mastermind), so you might have to try lots and lots and lots of guesses before you find the consistent one. The better way would be to use a list of all possible codes, and strike out the ones in each round that are inconsistent with the previous guesses. Then you can select among all consistent codes. I'll write up that optimization shortly, which should speed up the code by several hundred times. But this one does work... check it out.

#!/usr/bin/env python
#
# A naive implementation of the game MasterMind, to test some ideas 
# that I learned in a brief scan of some of the known literature.
#

import random
from sets import Set

# traditional Mastermind uses six different colors, not exactly certain
# what they were, so I chose Red/Yellow/Blue/Orange/Green/Purple...

colors = ['R', 'Y', 'B', 'O', 'G', 'P']


# generate a random secret code (or guess)

def randomcode():
        return ''.join([random.choice(colors) for i in range(4)])

def evaluate(guess, secret):
        b, w = 0, 0
        gs, ss = Set([]), Set([])
        for i in range(4):
            if guess[i] == secret[i]:
                b = b + 1 
            else:
                gs.add(guess[i])
                ss.add(secret[i])
        return b, len(gs.intersection(ss))

def solve(secret):
        history = []
        guess = randomcode()
        nguesses = 1
        while True:
                b, w = evaluate(guess, secret)
                history.append((guess, b, w))
                print guess, b, w
                if b == 4:
                        break   # we solved it...
                # generate a new random guess, consistent with
                # all the previous guesses.
                nguesses = nguesses + 1 
                while True:
                        guess = randomcode()
                        consistent = True
                        for g, b, w in history:
                                nb, nw = evaluate(guess, g)
                                if nb != b or nw != w:
                                        # nope, not consistent
                                        consistent=False
                                        break
                        if consistent:
                                break
        print
        return nguesses

ROUNDS = 100
totalguesses = 0

for x in range(ROUNDS):
        totalguesses = totalguesses + solve(randomcode())

print "average number of guesses was %.2f" % (float(totalguesses)/ROUNDS)

Addendum: I coded up the optimization that I mentioned above, and it seemed not to help that much. Run time dropped from 21 seconds to 17 or so. Not very good. Perhaps I don't know what's going on here. Then again, I still haven't had any caffeine this morning, so perhaps my puzzler isn't quite up to speed yet.

21Nov/090

Investigations into the Master Mind Board Game

Over at the Programming Praxis blog, the task of the day is to write a program to solve the game Mastermind. Mastermind is actually a fairly interesting game mathematically speaking, and has a fairly rich set of mathematics behind it, and yet it's actually small enough to analyze easily using modern computing power. I might try to use this as a test program to try out the new Go programming language from Google. In the mean time, here are some links:

Investigations into the Master Mind Board Game

Here's a link to computer science luminary Don Knuth's paper The Computer As Master Mind

21Nov/090

Orion Nebula

IMG0012
IMG0012
21st November, 2009


Dan Lyke of flutterby drew my attention to the astrometry pool on Flickr. If you upload an astrophotograph to this group, a process comes by later and tries to identify the stars in your image, and adds annotations and labels to it. Very nifty. Check it out. Try clicking the image above, and it will send you to the Flickr page with the annotations.

Filed under: Astronomy No Comments
20Nov/090

Creating an Anaglyph from a Stereograph

Back in 2005, I wrote a little blog post about creating stereo images with the GIMP along with a screencast. Little did I know that a couple of years later, I'd end up learning far more about stereo imaging when I became the stereo rendering lead for Toy Story and Toy Story 2. This post has circulated back to the sidebar in my "years ago on this date" section, so I thought I'd resurrect this video (the links were broken) and even though it is dated, it's still pretty good information, so check I thought I'd upload it to blip.tv (I would have done Youtube, but it's 11 minutes long, and Youtube rejected it) and make it available again. Enjoy!



Filed under: 3D No Comments
20Nov/091

Handmade Cigar Box Instruments – Ukuleles – Banjos – Guitars

It's been a while since I posted a link to anything related to home made musical instruments, so when I ran across this page this morning, I thought of my friend Tom and his love of quirky instruments, and decided to pass it along. Papa's Boxes sells both kits and completed ukuleles and banjos made from cigar boxes. Pretty neat folk instruments. Check it out.

Handmade Cigar Box Instruments - Ukuleles - Banjos - Guitars

Filed under: Music 1 Comment
18Nov/090

Homemade Thin-Film Transistor Experiments

Another link to some interesting experiments on building your own thin-film transistors.

And a Quarter Gets You Coffee » Homemade Thin-Film Transistor Experiments

Addendum: Of course any mention of building your own transistors would be remiss if it didn't mention hacker-savant Jeri Ellsworth. She did an amazing job fabricating her own semiconductor devices, and in this video from Metalab, explains some of the basics.


Lecture Given At Metalab About Build A Home Chip Lab from Jeri Ellsworth on Vimeo.

17Nov/090

VK7 OPTICAL COMMUNICATIONS EXPERIMENTATION

While listening to the "This Week In Amateur Radio" podcast this morning, I heard reference to a new record setting non-line-of-sight one way contact that took place over optical wavelengths. A sucessful transmission over a distance of 288 kilometers was achieved by using an LED based transmitter. The report (PDF) provides many interesting details, such as their use of a GPS locked sound card to permit received signals to be resolved to just a milliHertz or so. Nice!

VK7 OPTICAL COMMUNICATIONS EXPERIMENTATION

Here is some video of the transmitter in action. The floodlight that you see is generated by an array of 60 Luxeon LEDs, collimated by Fresnel lenses. Each LED is about 3.3 watts. Pretty cool.


httpv://www.youtube.com/watch?v=vu-5KNVjNO4

Filed under: Amateur Radio No Comments
16Nov/090

Mandelbulb formula…

Without further explanation, here's Daniel White's "Mandelbulb" formula.

(x, y, z)n = rn (cos(n θ) cos(n φ), sin(n θ) cos(n φ), -sin(n φ))
r = sqrt(x2 + y2 + z2)
θ = atan2(y, x)
φ = atan2(z, sqrt(x2+y2))

14Nov/0928

Another try at an Arduino Based Morse Beacon

Back in 2008, I blogged about a stupid program I wrote to implement a Morse Beacon on the Arduino. I couldn't find that code, and it was stupid anyway, so I went ahead and implemented a new version, with an added improvement: it doesn't hardcode dots and dashes, it has a built in table. Right now, the message is hardcoded into the program, but in the future, I'll probably work up a trivial command language so you can change the message and speed, and store the message in the on-chip eprom. On the other hand, doing it by modifying the program source code isn't really very much harder than getting a terminal to talk to your Arduino (it might even be easier) so this still might be the best way.

Basically, this just puts a logic high state on output pin #13 whenever the keydown should occur, and low when it is released. My Arduino is one of the older ones, so I needed to put an LED in myself, but I understand more modern ones have a built in LED. You could use whatever output pin you like though, with the obvious modification. To turn it into a full fledged keyer, you just need a transistor to handle the switching. On this model of Arduino, pin 13 has a 1K resistor in series to current limit, so you should just be able to put in any NPN transistor (base in pin 13, emitter to ground) and then use the collector/emitter to key the transmitter (I might also think about using an optoisolator, just to be safe).

This is overkill in a lot of ways: the program, sloppily as it is written only takes about 1/7 of the memory on my Arduino, and modern ones have double the space. We could do the same with a very small Atmel. But Arduinos are available and versatile, and have considerable potential. Worth playing with.

//
// Simple Arduino Morse Beacon
// Written by Mark VandeWettering K6HX
// Email: k6hx@arrl.net
// 
// This code is so trivial that I'm releasing it completely without 
// restrictions.  If you find it useful, it would be nice if you dropped
// me an email, maybe plugged my blog @ http://brainwagon.org or included
// a brief acknowledgement in whatever derivative you create, but that's
// just a courtesy.  Feel free to do whatever.
//


struct t_mtab { char c, pat; } ;

struct t_mtab morsetab[] = {
  	{'.', 106},
	{',', 115},
	{'?', 76},
	{'/', 41},
	{'A', 6},
	{'B', 17},
	{'C', 21},
	{'D', 9},
	{'E', 2},
	{'F', 20},
	{'G', 11},
	{'H', 16},
	{'I', 4},
	{'J', 30},
	{'K', 13},
	{'L', 18},
	{'M', 7},
	{'N', 5},
	{'O', 15},
	{'P', 22},
	{'Q', 27},
	{'R', 10},
	{'S', 8},
	{'T', 3},
	{'U', 12},
	{'V', 24},
	{'W', 14},
	{'X', 25},
	{'Y', 29},
	{'Z', 19},
	{'1', 62},
	{'2', 60},
	{'3', 56},
	{'4', 48},
	{'5', 32},
	{'6', 33},
	{'7', 35},
	{'8', 39},
	{'9', 47},
	{'0', 63}
} ;

#define N_MORSE  (sizeof(morsetab)/sizeof(morsetab[0]))

#define SPEED  (12)
#define DOTLEN  (1200/SPEED)
#define DASHLEN  (3*(1200/SPEED))

int LEDpin = 13 ;

void
dash()
{
  digitalWrite(LEDpin, HIGH) ;
  delay(DASHLEN);
  digitalWrite(LEDpin, LOW) ;
  delay(DOTLEN) ;
}

void
dit()
{
  digitalWrite(LEDpin, HIGH) ;
  delay(DOTLEN);
  digitalWrite(LEDpin, LOW) ;
  delay(DOTLEN);
}

void
send(char c)
{
  int i ;
  if (c == ' ') {
    Serial.print(c) ;
    delay(7*DOTLEN) ;
    return ;
  }
  for (i=0; i<N_MORSE; i++) {
    if (morsetab[i].c == c) {
      unsigned char p = morsetab[i].pat ;
      Serial.print(morsetab[i].c) ;

      while (p != 1) {
          if (p & 1)
            dash() ;
          else
            dit() ;
          p = p / 2 ;
      }
      delay(2*DOTLEN) ;
      return ;
    }
  }
  /* if we drop off the end, then we send a space */
  Serial.print("?") ;
}

void
sendmsg(char *str)
{
  while (*str)
    send(*str++) ;
  Serial.println("");
}

void setup() {
  pinMode(LEDpin, OUTPUT) ;
  Serial.begin(9600) ;
  Serial.println("Simple Arduino Morse Beacon v0.0") ;
  Serial.println("Written by Mark VandeWettering <k6hx@arrl.net>") ;
  Serial.println("Check out my blog @ http://brainwagon.org") ;
  Serial.println("") ;
}

void loop() {
  sendmsg("K6HX/B CM87") ;
  delay(3000) ;
}

Addendum:


Addendum2:

Josh asked me how the morse code table works. It's a little bit clever (a very little bit) but I guess it does require some explanation. Morse code characters are all length six or less, and each element is either a dot or a dash, so it would seem that we can store the pattern in six bits. Let's say that dits are zero and dahs are one. Lets store them so the first element gets stored in the least significant bit, and the next in the second most, and so on. The only trick is knowing when there are no elements left, because otherwise we can't tell (for example) K (-.-) from C (-.-.) To do that, we store a single extra one after all the other elements are taken care of. Then, when we are looping, we do the following. If the pattern is equal to one, we are done (that's our guard bit). If not, we look at the least significant digit. If it is a zero, we have a dit, if we have a one, it's a dah. We then get rid of that element (by dividing by two, or shifting right if that floats your boat) and repeat. Voila. Each character takes only a single byte to store its pattern, and decoding is just done in a few instructions.

Hope that helps.

Addendum3: Well, I couldn't leave that alone, witness this...


There are many examples that people use to output sound, most of which seem to bang an output pin high or low, call delay to wait a given number of microseconds, then change its state. This seems odd to me, because the Arduino has some pretty good pulse width modulation. This can be used to make higher quality sound, but for me, it also proved to be easier. I just configured pin 9 to be an output pin, and then used analogWrite(9, 128) to turn on the sound, and analogWrite(9, 0) to turn the sound off. That's it! You get about a 500hz tone, and it works really well.

Click here for the source code.

Filed under: Amateur Radio 28 Comments