Category: B work

PDB for n00bs

PDB is the python debugger, which is very handy for debugging scripts. I use it two ways.

If I’m having a problem with the script, I’ll put in the line

import pdb; pdb.set_trace()

just before where the problem occurs. Once the pdb line is hit, I get the interactive debugger and can start stepping through the program and seeing where it blows up, and what variables are getting set to before that happens.

However, I recently found a very handy second way. I was debugging a script with a curses interface, which cleans up when it exits. Unfortunately, that cleanup means that my terminal gets wiped when something crashes, so instead of a stack trace, I just get dumped back to the terminal when something goes wrong, with no information at all left on the screen.

Invoking the script with

python -m pdb ./my_script.py

gets me the postmortem debugger, so when something goes wrong, the program halts and I get the interactive debugger and some amount of stack trace. It’s messy looking because of curses, but I can at least see what is going on.

Safety third!

Say what you will about globalization and the downfall of the USA, I still like ordering stuff from China. It’s cheap, and it takes so long to get here that I forget I ordered it, so it’s a surprise to me.

Recently, I got a bunch of li-poly battery monitors. These (not surprisingly) monitor li-poly batteries and sound an alarm when the battery voltage gets too low. Overdischarging a li-poly battery can damage the battery fairly quickly, and so may mean you have to buy a new battery. This is far better than overcharging them, which can start a pretty dramatic chemical fire.

The monitors I got are these or something very like them. The ones I have have a button which you can press to set the alarm voltage, with a default of 3.3V/cell.

Like a good hacker, I immediately opened one of them up. It has two ICs, one of which is a Atmel 24C02BN, which is a 2kbit I2C EEPROM. The other is unmarked. I had high hopes that it would be an Atmel part as well, or at least marked, so that I could possibly reflash it with my own firmware.

Having 16 pins counts it out from being any of the ATTiny or ATMega series, as well as any of the 8, 16, or 32-bit PICs. I imagine it’s something like an Elan microcontroller, and probably not super-well documented.

I did also find out that the speakers are simple dumb speakers, not beepers, so the micro generates the audio waveform for them. That means if I want to use the beep as a shut-off signal, I’ll have to do a little filtering, or add a 555 as a pulse stretcher.

Flickr Downloadr that really works

Not my work. Get it here.

It does exactly what it says on the tin. This is letting me close a years-old open loop I had, which is that Flickr had a lot of my photos, but sucked so bad that I didn’t want to reward them with money in order to get my photos back.

As soon as the download is done, that Flickr account is toast.

Un-Ubuntuing Ubuntu, Again

Ubuntu makes no secret of the fact that they will choose something that looks good but doesn’t work over something that works. That’s pretty much the entire point of this blog post. Because xscreensaver uses an older X widget kit than light-locker, and so looks “antiquated”, they switched to light-locker for 14.04. Light-locker doesn’t atually work well, and causes many, many, many laptops to not return from suspend mode without a hard reset.

If you’d rather use software that works, you have to change some settings and remove a bunch of stuff. I removed light-locker, light-locker-settings, and gnome-screensaver. I also installed xscreensaver.

In order to lock on lid close, I started xfce4-settings-editor, selected xfce4-power-manager, and set/checked both lock-screen-suspend-hibernate and logind-handle-lid-swtich.

I currently get two login prompts when I unsuspend, one from xscreensaver and one from something else. I suspect the second one is logind, so I can get rid of the xscreensaver one by making xscreensaver not do screen locking.

I waste time to not waste time

I’m using a web server on my local machine plus an edited /etc/hosts file to serve up a page that reminds me to get back to work when I should be getting back to work, rather than, say, reading facebook. Yes, I can get around this by clearing my hosts file, but that makes it work to get to the blocked sites, and if I’m going to be doing work, it’s not time-wasting is it?

The hosts file looks like this:

ams@robot-lab7:~/weblock$ cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
#I elided a couple of lines here
127.0.0.1 www.facebook.com facebook.com
127.0.0.1 www.dresdencodak.com dresdencodak.com
127.0.0.1 www.xkcd.com xkcd.com
127.0.0.1 www.boingboing.net boingboing.net
127.0.0.1 ab3nd.livejournal.com livejournal.com
127.0.0.1 www.questionablecontent.net questionablecontent.net
127.0.0.1 www.hackday.com hackaday.com

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

That takes care of redirecting a lot of pages to localhost, rather than their real IP addresses. On my computer, I have a little web server, which is launched with the command
sudo webfsd -p 80 -f index.htm -u ams -r /home/ams/weblock/

