Selfmade jumper wire for breadboards

  1. Find that ol’ solid copper wire in the hacker space while cleaning up the cable box.
  2. While watching a movie, idly cut the wire, strip it, and strengthen the ends with 1.6mm shrink tube.
  3. Profit!

Posted in Electronics | Tagged , , , , | Leave a comment

Usability Face Palm

Opening http://www.ruhrpilot.de/ in full-screen on a big monitor reveals this gem:

The text reads: “Es können nur Karten mit max. 1024×1024 Pixel angezeigt werden. Bitte veringern Sie die Auflösung Ihres Bildschirms oder minimieren sie das Browserfenster.” (in english: “Only maps with max. 1024×1024 pixel can be displayed. Please lower the resolution of your screen or minimize the browser window.”)

After blacking out every other pixel of my screen with a pen and minimizing the browser window, I am thoroughly disappointed with the result!

Posted in Usability | Tagged , , | Leave a comment

Testing Budget LEDs

I found a source for rather inexpensive crystal clear 10mm LEDs (easyseller24.de), which I want to use in the Borg16 project. But how well do they fare, without a datasheet to rely on? Building a quick LED matrix plugged into the CNC routed board, I could compare them side-by-side. The colors orange, yellow and red are at around 2V, while the others are at around 3V, so they had to be tested in two groups. Both were driven with 10 Ohm resistors. Here you can see the result (you can click the picture for a larger version), and there are more pictures of the test setup in the gallery below:

led-colors

The two lonely red LEDs at the lower right side are Kingbright brand LEDs (10mm red, clear), which are three times as expensive as the others, which are the following colors from the above mentioned shop: pink, blue, white, warm-white, green, orange, yellow, red. In general I can say that green is the brightest, followed by the white, blue and warm-white LEDs, leaving the pink far behind. The red-to-yellow tones are comparable in brightness, and especially the yellow and orange show a distinct center dot which is not very consistently manufactured. This is not necessarily a problem as there will be an opal acrylic sheet in front of them, which is emulated here by the plastic lid of an IKEA storage container.

Posted in Electronics | Tagged , , | 1 Comment

Joysticks!

Posted in Electronics | Tagged , , , , | 2 Comments

HSDPA USB stick repair

I noticed a friend of mine used a clothespin to keep her USB surf stick working, so I suspected a broken solder joint. It was easy to fix, so here are some disassembling instructions for that particular HUAWEI Mobile Connect (Model E160) HSDPA USB stick. It’s a real shame so much electronics is thrown away at the first sign of trouble, as quite a lot of it is actually repairable. Often it is a simple problem such as a broken solder joint due to mechanic stress or blown electrolytic caps due to wear. Happy hacking!

hsdpa-1

Time: 30 minutes

Tools: PH0x60 screw driver, soldering iron, solder

  1. Remove the SIM card, open the case by lifting it at the outer edge and following around the bottom until the lid comes off.
    hsdpa-2
  2. Remove the little plastic cover at the end (2 screws), then remove the top circuit board (3 self-tapping screws and a black screw with blue loctite). The top board is connected to the other by a connector, but lifts straight off with just a litte force. Finally, unhook the black plastic spacer that covers the USB connector pins.
    hsdpa-3
  3. On inspection, the USB connector was loose and one of its pins was lifted from its pad. Resoldering the pin and the little clamps (on both sides) fixed the loose connection and restabilized the USB plug. Using fine solder (0.5mm) for the pin is recommended, as there is not a lot of space to work in. Pay attention not to damage the various SMD parts nearby.
    hsdpa-4
  4. Assemble in reverse of disassembly.
Posted in Electronics | Tagged , | Leave a comment

Simplistic Square Wave Generator in Verilog

Doodling around with electronics, I wanted to measure the frequency response of a simple capacitor-resistor circuit. It’s easy to calculate, but usually there is a lot to learn from actually doing the experiment and dealing with the problems that pop up. The interesting part of the problem was actually how to create a driver for the input AC signal, as I don’t have a function generator here, and my analog circuit fu is not good enough to build one from scratch without help.

So I cheated using two hacks. First, I tried to drive a TBA-820M audio amp (vintage IC) in feedback mode. That worked fine, except that I couldn’t get it to oscillate above 700 Hz, which does not cover enough of the spectrum.

