Adding analog input to the Pi using the Digispark

Warning Sign

Surely the rest of the process would be pretty straightforward – connect the dots, as it were. Boy, was I wrong.

The first thing you'll learn is that, if you plug the Digispark into a USB port on a running Raspberry Pi, the Pi immediately reboots. A sudden drop in supply voltage to the Pi because of a spike in current demand when the Digispark is turned on is big enough to reboot the Pi, as if you had unplugged it and then plugged it back in.

While the Pi is off, you have to plug in the Digispark so they boot together. The problem then is that the Digispark is only available for programming for five seconds after it boots. After five seconds, it goes offline and starts running whatever program is resident (by default, a program that flashes the onboard test LED). Of course, the Pi takes longer than five seconds to boot. By the time you reach the login screen, the Digispark has long since gone offline and is happily blinking its LED, completely oblivious to the rest of the world.

If you want to program the Digispark, you're going to have to do it on another a computer. No problem: Everybody has a laptop or desktop lying around they can use and any machine should do, right? Wrong.

The Digispark is very particular as to what computer it talks to. Plugging it into my laptop gave me nothing when I ran lsusb from a terminal. By running dmesg, I got what you can see in Listing 1. Moving it to another port, and then to an external hub, and finally to a cable did nothing to solve the problem. My computer and the Digispark stubbornly refused to acknowledge each other.

Listing 1

My Digispark Misbehaves

$ dmesg
[97935.284931] usb 2-1.3: new low-speed USB device number 7 using ehci_hcd
[97935.686143] usb 2-1.3: device not accepting address 7, error -32
[97935.759108] usb 2-1.3: new low-speed USB device number 8 using ehci_hcd
[97936.160528] usb 2-1.3: device not accepting address 8, error -32
[97936.160753] hub 2-1:1.0: unable to enumerate USB device on port 3

Three computers later, I still had not made any progress. Finally, the Digispark decided it liked my wife's antique Sony Vaio and started to behave:

$ # In programming mode (5 seconds)
$ lsusb
Bus 002 Device 010: ID 16d0:0753 GrauTec

Interestingly enough, the Pi also has no problem recognizing the device, but, as mentioned above, the five-second window makes it impossible to program from the Pi.

This, by the way, is not what you'll see when the Digispark is in run mode (i.e., five seconds after being plugged in). If it is not sending information back over the USB interface, you won't see the Digispark at all, but if it is, you'll see something like this;

$ lsusb
Bus 002 Device 032: ID 16c0:05df VOTI

Note how the device ID has changed completely. Compare the IDs and commercial names in the two listings and remember them, because it will come in useful later.

Apparently, another way for the Digispark, and other USB devices, to be recognized and connected is to use an external powered USB hub (i.e., one that plugs into the mains). I have yet to try this.

The Overload

The Digispark is a very specific, low-cost piece of hardware, so to program it, you need a very specific and admittedly low-cost piece of software. Although you could download and install the different bits, specifications, and programmer examples (which will be useful in future projects) from the Digispark homepage, I found it was easier just to download the packages supplied from their wiki [4]. In Linux, you'd download the DigisparkArduino-Linux32-1.0.4-May19.tar.gz (or ...-Linux64-... package, depending on your architecture) and unpack it into your working directory (I'm using the 64-bit version):

$ tar zxvf DigisparkArduino-Linux64-1.0.4-May19.tar.gz

The Digispark uses a special version of the Arduino IDE, and you can find the executable in the DigisparkArduino-Linux64/Digispark-Arduino-1.0.4/ subdirectory. Additionally, you might have to copy the supplied udev rules to make sure things work as expected:

$ cd DigisparkArduino-Linux64/
$ sudo cp 90-digispark.rules /etc/udev/rules.d/

While you are programming the Digispark in your new Arduino IDE, keep the device unplugged from your computer. When the time comes to copy your programs over, choose Tools | Board | Digispark (Tiny core) (Figure 2) and Tools | Programmer | Digispark and hit the upload button (the "Play" button with an arrow pointing to the right in the toolbar).

Figure 2: The version of Arduino supplied with the Digispark is preconfigured for this tiny board.

The following message:

Running Digispark Uploader...
Plug in device now... (will timeout in 60 seconds)

appears in the console window at the bottom of the IDE. Now is when you plug in the Digispark so your program can upload. The uploader informs you whether or not it has been successful.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Get your Pi to read analog data

    The Raspberry Pi still lacks analog GPIOs that would allow it to read directly from temperature and light sensors, or even humble potentiometers. With an inexpensive chip and some software-fu you can grant the Pi the gift of analog sensing.

  • A home intrusion detection setup (sort of)

    At least part of the popularity of the Raspberry Pi can be attributed to its high maker value; that is, a skilled maker with a Pi can build marvelous and beautiful things. Me? Not so much, but I was willing to try to build a home security system with the stuff in my junk box. Here's what happened …

  • A new way of no-solder prototyping

    The Grove system's standardized connector and multitude of devices allow quick and easy project prototyping with your favorite small-board computers.

  • Write your own drivers for Arduino

    So, you have some new kit for your Arduino – maybe some sensors or ICs – but programming them is clumsy and painful. Don't despair: You can make your life easier by writing your own drivers!

  • Use an analog sensor as a video game controller

    We put our Analog-to-Digital converter to work reading positions from an analog sensor (a potentiometer) and control a bat in a simple implementation of the classic Breakout game.