Digispark on Ubuntu: fails to upload
Of course,’works on Ubuntu’ regularly comes with a disclaimer that you need to take some additional measures to get everything working correctly. The installation instructions work fine and install the Digistump core and tools in your .arduino local folder. Compilation is then as easy as with any Arduino-like product, but on my Ubuntu 16.04 installation, upload fails with the message: error during upload. “micronucleus: library/micronucleus_lib.c:63: micronucleus_connect: Assertion `res >= 4′ failed.
The troubleshooting page indicates that this is a permission problem, so I delved into that aspect. I added the suggested rules and ran the IDE as root, but to no avail. I then decided to run all steps manually, so I could debug the entire toolchain where needed. I also decided to install the latest version of Micronucleus, the tool Digistump uses to upload the sketch through the on-board USB.
Compilation of this simple tool failed due to missing USB headers, so I installed libusb (and libusb-dev):
sudo apt-get install libusb libusb-dev
Compilation then succeeded and after copying the executable to the Digistump tools folder, I was able to upload my demo sketch and blink the LED. Funny enough, the old micronucleus executable now also worked, so I must assume that my original problem did not have to do with permissions, but with missing libraries.
So,for anyone running into a similar issue: try installing libusb. Of course this is stated clearly in the troubleshooting page I linked above:
“…If you are getting an error (especially on ubuntu) when compiling or uploading sketches – try installing libusb …”
but it is easy to miss this.
Now, apparently you get this same error as well if you leave the Digispark in your USB port. You must remove it from the port, click the upload button in the Arduino IDE and then, after the prompt, insert the Digispark module. This will repower the module and leave it listening for programming requests for like 5 seconds. If it is still plugged in, the module will probably not accept the programming requests, which leads to these (rather silly) core dumps.