The other idea was to generate a square wave using an FPGA development board I had lying around. In the end, this didn’t work either. Although I could produce signals of a huge range of frequencies, the driver is far from ideal, and thus the frequency response of the circuit to be tested is distorted.

In any case, here is the simple circuit design for the FPGA chip in Verilog. First, I define the clock divider module that produces the desired output frequency by counting off a certain number of ticks from the input clock:

module clockdiv(input clk, input [24:0] ticks, output oclk);
  reg [24:0] tick = 0;
  reg dclk = 0;
  assign oclk = dclk;
  always @(posedge clk)  begin
    tick = tick + 1;
    if (tick >= ticks) begin
      tick = 0;
      dclk = ~dclk;
    end
  end
endmodule

There are 16 different frequencies, ranging from 10 Hz to 50 kHz, and a push button can be used to cycle through them:

module mode_selector (input next, output [3:0] omode, output [24:0] oticks);
/* External clock frequency divided by two gives number of ticks per second.  */
parameter frequency = 27000000 / 2;

reg [3:0] mode = 0;
assign omode = mode;

reg [24:0] ticks = 0;
assign oticks = ticks;

always @(posedge next) mode = mode + 1;
always @(mode) begin
  case(mode)
  0: ticks = frequency / 10;
  1: ticks = frequency / 20;
  2: ticks = frequency / 30;
  3: ticks = frequency / 50;
  4: ticks = frequency / 100;
  5: ticks = frequency / 200;
  6: ticks = frequency / 300;
  7: ticks = frequency / 500;
  8: ticks = frequency / 1000;
  9: ticks = frequency / 2000;
  10: ticks = frequency / 3000;
  11: ticks = frequency / 5000;
  12: ticks = frequency / 10000;
  13: ticks = frequency / 20000;
  14: ticks = frequency / 30000;
  15: ticks = frequency / 50000;
  endcase
end
endmodule

A push button is directly connected to an input I/O pin of the microchip. Unfortunately, a push button bounces when pushed and thus the signal is not a clean on/off but a very rapid succession of on/off states. In other words, the push button needs to be debounced. There are many ways to do it, I followed a simple approach. When the button is activated, we signal the event and start a timer to count down from 100ms to zero. Only when the timer reaches zero we allow another event to be sent.

module button (input clk, input butin, output butout);
parameter timeout = 27000000 / 10; /* 100ms */
reg [31:0] counter;
initial counter = 0;
always @(posedge clk)
begin
    if(butin)
           counter = timeout;
    else if(counter > 0)
      counter = counter - 1;
end
wire down = counter != 0;
reg prev_down;
always @(posedge clk)
begin
  prev_down = down;
end
assign butout = down == 1 && prev_down == 0;
endmodule

Now we can pick up the pieces:

module main(input USER_CLOCK, input GPIO_BUTTON0, output GPIO_HDR0,
            output GPIO_LED_0, output GPIO_LED_1, output GPIO_LED_2, output GPIO_LED_3);
wire [24:0] ticks;
wire [3:0] mode;
assign GPIO_LED_0 = mode[0];
assign GPIO_LED_1 = mode[1];
assign GPIO_LED_2 = mode[2];
assign GPIO_LED_3 = mode[3];

wire butnext;
button butn (USER_CLOCK, GPIO_BUTTON0, butnext);
mode_selector msel(butnext, mode, ticks);
clockdiv slowclk (USER_CLOCK, ticks, GPIO_HDR0);
endmodule

The four output LEDs are used to display the currently selected mode, very simple.

Posted in Uncategorized | Leave a comment

Installing Fedora 16

Random notes from installing Fedora 16, focussing on the negative things, because that is what is needed to make progress.

