Grathio Labs » Softwarehttp://grathio.com
Wed, 27 Aug 2014 20:22:51 +0000en-UShourly1http://wordpress.org/?v=233National Novel Writing Month Progress Monitorhttp://grathio.com/2012/10/national-novel-writing-month-progress-monitor/
http://grathio.com/2012/10/national-novel-writing-month-progress-monitor/#commentsTue, 23 Oct 2012 16:06:02 +0000http://grathio.com/?p=825I don’t know if everyone has a novel in them or not, but every year in November a few hundred thousand people give it a shot by participating in National Novel Writing Month. The daunting goal is to write a 50,000 word novel in 30 days. At just under 1700 words a day, the event tends to be as full of excuses as it is participants.

Organizers have come up with numerous ways to keep writers motivated. There are local events, writer meet-ups at coffee shops and libraries. The web site makes a big deal about sharing your progress, posting your word count for other members to see and to, in a fashion, certify that you’ve succeeded. Or not. There are forums and an assortment of widgets to put on your web site to show off, battle, or compare word counts against other writers or even geographic areas.

Sometimes it takes a little more of a kick in the pants to keep you motivated, so I put together this physical progress monitor. It automatically tracks your (or your chosen stalking victim’s) progress toward 50,000 words using the data from the NaNoWriMo word count server.

It’s a pretty basic project that a beginner (who can follow instructions) can tackle. You can probably also get parts you need locally.

It won’t take too long (depending on how good you are with folding paper) and you don’t need a soldering iron or other speciality tools. Some very basic programing knowledge is helpful but not necessary.

Time: It shouldn’t take more than two hours, depending on how good you are at working with paper.

Step 1) Basic Setup.

The Arduino is the bit that will control the real-world gauge. To control it you first need to download and install the Arduino application from here. If you’ve never used an Arduino before it’s important that you go through the Getting Started guide to get everything set up correctly and to understand how everything works.

Processing runs on your computer and fetches the information from the internet and sends it to the Arduino. You’ll need to download and install the Processing application from here.

If you want to track your own writing you need an account at NaNoWriMo.org. You can create it here. Or you can follow other writers if you know their NaNoWriMo account name. Make sure you create a novel as well, otherwise it won’t have any words to count.

Note: If you have older versions of Arduino or Processing applications, be sure you get the latest. This project uses version 1.0.1 of Arduino and 2.0 (Beta 3) of Processing.

Step 2) The Arduino

Now lets set up the servo and the Arduino.

First fasten a horn to the servo. “Horns” are the little plastic bits that came with your servo that fits on the shaft. If you have a round, X, or star shaped one, use that. Otherwise use the biggest one. Snap it on the shaft of the servo and then fasten it in place with the little screw that came with it. Don’t over-tighten.

Next we’ll connect the servo to the Arduino. Use three male jumper wires and connect them as below. If you don’t have any male jumper wires you can make them out of 22 gauge wire. Cut three lengths of wire about 3 inches (8cm) long, and strip 1/4″ (8mm) of insulation from each end.

Black or Brown servo wire to GND on the Arduno. (There are 3 GND connections. Any one is fine.)

Red servo wire to 5V pin on the Ardunio.

Orange or White servo wire to Pin 9 (Digital) on the Arduino.

To test that everything is working, open the Arduino application and go to File -> Examples -> Servo -> Sweep. Upload this to the Arduino and the servo should turn slowly back and forth. If not, check all your connections and maybe go through the Getting Started guide again.

Once you’re sure the servo is connected and working well, download the nanowrimo Arduino code from here and save it on your compter. In the Arduino application, go to File -> Open, select nanowrimo_arduino.ino and upload it to the Arduino.

At this point it shouldn’t do much of anything except blink the yellow light labeled “TX” every second or two. To get it to do something we need to connect it to data from the internet, and we’ll do that in the next step.

Step 3) Processing

Download the Nanowrimo Processing code from this link and save it on your computer. Launch the Processing application and go to File -> Open and select nanowrimo_Processing.pde.

Scroll down about 100 lines until you see a section like this:

Change the “ChangeMe” to the account name you want to follow. Make sure to keep the quotes around the name. If the name has any spaces in it, replace them with minus signs. (If you have trouble figuring out the correct name, log into your NaNoWriMo account and look at the address bar of your browser. The name we need is to the right of the last / slash.)

