Sunday, January 6, 2013

OS By Petzl - Mixed Results

Tried using the OS By Petzl software on a Core battery connected to a Tikka XP2:

  • The software doesn't work on my x220 tablet running Windows 7 (64-bit): it fails to detect that the battery is plugged in.
  • Even after trying to run the software in various Windows Compatibility modes (Vista, XP SP2, XP SP3, Windows 7).
  • It does work on another computer which is running Windows XP: can name the battery, tell it which lamp is being used, and set profiles.
  • But I can't create a custom profile. The instructions are just plain wrong.
  • Maybe a conflict with Lenovo drivers? Who knows.

Lessons learned:

  • If I had been using Windows 7 System Restore, it would have saved me a lot of trouble trying to uninstall the Petzl software and drivers.
  • Restoring from a previous backup (Windows 7 Backup and Restore) works fine, and only took about 90 minutes.
  • Was also able to use Areca to restore user documents. (Right-click on an archive, choose "Recover...", and choose a recovery option.)
  • Drag and drop of a VMWare Player Linux VM to/from a USB drive worked fine as a way to backup it up.

So, be warned. The OS By Petzl software kinda sorta works, but don't count on it. Bet the battery controller could be hacked though.

Tuesday, January 1, 2013

Bus Pirate meets the 93LC46B

One of the toys I acquired last year (or possibly even the year before) was a DangerousPrototypes Bus Pirate. Among the many things it can do is read/write EEPROM chips, which is a type of memory. They are used in electronics to store things like programs and state information. People have used Bus Pirates to recover motherboards that have been bricked by a bad BIOS flash. Some laptops have start-up password protection. The password is stored on an EEPROM chip, and if the user should become forgetful, reading the chip is one way to recover it.

I found an old EEPROM chip in my spare parts collection, the 93LC46B. The data sheet says it communicates using 3-wire serial I/O, and can store 1024 bits organized either as 8- or 16-bit words.

Next was the question of how to wire the bus pirate to the chip. I liked the idea of plugging some headers into a breadboard:

These give the Bus Pirate's clips something to grab onto.

Then, I wasn't sure if I needed to create a separate power supply. Turns out one can simply power the chip directly from the Bus Pirate's 3.3V connector. This is undoubtedly one of the reasons the Bus Pirate is such a well-regarded tool.

Finally, I hooked up the CS (chip select), CLK, MOSI (to the DI or data in pin), and MISO (to the DO or data out pin) connectors.

I used putty as a terminal to control the Bus Pirate. Configuring the Bus Pirate in 3-wire mode took a little trial-and-error, but I finally found settings that worked:

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2013.01.01 19:28:55 =~=~=~=~=~=~=~=~=~=~=~=

1. HiZ
2. 1-WIRE
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
9. DIO
x. exit(without change)

Set speed:
 1. ~5KHz
 2. ~50KHz
 3. ~100KHz
 4. ~400KHz

 1. CS
 2. /CS *default

Select output type:
 1. Open drain (H=Hi-Z, L=GND)
 2. Normal (H=3.3V, L=GND)

Power supplies O

The 93LC46B's data sheet says the chip select needs to be held high before sending any commands, which is why I chose "CS" instead of "/CS" from the menu ("/CS" means the chip select pin is held low).

The other thing that got me was the output type. At one point, I selected "Open drain" and then couldn't figure out why CS wouldn't go to 3.3V when it was enabled. Something I found out while debugging this is the Bus Pirate's ADC connector can be used to measure voltages, up to 6V. At any rate, after realizing the CS problem was caused by the wrong output type, things started working a lot better.

The 93LC46B's commands take the form of a start bit, 2 op code bits, 7 address bits, and optionally 8 data bits for some write commands. This means having to tell Bus Pirate to write 10 or 18 bits. This is one way to from address 0:

3WIRE>[0b110;3 0b0000000;7 r;8]
WRITE: 0x06;3 
WRITE: 0x00;7 

The command broken down:

[            Enable CS
0b110;3      Write 3 bits: start bit '1', opcode '10' (read)
0b0000000;7  Write 7 bits: address 0x00
r;8          Read 8 bits
]            Disable CS

So far so good. I am able to issue 10-bit commands to the chip. These commands include write-enable and erase-all. (Erase writes '1' into each bit position). Unfortunately, I haven't got any 18-bit commands, which take data, to work. So I'm not yet able to write arbitrary data into the eeprom.

Lessons learned:

  • Learned how to wire up the Bus Pirate to a chip.
  • Got some experience with driving the BP in 3-wire mode.
  • Learned how to write words which are not 8-bits in length to the device.
  • The BP's ADC connector can be used to confirm the CS goes to the correct level.
  • Read the datasheet carefully, watch for gotchas like "write-enable must be sent before writing data or erasing cells".


Finally found the correct data sheet. Turns out the 93LC46B only operates in 16-bit mode. So that jumper in the first picture has no effect on the chip's organization. The correct command format takes 6-bit addresses and 16-bit data:

3WIRE>[0b110;3 0b000000;6 r:2;8]  // read two 8-bit words from address 0x00
WRITE: 0x06;3 
WRITE: 0x00;6 
READ: 0xFF 0xFF 
3WIRE> [2K
3WIRE>[0b100;3 0b110000;6]  // enable write
WRITE: 0x04;3 
WRITE: 0x30;6 
3WIRE>[0b101;3 0b000000;6 0x12;8 0x34;8]  // write 0x1234
WRITE: 0x05;3 
WRITE: 0x00;6 
WRITE: 0x12 
WRITE: 0x34 
3WIRE>[0b110;3 0b000000;6 r:2;8]
WRITE: 0x06;3 
WRITE: 0x00;6 
READ: 0x12 0x34 
Power supplies OFF
Power supplies ON
3WIRE>[0b110;3 0b000000;6 r;16]  // another way to read 16 bits
WRITE: 0x06;3 
WRITE: 0x00;6 
READ: 0x1234 

No wonder the chip wasn't accepting any data. Lessons learned:

  • Find the right datasheet. Be excruciatingly exact. A single incorrect letter or digit can waste a lot of your time.
  • Hardware doesn't return error codes. Either it works or you made a mistake. Figuring out where you went wrong is hard.

Monday, December 31, 2012

The Law of Comparative Advantage

Heard about Comparative Advantage on the CBC Ideas program, episode The Screw That Changed The World. The colourful analogy was: although Winston Churchill was a good bricklayer, he is better off to run the country and pay someone else to build his walls. Similarly, the brick layer is better off building walls, whilst paying W.C. to run the country. It's food for thought for someone like myself, who likes to dabble a bit in everything.

Monday, December 24, 2012

Nokia N8 Upgrade to Belle 111.040.1511

I've been putting off any changes to my N8 until I had a lot of spare time in case anything should go wrong. Up to today, I was running a custom Belle firmware (don't remember the details) that I had modified slightly (default analog clock, fixed some errors with the little icons along the top, etc). It was reliable and fast, and I loved the customizability. But a few months ago, the Store stopped working. It would load, but I couldn't go to the screen with My Stuff to check for updates, and I couldn't download new content.

Removing the custom firmware took a little research. The generally accepted procedure is to flash the N8 with the 11.5 Scandinavian version, after which you can install whatever you like: Anna, Belle, etc. Problem is, v11.5 no longer appears in Navifirm. After some hunting, I finally found a copy on the N8FanClub site.