Installer failures:

  • The default ISO image is 32 bit, and one has to search for the 64 bit version. That’s ridiculous.
  • There is no default option to install a RAID + Encryption + LVM configuration, so the custom partitioning method must be used.
  • There is no way to start with a degraded RAID, so a spare disk needs to be available as backup.
  • The custom method does not create a GPT disk label at least under some circumstances, leading to a disk that not only doesn’t work, but even hangs up my AHCI BIOS detection routine.
  • This is particularly bad if the drive in question is known to hang up at BIOS POST (Seagate 7000.11) with a previous firmware. Chasing ghosts is no fun.
  • Although Fedora can not fix my BIOS, they can double check that the disk label and boot sector are OK. Truecrypt has very thorough consistency checks in their bootloader when using system encryption, going to the trouble of creating a rescue disk for restore. Fedora could do that, too.
  • The system does not come up because of a known bug in the installer. But the fix in the FAQ on the Fedora web site is incomplete and wrong.
  • The Fedora rescue system can’t even mount the resulting mess, it has to be mounted and repaired manually.
  • Reinstalling over a failed install fails because the installer crashes when it sees the RAID it created.

GNOME Shell failures:

  • The GNOME shell crashed when I restored my home directory from a test install, for unknown reasons (because it does give no diagnostics, just an empathetic smile). I suspect SE Linux.
  • The default theme has many issues: The terminal font is too bright on a white background, the fonts are mediocre, the active window title not distinctive enough. In the Tree Style Tab plugin of firefox, the active tab has no highlight at all anymore (it used to in Gtk 2).
  • There is no way to change the theme (the selection box in gnome-tweak-tools is greyed out). An extension that is supposed to allow theme changes on extensions.gnome.org is not installable due to a version mismatch.
  • Everything is so bright, it’s hurting my eyes. I’d love to use the darker theme that totem has on other windows, too.
  • I found out that ALT+Escape does something weird, it pops up black frames randomly across the screen, supposedly they should highlight application windows, but they are off by a fair amount.
  • The controls of gnome shell are not documented in the gnome-shell itself.
  • There is no way to remap the controls for gnome shell. I have a keyboard without a Windows key, so there is no way to get to the Activities screen with the keyboard.
  • gnome-tweak-tools has the ugliest splash screen I have seen in the last decade, but it still is a vital program that should be installed by default and widely advertised in the activities screen. Then make it pretty, please.
  • I could crash the gnome shell twice with the javascript console in 20 seconds, using 5 mouseclicks and 6 keypresses. Gratulations for making a safe language trivially unsafe. The second time it crashed, it brought down the entire session.
  • xbmc compiled and ran fine, then when quitting the program, the gnome shell and the session stuck. Only the mouse pointer moved, but there was no response to any input. I had to log in on the text console and kill the shell, so that it restarted itself.
  • I am too scared to try any extensions, but I know I will need them.

SE Linux failures:

  • Restoring a home directory from backup resulting in a gnome-shell crash. I suspect it’s a SE Linux thing, because after restoring the original home dir (which I just moved out of the way) it worked again and there were a bunch of SE Linux related warnings for dbus, gconf etc.
  • Installing a proprietary printer driver from Samsung required manual patching up the installed files.
  • The troubleshoot messages come with “fix this problem” instructions that don’t fix the problem.
  • Grepping for substrings in an audit log and then piping the result into a security policy manager. Srsly? LOL.

And…

  • Firefox sells my searches to Google.
  • Thunderbird spies on me at startup.
  • The installer asks me for confirmation if I don’t want it to spy on my hardware profile. Aside from overwriting all disks, this is the only time it asks for confirmation. At least it defaults to no. How sad is it that we have to be thankful for that?

I might update this as as I find out more. Sadly, this was a lot of trouble.

Posted in Uncategorized | Leave a comment

User Interface Design failure common in Mac OS X, Ubuntu Unity and Gnome Shell 3

It is not news by now that Canonical Unity and Gnome Shell 3 are considered flawed by many GNU/Linux developers (such as Linus Torvalds, Eric Raymond, and many passionate people with less known names). There are many flaws that hinder the short term adoption of these. Flaws that are fixable, but make them unusable until they have been developed beyond their current pre-alpha quality.

Let’s first talk about the shoddy programming quality. The crashes I have seen in Gnome Shell 3 have been spectacular, to the point of not being able to log in anymore at all (with all extensions disabled). Ubuntu never had high software quality (memory leaks in the system monitor, race conditions in ibus, misconfigured kernels, etc). Clearly, there is not enough man power behind these efforts to sustain both the design and the implementation work. Users shouldn’t be allowed anywhere near these projects for a long time, but, given enough interest in developing these ideas, these problems could be fixed if enough effort is made. So, although a show stopper at the moment, implementation quality does not need to be a problem for adoption in the future.