If you’re planning on writing more (or less) than 50,000 words you can change the word target here. (Make sure not to include any commas in the number.)

Run the program. (Control-R or hit the triangle Play button on top left of the interface.)

First look at the bottom of the Processing window where there should be some white text. (If there are many lines of red text, double check your changes and make sure the name has quotes and has a semicolon after it. Also be sure you’re not using an older version of Processing.)

Note for Mac and Linux users: The first time you run this there might be some extra instructions on the bottom of the Processing window. Follow them so your Serial port can talk to the Arduino.

If all goes well you’ll see a list of gibberish-looking serial ports with the top one highlighted. (It’s okay if the names are different from this screen shot.)

The one with the arrows pointing to it needs to be the same one that the Arduino is attached to. (To double check launch the Arduino application, and look at Tools -> Serial Port for the one with the checkmark next to it.) If the arrows don’t point to the correct port, make note of the bracketed [number] next to the correct port and change the zero in serialPortNumber = 0; to the correct number. Click Run again.

If all goes well a small window should pop up. It will load a widget showing this year’s progress. After a few seconds the Arduino should connect and the servo will rotate to zero. (Assuming you’re building this before you’ve started writing.)

Troubleshooting:

If the widget says “user not found” double check the user name you entered.

If it says “Arduino not found” or says “Arduino connecting…” for a really long time double check that the Arduino is connected, that the green power light is on, the nanowrimo_arduino.ino code has been uploaded, and the correct serial port is chosen on line 101.

If it says “Error Loading Data” there may be something wrong with nanowrimo.org or your internet connection. Make sure you can get to the site in a web browser.

If there is lots of red text and nothing happens, re-download the Processing code and carefully make your changes again. Also be sure you are using the latest version of Processing, it won’t work with versions before 2.0

Congratulations! Now all that’s left is to make it pretty.

Note: It may take up to two hours for word count changes to update. That’s because the NaNoWriMo servers can take that long to post results. Be patient.

Step 4) The case

Feel free to ignore, alter, or improvise this step. You already have a machine that will turn a dial 180° as your novel approaches 100% complete, and you can improvise your own case. (For the curious: the servo turns clockwise as word count increases.)

If you don’t feel like improvisation you can make one of these cases out of card stock.

Download the PDF for your chosen style and print out all the pages at 100% on card stock.

The outer case design is all yours. I made one look like a pile of books and added a couple of words to the front of the other one.

Follow these guidelines when building the case:

Cut on the solid lines.

Fold up on the dashed lines.

Fold down on the dotted lines.

Don’t cut or fold anything that’s gray.

Tabs and slots have matching letters and numbers. The letter is the suggested connection order. The numbers are for the tabs of each piece. For example slot B4 is looking to connect with the second tab on the 4th piece.

I recommend reinforcing tabbed joints with tape where possible. It will hold together with tabs, but it has motors moving parts of it around and without tape it will tend to work its way loose after a while.

I go through the whole process in the video above, so give it a watch through (or a pause through) if you need help figuring out what goes where.

Part #1: The Arduino Base

This forms a base for the Arduino to sit in and holds the whole thing together. Cut it out and bend each end around below and fasten the tabs back into its self. Test the Arduino for fit.

Part #2: The Servo Support

This is the most complex part. It forms a sturdy support to hold the servo in place. Assembled it forms an upside down U that fits into the Arduino Support Base, straddling the Arduino, near the front of the case.

The Dial

