Gerrit Niezen

Maker of open-source software and hardware.

Feature image

A week ago I wrote about what a user-space USB driver is and how they work great on macOS and Linux, but not on Windows.

Today I started working on two user-space USB drivers for Node.js. The first one is for the Prolific PL2303 chipset. We have quite a few diabetes devices at Tidepool that make use of the PL2303, like the IR dongles used by the Animas pumps. When using this driver there is no kernel extensionon required on macOS anymore, and you can connect directly to the device over USB.

The PL2303 driver code was originally written by a former CTO of Mozilla, Andreas Gal. He co-founded an IoT company (Silk Labs), so my guess is that he wrote this driver for one of his IoT experiments, as it's on his personal GitHub profile. Silk Labs have now pivoted from IoT to embedded AI, so I doubt he is interested in maintaining his code. I've forked his repo and started adding some improvements, like specifying the baud rate. I also want to publish this as an NPM package.

In addition, I started working on a Silicon Labs CP2102 user-space driver for Node.js today. And once that works, I'm planning on porting my WebUSB Texas Instruments 3410 USB driver over to Node.js as well. User-space drivers FTW!

Comment on this post

Feature image

I've been enjoying a new e-mail newsletter by James Bowman of Excamera Labs. James is the creator behind awesome electronics projects like the Gameduino 2, a full colour touchscreen for Arduino.

He has a bunch of new projects at the moment, like the SPIDriver that let's you connect to SPI devices from your computer. And some of these projects he is building at home, as he explains in the latest edition of the newsletter:

For short-run through-hole PCB assembly, there's not much point in having these made abroad vs. making them yourself. Either way an 18-year-old with a soldering iron will be doing the work.

He pays his son $12 per hour for assembly and here is his argument on why it's a good thing:

It's also good just to get young people involved. Often when we're thinking of ways of introducing people to technology, we think of putting them in class. They already spend a lot of time in class! Much better to engage them in something practical and slightly unfamiliar. They seem to find it satisfying, and catching the inevitable failures gives them a hands-on insight into how things work.

I don't know what your high school work experiences were like, but I feel like maybe he's got a point. He goes on to explain how, due to Chinese manufacturers now selling directly online, getting electronic components doesn't have to be expensive. Buying 350 components of specific type would cost him $144 from a US distributor, while he could buy it directly from the Chinese manufacturer for $15.

In an earlier edition of the newsletter he describes how to make a “placement stencil” using a laser cutter, which makes it very easy to place components on a PCB by hand. Stencils for applying soldering past are also cheap nowadays, and you could get an IR reflow oven for a reasonable price as well.

In short, if you're making hundreds (instead of thousands) of something, it may just be easier and cheaper to do it yourself, even if said something is electronics.

#Electronics #Making

Comment on this post

Feature image

On Sunday I made some bobotie and we had the leftovers for dinner tonight. It is a typical South African dish mainly consisting of mince meat with raisins and covered with an egg-milk mixture, baked in the oven.

We got a packet with the recipe and most of the required spices in South Africa when we last visited in February, and all the remaining ingredients are readily available here in the UK, including the South African chutney brand Mrs. Balls. I think it may be the only product on British supermarket shelves with Afrikaans instructions on it: “Skud die bottel”!

Comment on this post

Feature image

In December I got the Ananas soldering kit as part of a Boldport Club subscription.

IMG_4674

The Ananas is a three-dimensional PCB with LEDs that flash with different timings. It was great fun soldering it together in January, but I wanted a nice stand for it so that it doesn't fall over.

Luckily someone else had the same idea and posted a stand design to Thingiverse. I just printed it out and it works great!

ananas

#Making

Comment on this post

Feature image

I'm just sitting around this lazy Sunday afternoon stitching my son's blanket and watching some tennis.

We cut his favourite blanket into four pieces, so that there is always one of them available when he needs it. I've never stitched before, but after a quick introductory lesson by my wife it's been reasonably easy going so far. The trickiest part is threading the needle.

I don't usually watch tennis, but for the first time in nearly a century[1] there is a South African playing in the final at Wimbledon. Let's see what happens!


  1. 97 years to be exact ↩︎

#Making

Comment on this post

Feature image

We just bought our first house! We've been living in Swansea for almost six years now, so it was probably good time to get a home of our own. It's been an interesting experience purchasing a property here in the UK, trying to figure out which things the estate agent deals with and which things you go to your solicitor for.