Second, let’s consider feature incompleteness. Breaking backwards compatibility is absolutely inexcusable for a shell. The irresponsibility on display here by both the Gnome Shell project and Canonical is staggering. They both break panel applet support, which disables high value productivity tools such as the hamster time tracker. Clearly, the reason is lack of resources. If they can’t even ensure that their own software works, hoping for them to support the software of others is certainly optimistic. Again, over time, the missing functionality can be regained, and then this does not need to be a critical flaw. Again, users shouldn’t be let anywhere near the Gnome Shell 3 and Unity until all the functionality is provided.

Third, any radical design change will struggle to achieve consistency. Here, Gnome Shell 3 seems to do okay from my limited experience with it, but Ubuntu has dropped the ball on this for quite some time. Like in the good old days of the emerging graphical desktop in GNU/Linux systems, we can now enjoy disturbing differences such as three different types of scroll bars, menu bars that are sometimes global and sometimes per window, and broken themes. In fact, theme support is now so terrible that installing any non-default theme is downright dangerous. I have seen irregular crashes and 100% cpu time consumption from choosing a non-default theme. This problem can be very hard to track down. But, over time, consistency can be achieved again, by doing the necessary hard work to fix all those little inconsistencies. This does not need to be a problem forever. Until then, users shouldn’t be allowed anywhere near Ubuntu.

Fourth, there is a lack of principled design and evaluation. The Gnome Shell 3 design page makes a lot of claims but provides no hard data to back it up. The usability testing plans are stuck in phase I indefinitely. And Ubuntu seems to progress on its “desktop experience” without taking a clue out of the limited usability testing they do. These systems want to be used by millions of people, yet they base their radical design changes on usability testing with zero (Gnome Shell) or two dozen (Canonical Unity) people. Again, this is probably due to limited resources, but again users shouldn’t be let anywhere near until the designs are proven, and then they should be marketed only towards the target groups for which they have proven themselves.

Sometimes, these problems go hand in hand. Gnome Shell 3 gets particularly instable if you use third party extensions, which you must in order to gain feature completeness. And there is no hope for consistency as long as these projects try to radically transform the “desktop experience” in the way they do.

Now, all these flaws must not persist forever. There may be a time when these problems are worked out, and then Gnome Shell 3 or Unity may actually be usable for some user group. Until then, these systems are unfortunately just another example of cargo-cult programming. They both imitate some of the features of a Mac OS X 10 GUI. Here are some examples that one or both copy:

  • The ALT-Tab behavior that switches between applications instead of windows.
  • The system preferences under a corner menu (Mac OS X: Under the apple logo in the upper left corner, Gnome Shell and Unity under the login menu in the upper right).
  • The Expose style application switcher.
  • The dock. Here, Gnome Shell diverges in that it makes the dock visible in the expose mode and not in the regular mode.
  • The icons in the dock, which do not start the program but move it up front. Plus an indication in the dock which applications are running.
  • In Unity, the global menu bar.

The big question will be if Gnome Shell 3 and Canonical Unity can overcome the above limitations and be more than a cargo cult.

However, there is one particular feature where the choice of Gnome Shell 3 and Canonical Unity is piss-poor. That is the imitation of the ALT-Tab behavior of Mac OS X, which switches between applications instead of windows. The reason behind that is very simple: The tasks a user needs to do is not defined by an application, but by a mix of windows from different applications. And a single application can have windows related to different tasks. I might have a gimp window, a browser window and a file explorer open for one task, and a browser window, a file explorer and a text editor for a completely unrelated different task. With application based switching, I have the choice between bringing up gimp, or both browser windows, or both file explorers, or the text editor. (If you are a power user, substitute file explorer with command line terminal).

I switch between windows relatively often. In fact, compared to any other graphical shell task such as starting applications, receiving notifications, or moving and resizing windows, I switch between windows an infinite number of times, while I almost never do any of the other stuff. Yet, switching windows is an insufferable experience on any of Mac OS X, Gnome Shell 3 and Ubuntu Unity. They all share this flaw, and until the computer is much smarter in detecting windows related to the same task, the only proper behavior for ALT-Tab is to switch between windows and not applications. The ALT-Tab behavior in Mac OS X is so bad that people are happy to pay money to change it.

