My friend Callen tried to help me run a DC motor to roll my curtains up and down. We didn’t make a ton of progress, but we had some fun making a little music.

I’ve gotten to the point in Zorchpad development where I’d like to see how the whole thing fits together and if there will be any insurmountable problems. We’re still trying to figure out some things like–will it have one screen or two? What form factor will it be? Will the keyboard fold in half? So I put together a cardboard model.

This model has:

  • A power switch. I’m assuming the very first prototype will run on battery, not solar like the final one.
  • Two memory-in-pixel screens (total power usage: 0.001 W)
  • One e-ink display (total power usage: variable/unknown)
  • An apollo3 artemis board, which includes RAM, CPU, microphone, and BTLE (not pictured, total power usage about 0.0005 W)
  • One flash chip (not pictured, power usage variable)
  • A battery slot. I’m using AAA for my convenience (Holds: 3000 joules = ~20 days power)
  • An audio jack for headphones
  • A microSD slot
  • A custom keyboard (total power usage: variable/unknown)
    The keyboard is closely modeled off a standard one, for now.

Immediately, a few problems pop out:

  • It’s fairly long. This will stick out of my pocket. This is with very closely spaced keys on a somewhat reduced keyboard.
  • There’s not really a great place to put solar panels. It’s has almost zero free space, plus there’s going to be a lot of wiring. Are we going to drill holes through the solar panel to let wires pass through? Also, I really haven’t been able to figure out how many cm2 of solar we need.
  • It’s hard to get the screen to stay propped up on my cardboard model. I’d like a solution that doesn’t use hinges, since those tend to loosen over time.

My next step will probably be to make a custom working keyboard. Then, I’ll make an entire working zorchpad. Both will be either cardboard or 3d-printed (whichever is easier).

Hello, Linux terminal users! Let me present you a simple feature you’ve all seen, but might not have noticed.

You’re on the terminal, and you open a text editor of chice–nano, vim, emacs, acme etc.

After you edit for a bit, you close the editor.

Now you’re back where you left off. My question is, how? How does nano remember what used to be on screen? How does it get restored? Is nano doing this, or bash?

Well, I took at look at the source code to nano. Then I thought, “whoa! that’s way too complicated.” So I found a much simpler project called ted someone made to educate themselves. That was also a little complicated, but both seemed to use ncurses. So I wrote the following simple program, which also displays something and then restores the screen. Even though it’s very simple, it still works.

// Compile with: gcc -lncurses editor.c -o editor

#include <curses.h>
#include <stdio.h>

int main(int argc, char **argv) {
    initscr();

    refresh();
    printw("Hello world");
    getch();

    endwin();
    return 0;
}

Aha, so it’s something in ncurses, maybe. Let’s dive deeper.

So initscr() presumably saves the state in some fashion. endwin() definitely restores it, because if we comment that out, the terminal stops being restored. Since initscr() probably does lots of other irrelevant logic, we could take a look at endwin() to dive in. But let’s do something even simpler first.

As background, the linux command line is pretending to be an obsolete piece of hardware called a terminal. Specifically, it’s pretending to be a model called the DEC VT100 (or a later one, but they’re mostly backwards compatible). The terminal accepted text over a wire, and printed it to the screen.

When it got special text, it would do special things. These are captured today as “escape codes”–special non-printable characters, which cause your software terminal to also do special things. What kind of special things? Well one example escape code is “Backspace”, which deletes the last character. Another code is “\r\n” (carriage return; new line), which goes to the beginning of the line, and down one.

I suspect the answer to what’s happening with save and restore of my terminal might be some magic escape codes. So let’s just redirect the output to a file, and see what data is being center over the virtual wire to our virtual terminal.

