Convert Trinket to Digispark

The Trinket 5V and the Digispark share the same hardware design, right down to the LED being on PB1. Personally, I prefer the Trinket hardware over the Digispark, but the Digispark has a totally different ecosystem and is stackable, but for this article only the hardware design similarities will be exploited.

Digispark inherits most of it's personallity from the littlewire project, http://littlewire.cc/ and having been around longer there is a significant following of users. In addition to a pedigree heritage, there is a ready set of libraries available for the Digispark. I have used several with the Trinket without modifications with perfect success. So, with the bootloader of the Digispark a weebit smaller and the availability of a simple-to-use uploader program, micronucleus.exe (Windows,) I figured I should do a little Frankenstein doctoring and flash the Trinket hardware with the Digispark bootloader software. The results is excellent (or, said properly, my results were excellent.)

Micronucleus is a simpler tool than AVRDUDE, that is if one must be at the command line and upload the HEX anyway. One simply types "micronucleus CompiledFileName.hex" and you then plug in the Digispark after-the-fact! Micronucleus is polling for the connection so there is a 60 second window ... an eternity if you have been trying to hit the Trinket timing. Simply download micronucleus.exe and store it somewhere in your path, I put mine with my other Arduino stuff here: C:\Program Files\arduino_105\hardware\tools\avr\bin and then you can open a command window to your OS, CD to the Arduino GUI temporary directory and upload the HEX. This is not even painful and I have tested it on Win-Vista 32-bit with Arduino 1.0.5 without issue. Of course, the standard disclaimer of your results may differ is appropriate.

Digispark offers 100% Arduino GUI integration, but you must download the entire Arduino download and it is currently only at 1.0.4. But it is available.

Notes: - You MUST install the Digispark boards.txt file and core files, just like the Trinket. When this is successful, you will see the 4 Digispark entries under Arduino - Tools - Boards. You must compile with a Digispark board selected, not Trinket. - Core Files are here: https://github.com/digistump/DigisparkArduinoIntegration/tree/master/hardware/digispark - USB drivers, See step #3: http://www.instructables.com/id/Digispark-DIY-The-smallest-USB-Arduino/?ALLSTEPS - There is NO need to compile and upload... simply do a Verify (check mark) in the GUI. If you have your Arduino Preferences set to Show Verbose Output during compilation, then you will see the path in the console window.

For example: I selected the Fade Sketch from the Examples in Arduino 1.0.5 and selected the board: Digispark 16MHz. I changed the LED to be on PB1 (int led = 1; ) and compiled using the Verify option in the GUI (just the checkmark.)

C:\Users\owner\AppData\Local\Temp\build7518571963010665540.tmp\Fade.cpp.hex Binary sketch size: 904 bytes (of a 6,012 byte maximum)

I then opened a Command window and navigated to the directory with the HEX file. (On windows, just open Explorer and type %temp% and press Enter.) Navigating to the build directory, I type;

dir *.hex

Directory of C:\Users\owner\AppData\Local\Temp\build7518571963010665540.tmp

10/07/2013 11:53 AM 2,575 Fade.cpp.hex 1 File(s) 2,575 bytes 0 Dir(s) 102,306,967,552 bytes free

  • To upload, type:

micronucleus fade.cpp.hex

Sample of successful upload:

Please plug in the device ... Press CTRL+C to terminate the program. Device is found! connecting: 20% complete connecting: 23% complete connecting: 27% complete connecting: 30% complete connecting: 34% complete connecting: 40% complete Device looks like ATtiny85! Available space for user application: 6012 bytes Suggested sleep time between sending pages: 8ms Whole page count: 94 Erase function sleep duration: 752ms parsing: 40% complete parsing: 60% complete Erasing the memory ... erasing: 60% complete erasing: 70% complete erasing: 80% complete Starting to upload ... writing: 80% complete writing: 90% complete writing: 95% complete writing: 96% complete writing: 96% complete writing: 97% complete writing: 98% complete writing: 99% complete writing: 100% complete

Micronucleus done. Thank you!

If you are a DIY kind of Arduino person, this article will give you the basic information; Updated link http://www.instructables.com/id/Digispark-DIY-The-smallest-USB-Arduino/

Also, check out the Digistump forum for additional resources: http://digistump.com/board/

Please, Please, Please... you are off the beaten-path at this point. Support for libraries and bootloader must come from the Digistump Wiki/Forum. There is much information available via Google.

Have fun and remember the process can be "undone" by reverting to the Adafruit Trinket bootloader. A high-voltage programmer will be required if you set the Reset Pin as a digital I/O exactly like the Digispark.

Ray

Thanks Ray.
This would make a good post on your blog.
BTW, the instructables link is broken.

This one seems to work : http://www.instructables.com/id/Digispark-DIY-The-smallest-USB-Arduino/... Unless theres two of them...

Doc

Thanks guys, I had dropped in the link without the URL tags. Edited & fixed.

I also made a note about the Digispark use of Reset as I/O and the fact that an HV programmer would be required to regress to a Trinket IF one elected to take the recommended Digispark Fuse settings.

Ray

Does the conversion also work for the Trinket 3.3V ?

Gerhard34: Does the conversion also work for the Trinket 3.3V ?

If you look at the Trinket 3.3 schematic, you will notice the zeners missing and the addition on a 3.3V regulator. From their site:

There are two versions of the Trinket. One is 3V and one is 5V. Both work the same, but have different operating logic voltages. Use the 3V one to interface with sensors and devices that need 3V logic, or when you want to power it off of a LiPo battery. The 3V version should only run at 8 MHz. Use the 5V one for sensors and components that can use or require 5V logic. The 5V version can run at 8 MHz or at 16MHz by setting the software-set clock frequency.

Schematics and Github links: https://learn.adafruit.com/introducing-trinket/downloads

Ray

Thanks Ray!

I've seen the schematic and afak the 3.6 V zeners are only necessary for the appropriate voltage at the usb interface.

Should the micronucleus bootloader work for 5 V as well as 3.3 V ATTiny85? Unfortunately I only have some basic knowledge about micro controller - so I wonder if there is any difference in fuse bits, clock frequency, .... ore anything else between the 5 and 3.3 V version.

cheers Gerhard

Should the micronucleus bootloader work for 5 V as well as 3.3 V ATTiny85? Unfortunately I only have some basic knowledge about micro controller - so I wonder if there is any difference in fuse bits, clock frequency, .... ore anything else between the 5 and 3.3 V version.

From the Digistump site https://digistump.com/board/index.php?topic=465.0

Give it a go? I'm not sure what the brownout setting of the digispark is if indeed there is any.

To change the clock speed to 8mhz, use this function:

Code: [Select]

define CLOCK_SPEED_16MHZ 0

define CLOCK_SPEED_8MHZ 1

define CLOCK_SPEED_4MHZ 2

define CLOCK_SPEED_2MHZ 3

define CLOCK_SPEED_1MHZ 4

define CLOCK_SPEED_500KHZ 5

define CLOCK_SPEED_250KHZ 6

define CLOCK_SPEED_125KHZ 7

volatile void setClockSpeed(byte speed) { CLKPR = 0b10000000; // enable clock change CLKPR = speed; }

and call it from setup() as setClockSpeed(CLOCK_SPEED_8MHZ);

F_CPU will still be wrong though because it will still think the clock speed is 16.5mhz - this causes everything to run half as quick, including delays.

Disclaimer: I have never tried this. Once you set the fuses to Digispark settings, you will need a high-voltage programmer to reset - You have been warned.