I think of all problems in Gnome Shell 3 and Unity, this problem is the worst, because it is a fundamental error in the design. For Mac OS X, this problem may have been less severe in the past, because Mac OS users have a different application design, where more tasks are integrated in a single application (for example, you can edit pictures in keynote and iphoto, etc, so you would not necessarily run an image editing application and a presentation application at the same time for the same task) and because Mac OS users are probably less heavy keyboard users. But enter GNU/Linux, where applications follow the Unix philosophy of doing one thing and doing it right and people buy keyboards such as this or this or even make laptop buying decisions based on the keyboard quality. This is why cargo cult programming is bad: If the assumptions don’t hold, the results don’t work.

Another example of cargo cult programming is the attempt to bring tablet and smartphone user interaction principles to the desktop. On devices that have a keyboard and not a touch screen, and where the screen is about 30 times larger than that of a smart phone, that is just ridiculous. But, I have not focused this article on those attempts, because clearly the current designs are more focused at copying Mac OS X than smartphones and tables. That’s a mistake those projects can still make, and it should be prevented when it happens.

There are other problems in Gnome Shell 3 and Unity: The arrogance that is displayed by the designers in that they prioritize their ideas over everything else. The astonishing inability to listen to critical feedback. The violation of their own stated design goals (how does application switching in Gnome Shell 3 “reduce distraction and interruption”?). The refusal to perceive the Shell as a platform, that must have a supported way to extend it.

I don’t think that user interfaces need to be exclusive. What’s good for a beginning user should also be good for an advanced, expert user. The ALT-Tab behavior is wrong not because it prioritizes one user over the other, but because it does not serve either. It’s a gratuitous change in imitation of another successful operating system, without any research into the question if that system is successful because of that behavior or despite of it.

At this stage, Gnome Shell 3 and Unity are rushed projects that are based on imitation instead of innovation, but without the proper execution. No wonder they cause so much friction in the community. The proper resolution will have to wait until these projects have overcome the initial imitation phase and made their own experiences. Unfortunately, due to random accidents in history, these lessons will be made at the expense of many users of Fedora and Ubuntu who are thrown into this mess. For Ubuntu, this is particularly frightening as it was marketed as a good beginner system for a long time. This was only true as long as it was based on the stability and development efforts of the community. There is little evidence so far that Canonical can single handedly revolutionize the “desktop experience”. So, as things stand, I have more hopes for Gnome Shell 3 to eventually become a viable solution, given enough iterations. Until then, it’s wait and watch.

Posted in Uncategorized | 3 Comments

A better iterator for couchdb-python

The most used python library for CouchDB seems to be couchdb-python. It is a simple little library that makes accessing a couch database a breeze, but it has a serious limitation when using views: The first thing it always does is to fetch all rows in the view. Then it processes them and keeps them as a list in memory. Because it is using simple data types (as opposed to a C extension or at least records), these lists have a huge overhead of about 1 KB per row (ouch!). And, this does not only affect custom views, but also the _all_docs view that is used to iterate over all documents in the database.

The bottom line is that a simple program such as the following can bring couchdb-python to a crawling halt as it tries to load all document ids into memory:

import couchdb
couch = couchdb.Server()
db = couch['mydatabase']

# This is dangerous.
for doc in db:
    pass

The problem is that this is the code shown in the documentation, and that it works just fine for small databases (say, up to 100,000 rows). But once you scale up the workload in your database, it starts to degrade. Python programmers will recognize that this is the same problem as with the range function, and that was fixed by xrange. Unfortunately, the authors of couchdb-python repeated this mistake. This is not good. Database software is all about scaling, and it is easy enough to design your software from ground up around that principle.

To show how it can be done, I wrote a paginating iterator for couchdb-python. Now, pagination in CouchDB is slightly convoluted, but not terribly so. It’s only a couple lines of code:

def couchdb_pager(db, view_name='_all_docs',
                  startkey=None, startkey_docid=None,
                  endkey=None, endkey_docid=None, bulk=5000):
    # Request one extra row to resume the listing there later.
    options = {'limit': bulk + 1}
    if startkey:
        options['startkey'] = startkey
        if startkey_docid:
            options['startkey_docid'] = startkey_docid
    if endkey:
        options['endkey'] = endkey
        if endkey_docid:
            options['endkey_docid'] = endkey_docid
    done = False
    while not done:
        view = db.view(view_name, **options)
        rows = []
        # If we got a short result (< limit + 1), we know we are done.
        if len(view) <= bulk:
            done = True
            rows = view.rows
        else:
            # Otherwise, continue at the new start position.
            rows = view.rows[:-1]
            last = view.rows[-1]
            options['startkey'] = last.key
            options['startkey_docid'] = last.id

        for row in rows:
            yield row.id

It is used like this (but could also be integrated in couchdb-python as the __iter__ method):

import couchdb
couch = couchdb.Server()
db = couch['mydatabase']

# This is always safe.
for doc in couchdb_pager(db):
    pass

The important concept in the implementation is the bulk size that specifies how many records should be requested at once. I have measured wall time and memory use of the above code as a function of the number of records per request. The couchdb-python implementation behaves as if bulk is infinite, which puts it at the far right of the diagram.

The diagram does not show the whole truth: Even though couchdb-python is at the far right, that does not mean it is the fastest solution, for two reasons:

  • At high memory pressure, the performance of the operating system degrades. I can’t show this in the diagram, as I have more RAM than python needs for my database. But for small RAM or large database configurations, the performance will get bad very quickly as the system starts to swap pages in and out of memory.
  • The diagram does not show the latency of the implementation. The latency is the time between processing any two rows. The higher the number of records per request is, the higher is the latency between the last row of a batch and the first row of the next one. There are various aspects to latency (maximum lag, jitter, etc). The latency behavior of couchdb-python is the most uneven possible: First it loads all rows into memory, then processes them all. That means you have to wait a long time until you can process the first row, although then you can process all rows immediately. Most of the time it’s better to process data more evenly in smaller bursts.

A couple of notes on the measured performance data: For small bulk sizes, the overhead due to the high number of small requests increases quickly. The workload shifts towards the CouchDB server (1.6 times the CPU usage of Python). For average bulk sizes, the throughput approaches its optimum, and the workload evens out at 1.2 times the CPU usage of Python for the CouchDB server. Memory usage in Python increases linearly with the bulk size once the initial allocation at 10 MB is exhausted. CouchDB has constant memory use at 20 MB throughout the whole measurement, no matter what the bulk size.

So, what is the optimum bulk size? Clearly, too small bulk sizes increase the overhead due to the high number of small requests. But too large bulk sizes increase the memory footprint and latency problems. The right value is somewhere in the middle. Where exactly? For the given machine configuration, I put it at 5000. There is no increase in throughput for larger bulk sizes, while for smaller bulk sizes, there is a measurable decrease in throughput. Also, I favor real time over memory use, for a simple reason: The only way I can reduce the wall time is by increasing the bulk size. But memory use can be optimized in Python by a factor of 100 by using better data structures to store the row data. So, throughput and latency are the important factors, while memory use is only a secondary concern.

Posted in Uncategorized | Tagged , , , , | 2 Comments

Parsing Unicode text with Python PLY

Python PLY is quite helpful in writing a simple scanner and parser, but I had some trouble figuring out how to make it accept Unicode tokens. I kept getting weird errors like this:

Getr. Zählung
Syntax Error: '̈hlung'

The syntax error is displayed as an h with umlaut, something that does not even exist in German. On closer inspection, the problem turns out to be the COMBINING DIAERESIS character, which prevents the regular expressions in PLY from matching.

The solution is to use the Unicode normalization form KC (Compatibility Decomposition, followed by Canonical Composition), and to make sure that PLY uses unicode for matching:

lex.lex(reflags=re.UNICODE)
lex.input(unicodedata.normalize('NFKC', s)

Update:

Because I keep losing this snippet, I will record it here. It’s what you add at the top of the file if print doesn’t work. Don’t ask.

import codecs, sys
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
Posted in Uncategorized | Tagged , , , | Leave a comment