Tape or glue the indicator dial to the servo, making sure it’s rotated to the right location (it should be close to zero when the servo is in place. Tape the servo in place in the center of the servo support. (The center is marked with an arrow.) Feel free to load up the Servo Sweep test program to watch the dial turn back and forth. (And to make sure you have it lined up the right way.)

If the dial feels a little flimsy you can back it with another layer of card or a disc of thicker cardboard.

Part #3: The Back

Technically the back and right side, tabs A, B, and C fasten to the bottom rear of the Arduino Base. The next goes along the right bottom side of the base. Reinforce the bottom tabs with tape so the bottom doesn’t fall out when you pick it up.

Part #4: The Front

It’s pretty much the same as the back piece, but with a cutout for the dial or gauge. In addition to the base tabs be sure to connect it to the Back along the vertical edges.

Part #5: The Top.

Fold the tabs down and fit them into the remaining slots.

You’re done!

Plug it into your computer. Make sure the NaNoWriMo code is uploaded to the Arduino, run the Processing sketch, start writing and posting your word count to NaNoWriMo. Good luck!

Did you make one? Post a picture or a video in comments. I’d love to see it!

Update #4: Nov 23: The Instructable is complete. If you want more instructions than are listed here, go here and read all of the steps, see all the photos, and enjoy!

Update #3: Nov 11: If you’d like to get updates about the progress of the kits (like when they’ll be for sale and how much) you can sign up for the mailing list here.

Update 2 Nov 5th: Thanks for all of your (overwhelming!) interest in buying/making/finding one for yourself! Unfortunately I don’t have the spare time to make any extras right now. However I’m looking into what I can do to put together a kit or finished product for you guys. When I know something concrete I’ll post a message to the site.

Update Nov 3: Added a proper schematic. (Thanks Nik!) Also hosted some of the images elsewhere so hopefully the site will stay up until I can find a new, more reliable web host.

How many times have you seen a secret hideout with a secret knock? It’s a staple of cheesy dramas, Saturday afternoon movies, and tree houses throughout the world.

While working on another project I ran across the Arduino knock sensor tutorial. Sensing a single knock is a great little project for learning about microcontrollers, but what about sensing specific knocks? Seeeeecret knocks? And if we could detect a secret knock, shouldn’t it unlock a door? If you can’t tell by looking this was cobbled together from spare stuff around the lab, it’s not much more than a piezo speaker, a tiny gear reduction motor, and an Arduino. And PVC pipe. How about a video to explain:

Click onward to read more details, source code, photos, etc.**Disclaimer: This was built with stuff I had lying around the lab. There are many better ways to build this project. Tell me about them in the comments.

If you didn’t watch the video, here’s an overview:

A microphone (okay, really a speaker) presses against the door and listens for knocks. If it hears the right number of knocks in the right cadence it triggers the motor to turn the deadbolt and unlock the door. If the sequence isn’t recognized, the system resets and listens for knocks again.

Side view. Arduino microcontroller up top and peeking out at the left is the button to program new knocks. The shiny bit with the nut and bolt goes over the lock and is connected to a motor you can’t see. But you can see the piezo speaker on it’s spring to press it against the door.

The default code is Shave and a Hair Cut but if that’s too obvious you can enter a new knock sequence by holding down the red button and knocking your new secret knock (up to 20 knocks). The rhythm of your favorite song, Morse code, whatever! The widget will play back your knock (by blinking the lights) so you can be sure it heard everything correctly.

The whole thing is attached to the door with suction cups

The components are simple, most of the work is done in the microcontroller. The source code for the Arduino is available at the bottom of the page if you’re curious.

How does it work?

First it records the time between knocks. If there is a long wait for a knock it stops listening and starts analyzing.

First it checks the number of knocks. If that’s right, we go on to more vigorous authentication. First it converts the absolute timing of the knocks to the rhythm of the knocks. This lets us knock fast or slow and as long as we get the rhythm right it will unlock. That way I can still unlock the door if I’m tired or full of caffeine. After this it compares the timing with the secret key and if any individual knock is off by too much or the whole thing is off by a certain average amount the door stays locked. If not, we trigger the motor to turn and the lock to unlock. If the programming button is pressed it saves the rhythm information and then plays it back.

The detection is surprisingly accurate and can even be dialed up so it’s precise enough to detect an individual person’s variation on a knock, similar to a Morse coder’s ‘fist‘. (Though when the verifying is this tight it also triggers false negatives which are annoying.)

To keep things simple (and it’s because it’s what I had available) a motor is attached to the deadbolt using two pieces of spring steel bolted across the D shaft of the motor so that the connection will slip when the lock turns as far as it can. A more precise (and probably durable) way to do it would be to use a servo to turn the lock or have a detector sense when the lock had reached its extent. Or replace the dead bolt with a solenoid. Or whatever else you can think of.

The rest of the electronics are nothing special. Its so simple that just adding feedback LEDs almost doubled the parts count. The Arduino has a lot of unused potential on this project.

No proper schematic yet, but there’s a layout and parts list at the bottom of the page. Look for a fully documented Instructable soon.

With some extra electronics (an H-bridge) it would be possible to have the door automatically lock as well as unlock. Other improvements or changes that someone could do:

Adding a knob to adjust the sensitivity.

Building it into an actual door knocker.

Using a more economical microcontroller and enabling a sleep mode for better battery life.

Making the whole package small enough to fit inside the door.

Storing several knocks so several people can have their own private knocks.

Adding a real-time clock and using different knocks for different days of the week or times of day.

Listening for door bell presses rather than door knocks.

Adding a servo or solenoid powered knocker to provide feedback through the door. It could then offer a challenge-response security where the door starts a knock sequence and the user has to finish it correctly.

Rather than listening for knocks, putting a photoresistor in the peep hole and detecting flashes of light from a pocket flashlight or simply by placing your hand over the peephole. Or an infrared receiver and use special key presses on a remote control.

Do I have to point out that this is not a great security measure since overhearing a knock sequence is pretty trivial? No. But it’s fun to make and play with.

Ever since I first learned to program computers in the early 80’s I’ve wondered how valid it is to call a programming language a ‘language’. Sure, they’re called “languages”, so that should give me a hint. They’re pretty capable for transmitting information to computers and they purposely use some natural language constructions, ie: if {situation} then {take an action}. But how close to a natural language are they and what kind of nuance and emotion can we keep in translation? With that in mind here’s an attempt to translate some familiar English into a psudeocode computer language and see how it holds up.

But First: I know a lot of my readers are not programmers, and I know that you’re seriously considering skipping the rest of this article, but I encourage you to keep reading. Even though I use programming framework, it’s essentially about human communication.

Lets see if you can figure out the original of this famous speech:

conception = getCurrentYear() – (4 * 20) + 7;

fathers = liberty();

fathers.men = men;

continent += fathers;

function liberty(){

return new Nation();

}

Read on for the answer…

Yes, it is indeed the Opening of the Gettysberg address. A bit clumsy though. I couldn’t figure out how to say “dedicated to the proposition that…” Computers don’t really do dedication. Or rather they don’t do anything else.

Also it seems that programing languages pretty much only have the present tense.

Okay, that didn’t go so well, but let’s try something different:

world=stage;

stage.men=players;

stage.women=players;

stage.men.entrance=true;

stage.men.exit=true;

stage.women.entrance=true;

stage.women.entrance=true;

man.part=new Array();

That is from Shakespeare’s As You Like It Act 2, scene 7. This one is pretty decent. No iambic pentameter, but I think it comes across almost elegantly with little meaning lost. And a lot of programming is short lines and no initial capitals, which are also reserved for poetry. Let’s try another one.

then.times = [“best”,”worst”];

then.age = [“wisdom”,”foolishness”];

then.epoch = [“belief”,”incredulity”];

then.season = [“Light”,”Darkness”];

then.spring = “hope”;

then.winter = “despair”;

then.us.before = [MAXINT, 0];

then.us.all = [heaven, !heaven];

then = now;

That’s A Tale of Two Cities, for you fans of not reading Dickens. One thing that becomes clear is that it’s rare to get sentence to sentence (or sentence to line) parity with English. Careful readers will notice that I cut this quote short. The whole “…that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only,” part seemed impenetrable in any language I know. (Even English. Sorry Charley.) And there’s the problem of doing gray area comparisons (“mostly” “generally” “somewhat”, etc) that is hard to address.

(Genesis 1:1, King James version for those playing along.) It gets the base meaning across, but I totally skipped “And the Spirit of God moved upon the face of the waters” part. Verbs are hard. I thought about incrementing a pointer across an array called faceOfTheWaters[] but that seemed like a lot of work for “moved across”, not to mention that it could easily be confused with “moving” or “incrementing” or even “sorting”. Not a lot of nuance. Moving on…

gregor.dreams = troubled.

gregor.awake = true;

gregor.location = bed.

gregor.shape = vermin;

gregor.back = armor;

gregor.head = lift();

function lift(){

brown_belly.visible=true;

return brown_belly;

}

Who’d of guess I’d pull out Kafka’s Metamorphosis? Well there it is. Again, it doesn’t really lend its self well. Descriptions (declarations) are dull and repetitive if you only have a tiny handful of verbs, most of them for numbers. This one points out one of the biggest problems with translating programming into English. A programing language is so limited that 95% of the meaning of these passages comes from the English used, not from the programing. It’s a good thing languages excel at adding words and definitions. (If someone wants to translate these into ASM, they are welcome in comments.)

Comedy… It’s hard, even under the best of circumstances. But programming with wit, irony, parody and social commentary is beyond even the best programmers I know. This example also points out the strength of computer languages to organize complicated data, but its reluctance to do anything human with them.

I think that’s more than enough examples, lets wrap it up.

Programming languages have many of the components of human language, which should be no surprise, we invented ‘em. But they are extremely limited in their ability to express the things we easily do with natural language. And even this wasn’t a fair test since virtually all of the information in these code samples is from the English meaning of the variables. If they were changed to a,b,c and foo, they would be completely cryptic. The examples could have been extended to the point where they could graphically illustrate the complex concepts, but it would have added hundreds if not hundreds of thousands of lines, at which point it’s not terribly readable.

I wonder if there would be any benefit from bringing computer languages more into line with natural language? How would programming or computer use in general change if we had more adjectives and more tenses? What if our computer languages had a rich vocabulary of tens of thousands of words rather than just a few dozen* and what would we do with them?

Thoughts? Better translations? Feel free to comment.* Yes, most computer languages can be extended to add more words to them, but you can do the same with English if you buy, say, a medical dictionary. I’m speaking specifically of extending the core language.**** And no I’m not talking about BASIC et al. Though it’s creation focused on using more English words than other languages, it’s still constrained by the same operators and structures as other languages, regardless of what they’re called.

]]>http://grathio.com/2009/10/computer_languages_as_language_1/feed/13Christmas Cardhttp://grathio.com/2008/12/christmas_card/
http://grathio.com/2008/12/christmas_card/#commentsSat, 20 Dec 2008 23:55:28 +0000http://grathio.com/wordpress/?p=24What would Christmas be without a way to waste some time! Here are some Christmas themed photo puzzles to play with. Merry Christmas! Thanks for 2008, I’ll see you in 2009!
]]>http://grathio.com/2008/12/christmas_card/feed/1Time Zone-O-Meterhttp://grathio.com/2008/10/time_zone-o-meter/
http://grathio.com/2008/10/time_zone-o-meter/#commentsThu, 23 Oct 2008 20:33:49 +0000http://grathio.com/wordpress/?p=16