Webfs, and it’s daemon part webfsd, is a static-file-only http server. In this invocation, it runs as my user after binding to port 80 as root, and serves the file index.htm out of the directory /home/ams/weblock. That file is a very simple HTML file:

<div style=”display: table; height: 100%; width: 100%; background: #fff; _position: relative; overflow: hidden;”>
<div style=”_position: absolute; _top: 50%; display: table-cell; vertical-align: middle; text-align: center;”>
<h1>What should you be doing?</h1>
</div>
</div>

It just shows the text “What should you be doing?” in the middle of the page. This is also interesting because it shows how to center HTML content in the middle of the page, at least for small content. I’m not sure how well this works with larger or more complex content.

Direct-to-PCB laser printing

“Also, contrary to popular belief, there’s no issue with laser printing on a conductive surface.” – from here.

I’ve seen this in operation at Worcester Polytechnic Institute. There, the flexible/soft robotics lab uses copper tape on plastic substrate to make PCBs, sticks them to a sheet of paper, and runs it through a totally-normal, unhacked laser printer. Copper tape is probably thinner than PCB copper, so it ends up not sinking too much heat away from the fuser. The resulting PCBs can be etched right out of the printer, with no ironing step in the middle.

I have to hit a hardware store at some point this week, perhaps I’ll be able to get copper tape there.

Robosapien Repairs

I got a Robosapien V2 on Craigslist for very short money, and started working on turning it into a robot. This doesn’t interfere with my other projects because the stuff I’m using to robotify it is the same codebase I’ll be using for brain hacks at Defcon and and a drink dispensing robot at future festivals. But I digress.

On powering it up, the Robosapien complained about a “low brain battery” and turned itself off. When I replaced the batteries, it failed to do anything at all. I checked a few forums, and it turns out that the problem is the wire insulation failure that struck a lot of the Robosapien V2s. The problem is that the insulation on some of the wires, particularly the ones that are single strands, rather than part of multi-wire cables, is bad. It becomes brittle and crumbly, and then flakes off when the robot moves. This causes the batteries to short out, and die quickly, if you are lucky. If you are not lucky, the Robosapien melts or catches fire.

In my Robosapien, the affected wires appear to be confined to the leg wiring harness, particularly the motor wires, battery leads, and wires from the foot switch PCB to the main PCB. To fix this, I’m going to extract the wires, and replace them with un-crappy ones. It’s kind of a tedious job, but I am actually kind of looking forward to it as a way to unwind at the end of the day. Have a beer, replace a bunch of wires, chill out.

Furniture building

Most of my projects are on hold until I get a place to work on them. My current lab is about 11′ x 12′, with a little storage room off to the side. It’s not big enough to store my tools and provide a useful workspace, so I’m improving it in two ways.

The first improvement is to cut down on stuff. I own a lot of things that I’m not using, and don’t even have any really clear plans to use, so I’m collecting all that junk and putting it in boxes. Some of it is going to friends who are worse hoarders have clearer plans for it than me. Anything that people don’t take is going to have a chance to get sold at the MIT Flea Market in April, and then is going to get thrown away. Once I’m done getting rid of stuff, I’m going to start tagging things when I use them, and get rid of the stuff that I don’t use for a year. I’m not going to be terribly strict about this, but I am going to give it a shot, and see how much of the stuff I actually want when it comes time to get rid of it.

The second improvement is to make a useful workspace. I used to have a large corner desk, which I used for all sorts of work. Since I didn’t have space for that in my current apartment, I got a smaller desk from a friend. It’s a cute desk, but it isn’t useful. The top has drawers that open over the desk area, so you can only get at the contents of the drawers if you don’t have anything on the desk. That doesn’t happen with desks I own. Aside from that, it’s too small to accommodate tools, a computer, and a project, and since many of my projects involve both a computer and tools, this is a problem.

To replace the useless desk, I’m building a new workbench. It’s a standing desk, with a 5’4″ x 3′ upper surface made of birch plywood. The underside will have some space for storage and my computer. Since the computer desk and the work desk will be consolidated into one workbench, I’ll be able to get rid of both my computer desk and my current workbench, and both the chairs in front of them, and the pads that protect the floors from the chairs. I’ll probably keep at least one of the chairs around, in case I need it in the future, but it won’t be in my lab.

The category of this entry “B Work” refers to work which is intended to accelerate the thing you really want to do, which is your “A work”. “C work” accelerates your acceleration, and so very little of it needs to be done in comparison to the other two.