"In het verleden behaalde resultaten bieden geen garanties voor de toekomst"
About this blog

These are the ramblings of Matthijs Kooijman, concerning the software he hacks on, hobbies he has and occasionally his personal life.

Most content on this site is licensed under the WTFPL, version 2 (details).

Questions? Praise? Blame? Feel free to contact me.

My old blog (pre-2006) is also still available.

Sun Mon Tue Wed Thu Fri Sat
  3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Powered by Blosxom &Perl onion
(With plugins: config, extensionless, hide, tagging, Markdown, macros, breadcrumbs, calendar, directorybrowse, entries_index, feedback, flavourdir, include, interpolate_fancy, listplugins, menu, pagetype, preview, seemore, storynum, storytitle, writeback_recent, moreentries)
Valid XHTML 1.0 Strict & CSS
Using a JTAGICE3 programmer under Linux: Setting up permissions


Last week, I got a fancy new JTAGICE3 programmer / debugger. I wanted to achieve two things in my Pinoccio work: Faster uploading of programs (Having 256k of flash space is nice, but flashing so much code through a 115200 baud serial connection is slow...) and doing in-circuit debugging (stepping through code and dumping variables should turn out easier than adding serial prints and re-uploading every time).

In any case, the JTAGICE3 device is well-supported by avrdude, the opensource uploader for AVR boards. However, unlike devices like the STK500 development board, the AVR dragon programmer/debugger and the Arduino bootloader, which use an (emulated) serial port to communicate, the JTAGICE3 uses a native USB protocol. The upside is that the data transfer rate is higher, but the downside is that the kernel doesn't know how to talk to the device, so it doesn't expose something like /dev/ttyUSB0 as for the other devices.

avrdude solves this by using libusb, which can talk to USB devices directly, through files in /dev/usb/. However, by default these device files are writable only by root, since the kernel has no idea what kind of devices they are and whom to give permissions.

To solve this, we'll have to configure the udev daemon to create the files in /dev/usb with the right permissions. I created a file called /etc/udev/rules.d/99-local-jtagice3.rules, containg just this line:

SUBSYSTEM=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2110", GROUP="dialout"

This matches the JTAGICE3 specifically using it's USB vidpid (03eb:2110, use lsusb to find the id of a given device) and changes the group for the device file to dialout (which is also used for serial devices on Debian Linux), but you might want to use another group (don't forget to add your own user to that group and log in again, in any case).

0 comments -:- permalink -:- 13:57
Current measurement helper board

Recently, I needed to do battery current draw measurements on my Pinoccio boards. Since the battery is connected using this tinywiny JST connector, I couldn't just use some jumper wires to redirect the current flow through my multimeter. I ended up using jumper wires, combined with my Bus Pirate fanout cable, which has female connectors just small enough, to wire everything up. The result was a bit of a mess:

Messy setup

Admittedly, once I cleaned up all the other stuff around it from my desk for this picture, it was less messy than I thought, but still, jamming in jumper wires into battery connectors like this is bound to wear them out.

So, I ordered up some JST FSH connectors (as used by the battery) and some banana sockets and built a simple board that allows connecting a power source and a load, keeping the ground pins permanently connected, but feeding the positive pins through a pair of banana sockets where a current meter can plug in. For extra flexibility, I added a few other connections, like 2.54mm header pins and sockets, a barrel jack plug and more banana sockets for the power source and load. I just realized I should also add USB connectors, so I can easily measure current used by an USB device.