(Actual size 70×13 pixels. Border added so it doesn’t get lost on the page.) It’s tiny, but that’s exactly the point. When I was traveling a lot between Japan and the US I searched high and low for a software clock that would show me the time in the country I wasn’t in. Everything I found took up too much screen space and in many cases were simply ugly or hard to use. (Yes, a hard to use clock. Who would have guessed?)

So I built this one. It’s not configurable, but it does exactly what I need. It automatically adapts its self to show the time in Japan when I’m in America and vice versa. It sits comfortably on the upper right edge of the screen taking up only as much space as it needs, always visible and never in the way.

I’ve been a little frustrated by the
software for managing digital music in a way that is useful for an
all digital DJ. Virtually every music manager is a giant
spreadsheet, which is great if you’re creating a simple playlist, but
not much of a help for manging relationships between music.

So I created a project I’m calling
Mixture. This is just a prototype, proof of concept, and it’s pretty
nifty. It borrows iTunes data as a starting point and lets you
search and browse music in the usual ways. (Though compactly, so I
can keep Ableton Live
on most of the screen.) But its primary feature is to let me manage
relationships between complementary tracks. It allows me to annotate
the mix so I can recreate it and adapt on the fly. Many DJ’s have set
blocks that they play in order to cut down on the trouble of mixing.
This is similar, but it gives me a variety of branches for each track
I play. Adding good mixes to the database as I find them lets me
quickly and easily explore how the current song relates to others and
will let me choose branches during a performance and let me create a
unique, responsive set every time without worrying about getting a
bad mix or transition.

I threw this together in about a day
and a half using PHP and MySQL running locally, but it does prove the
concept works well and is a valuable asset even in this primitive
state. In the future I’d like to develop it as a Flash/Adobe Air
application that will let me drag music directly between
applications, provide more in-depth relationships, and possibly use
it to control supporting video, other external interfaces, and who
knows what.

More screenshots of the various interface elements after the jump.

This is the basic song list browser.
It shows a few basic columns, with more information on mouse over.
It also lets you preview a song and can be sorted by any column.

This is really the screen that makes
it something different than iTunes or Media Monkey. It lets me
create and annotate music relationships.