$ ./editor >magic.txt
$ xxd < magic.txt
00000000: 1b28 421b 2930 1b5b 3f31 3034 3968 1b5b  .(B.)0.[?1049h.[
00000010: 313b 3530 721b 5b6d 0f1b 5b34 6c1b 5b48  1;50r.[m..[4l.[H
00000020: 1b5b 4a48 656c 6c6f 2077 6f72 6c64 6a1b  .[JHello worldj.
00000030: 5b35 303b 3148 1b5b 3f31 3034 396c 0d1b  [50;1H.[?1049l..
00000040: 5b3f 316c 1b3e                           [?1l.>

Well, that’s certainly a bunch of magic. Now something cool happens:

$ cat magic.txt

This command does nothing visible. It doesn’t print “Hello world”, even though that’s in the file. In other words, it’s printing Hello world, then really quick resetting the terminal. Just too fast for my poor human eyes to see.

We’ve confirmed the escape code theory! This file has everything we need. We can look at the source code to ncurses if we’re curious, but we don’t need to (and I won’t).

One thing I immediately see in this file, is that it doesn’t seem to contain the words that were on screen. So it’s not that the program read what was on screen, and printed it back later. Rather, there are some magic escape sequences happening to save and restore the terminal.

Okay, so somewhere in those 70 bytes is a magic code or two we want. Let’s examine all the bytes.

What kinds of escape codes appear here? Hex 0x1b is ESC, basically the escape sequence–it cues the terminal in that a special escape code is coming. 0x1b9b ( ESC followed by [) is the CSI escape code. DEC private codes refer to other escape sequences used by the DEC terminals like the VT00 (I’ll just shorten this to “DEC” below).

Without further ado, let’s break down those 70 bytes. Apologies for any errors below–correct me in the comments.

  • 0x1b (B
  • 0x1b )0
    • Set second character set to “DEC Special Character and Line Drawing Set” [xterm DEC guide]
  • 0x1b9b ?1049h
    • Save cursor as in DECSC and use Alternate Screen Buffer, clearing it first. [xterm CSI guide]
  • 0x1b9b 1;49r
    • DECSTBM: Set scrolling region to rows 1-49 [xterm CSI guide]
      (When I ran the program, my terminal was 49 lines tall inside tmux–so the whole terminal in other words.)
  • 0x1b9b m
    • (Empty) color and style set comand [ANSI/CSI]
      I think this could be left out entirely.
  • 0x0f (Ctrl-O)
    • Shift In. Use the standard character set. [xterm]
  • 0x1b9b 4l
    • RM: Replace Mode / IRM [xterm CSI guide]
      Typing doesn’t shift everything over, it writes over existing content.
  • 0x1b9b H
    • Move the cursor to “home” (top left of the screen) [ANSI/CSI]
  • 0x1b9b J
  • Hello worldj
    • The program prints “Hello world”. The final j was echoed when I pressed “j” to exit.
  • 0x1b9b 49;1H
    • Move the cursor to line 49, column 1 — the bottom-left corner [ANSI/CSI]
  • 0x1b9b ?1049l
    • Use Normal Screen Buffer and restore cursor as in DECRC [xterm CSI guide]
  • 0x0d (\r or Ctrl-M)
    • Carriage return [xterm]
      Moves cursor to column 0
  • 0x1b9b ?1l
    • DECCKM reset: Re-enables the cursor? [VT100]
  • 0x1b >

OK, solved. The magic save bytes are 1b 9b 3f 31 30 34 39 68 (<ESC> [?1049h). The magic restore bytes are 1b 9b 3f 31 30 34 39 6c (<ESC> [?1049l). And xterm or tmux is doing the save/restore magic, based on seeing this escape mode.

Hmm, how minimal can we get a working file, I wonder?

#!/bin/sh
echo -ne '\x1b[?1049h' # Save terminal
echo -ne '\x1b[H'      # Home the cursor
echo "Hello world"
sleep 1
echo -ne '\x1b[?1049l' # Restore terminal

Yep. That works fine.

ANSI: https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
DEC: https://vt100.net/emu/ctrlseq_dec.html
DEC: https://vt100.net/docs/vt220-rm/chapter4.html#S4.6.18
xterm’s control sequences: https://www.xfree86.org/current/ctlseqs.html

I hacked up a little to-do app in an hour. The emphasis is on focus.

It’s linux only. You can find it in my short-programs repo on github.

Another update on the zorchpad. We now have a working 16-button keyboard (sadly no QWERTY yet). Here you can see a simple typing program that shows what you type on screen.

As mentioned in a previous post, the reason we’re using a custom keyboard is to stay to low power usage–much lower than a standard keyboard.

So far we have:

I tested with one tile. Now I made signs for my whole garden.

To start, I covered each marble tile in painter’s tape.

Then, I used double-stick tape to attach labels.

I cut out the words using an x-acto knife, and removed the paper and cut-out portion.

I spray painted them. I chose a higher-contrast color because of my one-tile test.

I peeled off the tape, and voilà:

Lessons learned:

  • Doing a test tile was a good idea
  • It takes almost as much time to peel out the letters as cut it. I was thinking of using a laser cutter to speed things up, but it could at most halve the manual labor.
  • You should switch x-acto blades more often than you think.
  • I should have spent even more time on an easy-to-cut font. The “a”, “e”, and “r” are too hard in this font.

I’m making labels for my garden sections by painting tiles.

This is a blank “subway” style marble tile. It’s 140×45 mm (2×6 inch). One is about $1. Avoid “glazed” or “glossy” tiles, which are too smooth for the paint to stick well.

First, we add a layer of tape. I used blue painter’s tape because it’s easy to see. I expect masking tape would work well too.

Attach the sign you want to your tape. I used double-stick tape. It’s better than single-stick around the edges, but that also works in a pinch.

Cut through the letters using an x-acto blade. I used a sans-serif font to make this step faster.

Remove the paper, as well as the tape. You can use the x-acto blade to peel up the tape. Make sure not to lift up the “holes” in letters like ‘B’ or ‘a’.

Paint the tile. I used pale/pastel blue acrylic spray paint. Make sure to either not spray the sides, or cover them in tape too.

Then I let it sit for 15-20 minutes.

Peel off the tape. I used gloves, and took out the holes using tweezers.

Peeling the tape while the paint is slightly wet is easier than completely dry. When it’s dry, the acrylic clings to the tape and “stretches” rather than cleanly breaking.

If you mess up along the way anywhere, acetone took the paint off great for me.

Then I let the paint completely dry. Optionally, you can seal it with a clear sealant if you want extra waterproofing.

I attach the tile to my raised beds using z-brackets sized to fit the tile thickness and a screwdriver. They look fine on the dirt too.

Looks nice! Maybe I’ll switch to a higher-contract color paint for white?

I recently made an art project as a birthday gift for a young friend of mine.

I hadn’t seen the exact technique I invented to make stencils posted anywhere, so I figured I’d share it. I don’t think this is a good method, but maybe it will inspire someone to do something better.

I started with a blank tile. On top, I put down a layer of painter’s tape (basically masking tape, but a little less stretchy).

I printed and taped a piece of paper on top (made using this online tool with the font BreeSerif):

I used an x-acto knife to cut through both the top paper and paper, then removed the paper. Then I peeled the letters out of the painter’s tape.

I painted the letters with acrylic, let them dry, and removed the tape. In retrospect, it probably would have been easier to remove the tape wet, because acrylic paint is a little stretchy and I went over the lines.

The letters happily lifted right off the glazed tile, which hadn’t been sanded or anything. I added a heavy coat of modge-podge spray sealant, which kept everything in place after drying.

Finally, I used a masonry bit to drill screw holes in the tile, so it could be attached to a door.

She seemed to like it :). But now she wants to make one too. I’ll have to see if I can invent an easier way.

I’m one of the designers for the yearly April Fools Puzzle Contest on IRC.

Please feel free to join at https://blog.ircpuzzles.org/. The idea is that you solve puzzles in a chatroom, and get the password to the next chatroom, and so on. If you’re not familiar with IRC, don’t worry–a link is provided to connect in your browser, too.

It’s a lot of fun, and I hope you enjoy!

P.S. The contest should be up for a while, so don’t worry about being late to the party!

A few friends and I first experienced this traditional Vietnamese Tết (Lunar New Year) food while visiting years ago. We loved it, and recently I looked up how to make it myself. It’s not a well known food in the US, so I thought it would still be fun to share.

I followed the recipe from “Enjoy a simple life“, but made a homemade cardboard mold as suggested by “Takes Two Eggs“.

Like a bread, this recipe takes a fair bit of time. I would start in the morning.

  1. Soak rice and mung beans overnight. Marinate seitan or meat.
  2. About 30 minutes of cooking. Boil beans and rice.
  3. About 30 minutes wrapping and packaging.
  4. Finally, an 8-12 hour boil in a big pot of water.

Ingredients needed:

  • Seitan or pork belly (optional), 4-8 oz
  • 5 c glutinous rice, lightly rinsed twice and soaked overnight
  • 2½ c dried slit mung beans, washed and soaked overnight
  • 2 shallots, thinly sliced
  • 2 leeks, use white part, thinly sliced
  • 2 t salt
  • 3 t black pepper
  • 1 t sugar
  • 2 t good soy sauce
  • 2 T fish sauce or 1 T mushroom powder
  • ½ c vegetable or peanut oil

Additional supplies:

  • Banana leaves (defrosted)
  • Twine, string, etc
  • Scissors
  • Plastic wrap
  • Aluminium foil
  • Cardboard and packing tape to make a mold. I used a soda box

Ingredient Prep:

  1. Cook rice with salt.
  2. Steam mung beans. Food-process them.
  3. Fry shallots and leeks in oil. Add seasonings.
  4. Remove from heat. Add the rest of the oil and mung beans. Mix thoroughly.

Making the cakes:

  1. Place the square cardboard mold on a sheet of plastic wrap.
  2. Put two cut banana leaves inside to form a little square pocket.
  3. In the pocket, layer ½ c rice, ¼ c mung beans mix, strips of meat or seitan, ¼ c mung beans, and ½ c rice.
  4. Fold the banana leaves over, and remove the mold. Close the plastic wrap to hold everything together.
  5. Wrap the plastic wrap in a layer of alumnium foil.
  6. Tie the foil shut with string.

Once you have all your cakes made, boil them at a low simmer for 8-12 hours. Your cakes are done.

They last weeks and stay pretty tasty. You can freeze them if you want them to last even longer.

Sources:

  1. https://enjoyasimplelife.blogspot.com/2012/01/vegetarian-sticky-rice-banh-chung-chay.html
  2. https://takestwoeggs.com/banh-chung/