The board also features a switch (after digging in my stash, I found one old three-way switch, which is probably the first component to die in this setup. The switch allows switching between "on", "off" and "redirect through measurement pins" modes. I tried visualizing the behaviour of the pins on the top of the PCB, but I'm not too happy with the result. Oh well, as long as I know what does :-)

Improved setup Top Bottom

All I need is a pretty case to put under the PCB and a ╬╝Current to measure small currents accurately and I'm all set!

Update: The board was expanded by adding an USB-A and USB-B plug to interrupt USB power, with some twisted wire to keep the data lines connected, which seems to work (not shown in the image).

0 comments -:- permalink -:- 18:27
Updating the Xprotolab portable firmware on Linux

Xprotolab Portable

I recently got myself an Xprotolab Portable, which is essentially a tiny, portable 1Msps scope (in hindsight I might have better gotten the XMinilab Portable which is essentially the same, but slightly bigger, more expensive and with a bigger display. Given the size of the cables and carrying case, the extra size of the device itself is negligable, while the extra screen size is significant).

In any case, I wanted to update the firmware of the device, but the instructions refer only to a Windows-only GUI utility from Atmel, called "FLIP". I remembered seeing a flip.c file inside the avrdude sources though, so I hoped I could also flash this device using avrdude on Linux. And it worked! Turns out it's fairly simple.

  1. Activate the device's bootloader, by powering off, then press K1 and keep it pressed while turning the device back on with the menu key. The red led should light up, the screen will stay blank.
  2. Get the appropriate firmware hex files from the Xprotolab Portable page. You can find them at the "Hex" link in the top row of icons.
  3. Run avrdude, for both the application and EEPROM contents:

    sudo avrdude -c flip2 -p x32a4u -U application:w:xprotolab-p.hex:i
    sudo avrdude -c flip2 -p x32a4u -U eep:w:xprotolab-p.eep:i

    I'm running under sudo, since this needs raw USB access to the USB device. Alternatively, you can set up udev to offer access to your regular user (like I did for the JTAGICE3), but that's probably too much effort just for a one-off firmware update.

  4. Done!

Note that you have to use avrdude version 6.1 or above, older versions don't support the FLIP protocol.

0 comments -:- permalink -:- 10:22
Dynamic memory allocation debugging

Arduino Community Logo

While trying to track down a reset bug in the Pinoccio firmware, I suspected something was going wrong in the dynamic memory management (e.g., double free, or buffer overflow). For this, I wrote some code to log all malloc, realloc and free calls, as wel as a python script to analyze the output.

This didn't catch my bug, but perhaps it will be useful to someone else.

In addition to all function calls, it also logs the free memory after the call and shows the return address (e.g. where the malloc is called from) to help debugging.

It uses the linker's --wrap, which allows replacing arbitrary functions with wrappers at link time. To use it with Arduino, you'll have to modify platform.txt to change the linker options (I hope to improve this on the Arduino side at some point, but right now this seems to be the only way to do this).

0 comments -:- permalink -:- 21:47
Pretty lights!

I've been working on my own binary clock for a while now. I've managed to get the PIC microcontroller from Microchip working for some time now. After being busy with other stuff I slowly resurrected this project. Since the microcontroller part is mostly done (the software works, for the limited prototype hardware I have so far), I am focussing on the actual casing for the clock now.


The casing of the clock has a big influence on the rest of the hardware (and thus software) design. The basic idea of a binary clock is to have 3 rows of 6 LEDs each, one row for hours, minutes and seconds, each representing a binary number. Since representating a binary number isn't limited to leds but anything that can represent on and off, 1 and 0.

I'll settle for leds for now since they are easy to use and give pretty lights. The exact form is not decided yet. I had this idea of making the clock a very flat box, probably black, with 18 small (1cm) squares that illuminate (something like the TIX Pattern clock, but smaller). For that I would need white leds and colored, halftransparent plastic to put in the squares.

Shopping spree

So I went shopping today and returned with a bunch of stuff. I got some fully transparent and half transparent sturdy plastic from a hobby shop, I got some colored half transparent plastic from a carrying folder and a handful of leds in yellow, green, blue and white. I also returned with a toy gun (full metal, so nice and heavy!) for lextalionis perhaps, liquid latex that is hopefully fit for making LARP weapons and looking for a box of pins, a nice 1000 page book about hardware design of game consoles, but that's beside the point.

The box design

I also found a box meant to hold sewing accesoires. It is a half-transparent plastic that contains 18 compartments (or 17 really, since one panel is missing). When I saw it I got a vision of the backside of the box, every compartment being one bit of the clock, with leds inside.

It turned out this idea actually seemed to work out nicely. I haven't been able to try this with multiple compartments lighting up at the same time, I expect I need to add some extra (light) shielding between the compartments. Also, I need LEDs with a bigger angle. Since my leds focus the light in a tight angle, only a part of the compartment backside is lit. If I put the led within a compartement, only a small circle of light appears at the outside. I need to put the LED about 10cm from the backside to get full coverage, which is impractical and reduces light strength.

Though this design seems to be quite nice, there are two main disadvantages to it. First, when it is turned off, the clock will probably look butt ugly. After all, it's not more than a plastic bogs when the lights are off. Second, the box is big. It's way bigger than needed to hold the leds, wiring and other electronics. I would say somewhere between 95% and 99% of the space is unused. Not so nice.

I'll get some wider angle LEDS first and then I'll see if I'm gonna build it like this. For now the box serves as a way better storage for a bunch of resistors, leds and other electronic components than the small glass bowl that used to contain my electronic junk.

The squares design

As noted above, I was envisioning some sort of black box containing coloured squares that could light up. I tried this design using a few layers of paper (not black, but you didn't see the difference with the lights off) with a hole in them. I put a coloured piece of plastic with a white light behind it. This was not very succesful. The white light is so bright, you barely saw the blue colour of the plastic. When using uncoloured plastic, the light was just too bright to look in.

The other approach, using half-transparent uncoloured plastic squares, with coloured LEDs behind then, worked out better. The red, yellow and green leds had the advantage of being less bright (nicer to the eye). The blue led looked nice, but was still a little bright.

All leds suffered from the same problem as with the box design above: Their viewing angle is too small. I had to put the leds at a distance of around 5cm from the paper, which is way more that the thickness I had in mind. Also, due to this focussing the center of the square is brighter than the edges.

This looks like a very promising design. I need to get a decent piece of (black) wood, plastic or cardboard to do some more tests once I can get my hands on some wide angled LEDs.

Note to self: Get a cheap digital camera, since conveying these ideas in words is crappy ;-)

0 comments -:- permalink -:- 01:51
Showing 11 - 15 of 15 posts
Copyright by Matthijs Kooijman