Flashing the N8 did not take long at all.

  • Close all applications and make a full backup using Nokia Suite.
  • Power down the N8.
  • Remove the microSD card and the SIM (this may not be really necessary because I forgot once, and nothing happened. Still, may not be a bad idea).
  • Uninstall Nokia Suite to prevent it from popping up every time the N8 is reconnected to the computer.
  • Install Phoenix.
  • Copy the Scandi firmware to Phoenix\Products\RM-596.
  • Start Phoenix, select the port the N8 is connected to.
  • Press ctrl-R to rescan.
  • Select Flashing -> Firmware Update and press the button with the three dots.
  • Choose firmware 0598984 Scandinavian DG.
  • Press the Refurbish button.
  • After programming the phone is complete, it was necessary to manually power up the phone and abort Phoenix. For some reason, it was waiting for a communications check with the phone, but the phone stayed powered down. Fortunately, the phone didn't brick. Once the N8 powered up, it was clearly running older firmware and was ok. Yay.
  • Rename the Scandi RM-596 directory, to save it for next time.
  • Download the new firmware and put it in Phoenix\Products\RM-596. At first I downloaded and flashed 111.030.609 since that was the most recent version for my phone (059C8T6), but when I realized that it was an old version of Belle, I threw it out. Reflashed to Scandi 11.5, and grabbed nam_0599218. The product code doesn't match (0599218 vs 059C8T6), but I did confirm that nam = North America. It seemed like a low risk substitute. If anything went wrong, I could just reflash, right?
  • With the new firmware in the RM-596 directory, restart Phoenix and connect the N8.
  • Select the right USB port, press ctrl-R, and select Flashing -> Firmware Update again.
  • Select the button with the three dots. The new firmware (0599218 nam) should appear).
  • This time select Update Software.
  • After about 5 minutes, the phone has been updated.
  • Restore the phone from backup, and enjoy setting up your N8 again.

The curious thing is that after I upgraded with the nam 599218 firmware, my phone still shows Product Code = 059C8T6. Unexpected, but I can live with that.

Lamb Korma

A creamy stew with tender chunks of lamb. Lamb shanks take a long time to cook, but are cheap, flavourful, and yield a gelatin-rich broth. Based on this recipe from

Onion paste

  • 4 medium sized onions, halved and peeled
  • 8 cloves garlic, peeled
  • 2 inches ginger, peeled

Whiz in a food processor and set aside.

Nut paste

  • 1/2 cup almonds
  • 1/4 cup cashews

The quantity and ratio of nuts is approximate and open to adjustment. Chop the nuts in a food processor, adding water a little at a time until a slurry forms. From 1/2 cup to 1 cup of water will be needed. Set aside in a covered container. This nut paste won't be needed until the korma is almost done.

Spice load

  • 1 tsp cumin seeds
  • 8 black cardamom pods (crack open, save insides, discard shells)
  • 16 pepper corns
  • 14 cloves
  • 1-2 dried hot peppers (optional)
  • 4 cinnamon sticks, 3" long, each broken in half

Except for the cinnamon sticks, grind the spices with a mortar and pestle and set aside. The recipe takes a long time to cook, so a medium-coarse grind is enough. Be sure to crack open all the peppercorns, as they never seem to disintegrate on their own.

Yogurt thickener

  • 2 cups yogurt
  • 2 tsp flour

Whisk together and set aside.