It took quite a few months from getting an offer accepted (where it's then considered “sold subject to contract”) to finally getting the keys. Usually there are a couple of weeks between exchanging the contracts and completing the sale, but for us this all happened on Friday.

It's both existing being a new homeowner, and also a bit scary in terms of responsibilities when things go wrong. But hey, I guess we'll take it as it comes!

Comment on this post

Feature image

I found these battery holders on Thingiverse. I printed the one to hold AAA batteries a while ago, and printed the AA one last night. The thing on the right is my honeycomb cable holder for USB cables.

AA_holder

I go through a lot of batteries for my Tidepool work, given that I have dozens of glucose meters and insulin pumps that need to be powered. It's nice to have a compact and stackable design to keep them all in one place.

When I eventually start using an different colour filament I can print the lettering that goes on the front. For now, it looks fine even without the different colours.

#Making #Tidepool

Comment on this post

Feature image

When you need to install a driver to get your USB device working, this driver is installed in kernel-space. On macOS this is called a kernel extension , which is a nice descriptive term. On Linux it's usually not even necessary not install anything, as support for almost every USB device is already built into the kernel. On Windows, the situation is ... a bit different.

With the release of macOS High Sierra, Apple is making it really difficult to install kernel extensions. Some have even called it a kextpocalypse. While I think Apple have made some serious UX mistakes in implementing this, I do agree with the sentiment regarding security. Kernel-space drivers run in a highly privileged mode which can seriously screw with your machine.

There is a great macOS app called Serial for connecting to serial USB devices. The first time I used it felt like magic, as it was able to connect to devices without having to install any kernel extensions. I contacted the developer and he explained that he basically wrote user-space drivers for all the devices.

Yesterday I added a user-space USB driver for CDC-ACM devices[1] written in Node.js by Nordic to the Tidepool Uploader. It works great on Linux and macOS, but not on Windows.

The reason is that even if you have a user-space driver, you still need to install a USB driver on Windows. That is because Windows apparently can't tell on its own that a USB device is a USB device and you always have to install a driver to tell it that.

The result of this is that Microsoft essentially requires anyone who want to use a USB device (that doesn't have a driver already built into Windows), to have administrator privileges and install a driver to use said device. Contrast that with macOS, where Apple effectively said with High Sierra that they don't want people to install drivers, so that user-space drivers are basically encouraged.


  1. that includes the Dexcom receiver and Tandem insulin pump we support at Tidepool ↩︎

#Tidepool

Comment on this post

I still haven't successfully received data from the meter, but analysing the USB packets using the logic analyser that I started with yesterday has been super helpful.

After I discovered yesterday that there wasn't any USB bulk transfer data being sent on the bus, I had a look at the relevant code and it turns out that I didn't define two of the registers correctly. Once that was fixed I could successfully load data into the SNDFIFO register, put the number of bytes to be sent in the SNDBC register, and send it on its way. I verified using the logic analyser that my bulk transfer data was now appearing on the USB bus.

Unfortunately, nothing is coming back yet. I figured that maybe I should try to sniff the packets between my WebUSB app and the cable, so I opened up my USB hub:

usbHub

After my initial surprise to discover that the PCB is purple[1], I connected the logic analyser the same way I did yesterday – straight to the USB connector.

And guess what? It worked great. I can see USB traffic between an app on my computer and a device connected to my USB hub, down to the bit-level. This means I can even sniff USB traffic on macOS El Capitan and Sierra, where Wireshark doesn't work. Now to figure out what is different between the WebUSB-to-device and Espruino-to-device communication.


  1. I've only ever seen purple PCBs from the awesome OSH Park ↩︎

#Electronics #Tidepool

Comment on this post

Today I want look at analysing what exactly is happening on the USB bus when we send and receive messages, to make sure that what I think is happening is actually happening. On a Windows or Linux machine this can be done with Wireshark. I think it may also be possible on macOS since the High Sierra release. However, we're working with a USB host controller chip, so Wireshark is a no-go.

There are professional-grade USB analysers from Total Phase that start at around \$475 (for USB 2.0 full-speed 12MBps) all the way up to \$6000 (for USB 3.0 5Gbps). While we should be able to use the 12Mbps analyser, I wanted to see if it's possible to use a little $10 logic analyser to analyse USB traffic:

This little $10 logic analyzer arrived on Friday and I am looking forward on using it with the awesome open-source @sigrokproject software. It would be great if I can get it to sniff some low-speed USB traffic. pic.twitter.com/Awhb9pSzvm

— Gerrit Niezen (@gendor) October 2, 2017

That was almost ten months go, and since I'm still struggling to figure out why I'm not getting any results back from the meter, I decided to give it a try. This 8-channel 24MHz logic analyser was only £13.44 (including P&P). It comes with a set of test hook clips, which I was able to connect to the USB port surprisingly easy:

hooksusb

The pins at the back of the USB connector has just enough space so that you can attach the hook clips. The USB connector pinout is +5V, D-, D+ and GND, so I had another look at the schematic on the Sparkfun website. It showed that D+ and D- are connected to resistors, while +5V is connected to an overcurrent protection device. Based on this I could identify which side was +5V and connected the hook clips. I connected D- to channel 0 on the logic analyser and D+ to channel 1, and GND to ground. I also connected D2 to CH2 to use as a trigger:

logicSetup

Now it was time to install the sigrok PulseView software. I chose “fx2lafw” as the driver for my analyser, and when it successfully connected, defined the three channels for D-, D+ and the trigger. I selected the maximum available frequency (24 MHz) and 1 G samples, which should allow for 42 seconds of sample time. I then added the USB signalling decoder with USB packet and USB request decoding, and specified the appropriate signals and full-speed signalling:

sigrok1

I also added digitalWrite(D2, 1) in my code where I wanted the trigger to occur. I started up the Espruino code and clicked on Run:

firstSession

I was successfully sniffing USB packets between the TUSB3410 chip in the cable and my USB host controller chip! After verifying that most of the packets I was sending were actually appearing on the bus, I noticed that my bulk out transfers were missing:

missingPackets

Above you can hopefully make out the setup packet 40 05 00 00 03 00 0A 00, which should be followed by some data. Instead it is followed by the “close” packet 40 07 00 00 03 00 00 00. So maybe that is where I should start looking as to why things aren't working!

#Electronics #Tidepool

Comment on this post

Enter your email to subscribe to updates.