The main event


  • 5-6 lbs lamb shanks, bone in. (Have the butcher cut each lamb shank into 3 pieces.)
  • Bacon fat saved from previous fry ups, or ghee, or olive oil
  • 1 tsp cumin seeds
  • 1/2 cup red wine (optional)
  • 2 cups water (approximate)


  1. Brown the lamb (while still frozen is ok, but watch for leftover bits of plastic wrapping) with the bacon fat in a large, heavy bottom pot and set aside.
  2. Let the pot cool for a few minutes.
  3. Add another spoon of bacon fat if necessary, and fry the cumin seeds for about a minute on medium heat.
  4. Add the onion paste, and fry until some of the moisture has evaporated. It will start turning greenish brown.
  5. Add the ground spices and broken cinnamon sticks, and fry for another 2 minutes.
  6. Add the lamb and mix well.
  7. Turn off the heat and stir in the yogurt / flour mixture. Slowly heat the mixture up to a bubble. Gradual heat is needed so the yogurt does not curdle. (Note: I use a medium heat and stir frequently. I've never seen the yogurt curdle yet.)
  8. Stir in the red wine and add water until the lamb is almost covered. Gently bring the mixture to a bubble again. Cover and simmer, stirring occasionally.
  9. After about 1.5 to 2 hours, the meat will begin falling off the bones. Debone or cut the meat off some of the larger chunks manually, to reduce cooking time. If desired, remove the bones, but scoop or push any marrow back into the pot.
  10. Optional: add raw, chopped potatoes, carrots, or other vegetables, and simmer until they are done. Cooked chickpeas can also be added.
  11. Once the lamb is tender and once the vegetables (if any) are done, but before the lamb falls apart, stir in the nut paste to thicken the broth. Simmer an additional 5-10 minutes on low heat.
  12. Season with salt and pepper to taste.

Serve with (basmati) rice

Tuesday, December 11, 2012

2005 Impreza headlight bulb replacement (again)

Two days short of a year after I replaced the Sylvania XVs on my Impreza, I had to do it again. I hadn't been paying attention, so one bulb may have burned out long ago. I just know that I had to drive home well after sunset with neither bulb working. The cool thing is while I was checking for a blown fuse at work before heading out, a fellow Subie driver wandered over to see if I needed help.

Once again, I chose the Sylvania XVs over the generic H1s at Canadian Tire, for a cost of $10 extra per pair. I like how bright they are, but I'll be on the lookout for bulbs that last longer.

It was not as warm this time, but at least it wasn't windy or raining. Also, I've upgraded my headlamp to a Petzl Tikka XP2, so the lighting situation was better.

Saturday, July 28, 2012

Lenovo x220t trackpoint problem and solution

So, it happens that the x220's screen rests on the trackpoint when it's flipped around in tablet mode. If the display wiggles enough to nudge the trackpoint, the cursor will drift away and refuse to go where the pen is pointing for 5-10 seconds. Pretty annoying, wouldn't you say? Took me awhile to figure out what was going on, too!

My "fix" is an AutoHotkey script to disable the trackpoint. I then configured the screen rotation button so that a long press triggers the script. Here's the AutoHotkey script:

; Enable either trackpoint or touchpad (toggle the setting)
Run C:\Program Files\ThinkPad\UltraNav Utility\UNAVOSD.EXE
Sleep 200
PixelGetColor, touchPadOnlyEnabled, 30, 135
if ( touchPadOnlyEnabled = 0xffffff )
  Click 300, 100 ; enable trackpoint
else ; trackpoint or both are enabled
  Click 300, 135 ; enable touchpad only

That is saved to "AutoHotkey.ahk" in My Documents. The file was actually created by AutoHotkey when I asked it to create a sample script. I just gutted it and added the above code. When the Left-Windows key is pressed together with the Z key, the action is triggered.

How it works is:

  • Run the Lenovo UltraNav Device Settings program, UNAVOSD.EXE. This is the same program that's run when you press Fn-F8. It requires that both the trackpoint and the trackpad be enabled in the BIOS.
  • Sleep for some time to let the on screen display (OSD) appear.
  • Peek at the UltraNav OSD to see if just the touchpad is enabled.
  • Enable just the trackpoint or just the touchpad depending on the pixel value retrieved in the previous step.

There are a few weaknesses about this script:

  • It enables only the trackpoint or the touchpad. I never enable both, but it's easy to change the logic if you like. FWIW, the coordinates of the "enable both" option is near x=300, y=65.
  • The script relies on hard-coded coordinate values and pixel color values. A change to the UltraNav OSD could break the script.
  • It relies on a sleep which may not be appropriate for slower computers.

To configure the screen rotation button, go to Control Panel -> Hardware and Sound -> Tablet PC Settings -> Set tablet buttons to perform certain tasks (aka the Buttons tab) -> Change. In the dialog, change "Press and hold" to "Press a key or key combination". Then enter the key sequence in the Keys field.

Hope that helps!