Digistump Forums

General Discussion => Other Arduino Talk => Topic started by: probono on January 01, 2013, 02:05:17 pm

Title: Building a Digispark compatible breadboard circuit
Post by: probono on January 01, 2013, 02:05:17 pm
The Digispark is basically an ATtiny85 running the Micronucleus bootloader. Here's how to build one yourself on a breadboard. This certainly doesn't look at good and definitely isn't as small as a real Digispark, but it can shorten the wait until you get your board.

Note that this is not the official circuitry (which I did not find online despite the board being advertised as "open hardware"), but from what I can see it's reasonably compatible.

CAUTION: While this works for me, I do not guarantee that it might work for anyone else. I assume no responsibity for any damage this might cause. Use on your own risk. Do not build this if you do not understand the circuitry.

Materials needed:
* 1 ATtiny85-20PU
* 1 Breadboard (could be saved if this is built on a PCB)
* 1 3.3V LDO voltage regulator, e.g., MCP1702
* 1 10 uF elko for the voltage regulator - it doesn't work otherwise
* 2 68R resistors
* 1 2.2K resistor
* 1 USB connector (could be saved if this is built on a PCB)

Schematic:
The entire MCU is powered at 3.3V obtained from a LDO regulator (I used a MCP1702 together with a 10 uF elko between its GND and OUT). ATtiny Pin 7 = D+, Pin 6 = D-. These must be connected to the MCU using 68R resistors. D- must additionally be "pulled high" though a 2.2K resistor (on the USB side, not on the MCU side of the 68R resistor).

First, flash the Micronucleus bootloader into the ATtiny and set the fuses (I used a USBasp):

wget https://raw.github.com/Bluebie/micronucleus-t85/master/firmware/releases/micronucleus-1.04.hex
./avrdude -C ./avrdude.conf -v -v -v -v -pattiny85 -cusbasp -Pusb -U flash:w:micronucleus-1.04.hex:i
./avrdude -C ./avrdude.conf -v -v -v -v -pattiny85 -cusbasp -Pusb -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m

Now we should see the device show up in lsusb/dmesg as idVendor=16d0, idProduct=0753

At this point, we can use the micronucleus command line tool to upload Firmware
sudo ./micronucleus micronucleus-t85-master/commandline/cdc232.hex

Believe it or not, this now shows up as a serial adaptor in dmesg:
[13563.472052] cdc_acm 1-2.3:1.0: >ttyACM0: USB ACM device

To get rid of having to use sudo, do

sudo su
cat > /etc/udev/rules.d/49-micronucleus.rules <SUBSYSTEMS=="usb", ATTRS{idVendor}=="16d0", ATTRS{idProduct}=="0753", MODE:="0666"
KERNEL=="ttyACM*", ATTRS{idVendor}=="16d0", ATTRS{idProduct}=="0753", MODE:="0666", ENV{ID_MM_DEVICE_IGNORE}="1"
EOF
service udev restart
exit

Then install the Digispark Arduino integration. Since I use Ubuntu I had to compile some parts by hand:

sudo apt-get -y install g++ libusb-dev
wget https://github.com/digistump/avr-dummy/archive/master.zip
unzip master.zip
cd avr-dummy-master/
make
strip avrdude
cd ..

rm master.zip
wget https://github.com/Bluebie/micronucleus-t85/archive/master.zip
unzip master.zip
cd micronucleus-t85-master/commandline
make
strip micronucleus

Within the Arduino directory do the following as per the instructions in the Wiki:

* Go to hardware/tools
* Rename avrdude to avrdude_original
* Copy the avrdude executable compiled above into the directory
* Copy the micronucleus executable compiled above into the directory

Now you should have your own breadboard Digispark :-)
Title: Building a Digispark compatible breadboard circuit
Post by: digistump on January 01, 2013, 05:29:03 pm
This is about right - but one major issue I see here, and maybe the source of the errors you\'ve seen trying to upload is that the micronucleus bootloader requires the Digispark to be powered with 5v not 3.3v so that it can properly run at 16.5Mhz - which is why we use 3.6v Zeners on the USB lines to tie it to ground.

In fact here is the schematic: https://s3.amazonaws.com/digispark/DigisparkSchematicFinal.pdf

We\'re still putting together the repository of all the board files and schematics, as well as the legal (ensuring they comply with any licenses they were derived from etc) and other work (cleaning them up, documentation, proper part numbers, etc) that surround them. But I\'m hopeful that the files will start to go up tonight, if not tomorrow.
Title: Building a Digispark compatible breadboard circuit
Post by: probono on January 01, 2013, 05:43:04 pm
Thanks for the schematic. I had issues with Zener-based v-usb circuits in the past so I thought it might be cleaner to power the whole thing with 3.3V. But I will experiment with your advice and see if it improves the reliability of the upload.
Title: Building a Digispark compatible breadboard circuit
Post by: digistump on January 01, 2013, 07:28:20 pm
The type of zener diode used is very important - I found that a 250mw or less one worked best. And of course it is still pushing things out of spec, but to have a stable 16.5Mhz to use the internal clock for USB I haven\'t found any alternatives to running at 4.5 ot 5.5v.
Title: Building a Digispark compatible breadboard circuit
Post by: Bluebie on January 03, 2013, 02:46:38 pm
I wouldn\'t run the attiny85 at < 4v if you care about bricking it. That puts the chip out of spec and the results are unpredictable - in my experience sometimes the bootloader will overwrite bits of itself and brick the device requiring a high voltage serial programmer (or regular ISP programmer if you didn\'t disable the reset pin) to recover.

The zenner thing is annoying, lots of people have issues with it, I hope there\'s one day a better solution but it is tricky to do voltage level conversion as both of the data lines are bidirectional.
Title: Building a Digispark compatible breadboard circuit
Post by: digistump on January 03, 2013, 04:32:05 pm
A voltage level conversion version of the Digispark is in the works, but I\'ve yet to decide if it will make sense to take that route as it adds quite a bit to costs and components and possibly size.
Title: Building a Digispark compatible breadboard circuit
Post by: Bluebie on January 04, 2013, 06:16:30 pm
How would you convert it, @digistump? Is there some sort of gadget for bidirectional voltage conversion like that, which operates fast enough to not mess up USB communications?
Title: Building a Digispark compatible breadboard circuit
Post by: digistump on January 05, 2013, 12:57:47 am
I\'m planning to try a few different methods - some of the fancy bidirectional converter chips (which require 3.3v as well as 5v) as well as some good old fashioned voltage dividers (which are still out of spec but might get it closer)
Title: Building a Digispark compatible breadboard circuit
Post by: Bluebie on January 05, 2013, 03:54:46 pm
Voltage divider! That\'s a cool idea, especially since you already have the 68ohm or whatever resistors there. Mmmmmm.
Title: Building a Digispark compatible breadboard circuit
Post by: probono on January 05, 2013, 04:48:11 pm
Tried it... using zeners gives less errors when uploading, but makes the device very picky (e.g., it doesn\'t work without a hub on my computer). Other zener-based devices (e.g., 3 different USBasps from 2 different manufacturers) behave the same way on my computer. So I think we could improve the reliability by using a MCU that can handle 3.3V properly, e.g., the ATmega168P or 328P? But that\'s probably the \"Pro\" version you\'re talking about then...
Title: Building a Digispark compatible breadboard circuit
Post by: Bluebie on January 05, 2013, 06:20:33 pm
Yeah, a chip with an external crystal oscillator would be able to run at low enough clock speeds to run on 3.3v while doing USB stuff, but the atmega\'s cost quite a bit more than attiny85. Digispark\'s schtick is cheap smallness. Arduino Nano already has the expensive smallness market covered.
Title: Building a Digispark compatible breadboard circuit
Post by: bobricius on January 06, 2013, 02:20:50 am
is usable? \"PCA9306 Level Translator\" https://www.sparkfun.com/products/10403?

The PCA9306 is a dual bidirectional I2C-bus and SMBus voltage-level translator with an
enable (EN) input, and is operational from 1.0 V to 3.6 V (Vref(1)) and 1.8 V to 5.5 V
Title: Building a Digispark compatible breadboard circuit
Post by: probono on January 06, 2013, 02:47:57 am
For the added cost of this chip I wouldn\'t be surprised if we could go straight to a MCU that handles 3.3V natively...
Title: Building a Digispark compatible breadboard circuit
Post by: digistump on January 06, 2013, 10:21:47 am
Once you get to chips like that you might as well grab something like a tinyduino (another kickstarter project run by Ken Burns, a great guy). To clarify the Attiny85 is 3.3v capable - you just need to use an external crystal which would use 2 of the i/o.
Title: Building a Digispark compatible breadboard circuit
Post by: RussNelson on January 16, 2013, 11:49:51 am
The teensy 2.0 is a nice micro if you want a larger board with more pins. And the teensy 3.0 if you want a LOT more pins, a LOT more storage, a LOT more ram, and a LOT more speed. I\'m fine with the digispark as it\'s currently conceived.
Title: Re: Building a Digispark compatible breadboard circuit
Post by: jaghvi on June 17, 2013, 11:41:27 pm
Can this board be used for serial data in,like in case a temp sensor is interfaced with it?? .As it doesn't have a inbuilt usb-serial converter .
Title: Re: Building a Digispark compatible breadboard circuit
Post by: Bluebie on June 19, 2013, 05:21:00 pm
Sure - you can communicate temperature to your computer using DigiUSB (which works a bit like serial) or enter it in as a keyboard with the DigiKeyboard library, or communicate the numbers via the DigiJoystick library. Joystick interfaces are an interesting option because they are designed for communicating numbers in a range which change over time. The numbers are communicated with digital precision, so a temperature input would work great with it. Plus, you could even use your temperature sensor to play games :P
Title: Re: Building a Digispark compatible breadboard circuit
Post by: Bluebie on June 21, 2013, 09:05:09 pm
We do not have permission to view this drawing
Title: Re: Building a Digispark compatible breadboard circuit
Post by: jaghvi on July 08, 2013, 02:41:23 am
i have all the aforementioned components to build a digispark on a breadboard.Now I want to know ,if i can burn the hex file using arduino as isp.I have arduino uno and no other ISP module?So is it feasible.
Title: Re: Building a Digispark compatible breadboard circuit
Post by: Bluebie on July 08, 2013, 06:29:53 pm
Yes, you can upload a bootloader to an attiny85-20 from within the digispark environment by selecting whichever kind of programmer you are using in the Programmer menu under tools, then connect the chip to the programmer and select Burn Bootloader. This will install the standard digispark bootloader, but will also disable access to the chip using an ISP programmer, enabling your programs to use the reset pin for whatever. After this, change the "Programmer" back to Digispark and connect the circuit to USB, and see if you can upload a simple program in the usual way.


Arduino ISP will be fine, or you can use a digispark by uploading the LittleWire firmware and connecting every pin from the littlewire digispark directly to the same pin on your hand made digispark, except for pins 3 and 4, which are used for USB between the littlewire and the computer. For LittleWire the programmer you should select is 'USBtinyISP'.


You say "I have all the aforementioned components" but you haven't shown us anything like that. You still haven't fixed your image so anyone but yourself can see it, so I have no idea what is in that picture.
Title: Re: Building a Digispark compatible breadboard circuit
Post by: jaghvi on July 16, 2013, 09:28:54 pm
I burned the bootloader on attiny85 finally :)
but serial port greyed out in the ide :(

Title: Re: Building a Digispark compatible breadboard circuit
Post by: jaghvi on July 16, 2013, 11:03:20 pm
@probono...why have u used d- and d+ as 6 and 7 pins resp.
When everywhere 2,3 are used for usb comm.
I have burned the bootloader and set fuses but yet its not detected
Title: Re: Building a Digispark compatible breadboard circuit
Post by: Bluebie on July 17, 2013, 07:27:46 pm
Digispark does not use a serial port. Set the programmer to Digispark and the Board to one of the Digispark variants and you should be able to upload to it if the bootloader really was installed correctly. Otherwise you have something wrong in your circuit.


Getting this USB stuff working is annoying - the circuit can be very dependant on the quality of the components you use. This is precisely why it is nice to just buy a little circuit board like the digispark and plug it in and not worry about all this stuff!
Title: Re: Building a Digispark compatible breadboard circuit
Post by: jaghvi on July 18, 2013, 03:12:49 am
It was because 90-digispark.rules was not there in my /etc/udev/rules.d....everything working great now.:) and followed steps of probono except used pins 2 and 3 as data lines and had to add 49-micronucleus.rules and 90-digispark.rules in /etc/udev/rules.
 
Title: Re: Building a Digispark compatible breadboard circuit
Post by: jaghvi on July 18, 2013, 04:12:34 am
@bluebie
trying to burn the cdc.hex file from avrdude ,detects the onboard digispark as ttyACM device but the sketch wont upload on the board.
But if its uploaded from micronuceleus command line it works fine ??
Title: Re: Building a Digispark compatible breadboard circuit
Post by: Bluebie on July 19, 2013, 08:33:07 am
the 'ttyACM' device will be your programmer, not the attiny85 chip itself. Your programmer is unable to program this chip now, because you have used the burn bootloader function to install the bootloader and change it's fuses disabling the 'reset pin' function. This allows you to use all six pins, but you cannot use an ISP programmer anymore to upload to this chip. You will need a high voltage serial programmer to upload directly to it now, or you can use a high voltage serial programmer or a 'tiny fuse resetter' (which is a simplified hvsp device) to reset the fuses to erase the chip, setting the fuses back to the default value where the reset pin is used to make the chip accept a new program upload instead of being used for general IO inside the programs you upload. I should have made it more clear that your tiny85 would loose this hardware reset function if you Burn Bootloader.


The upside is it isn't too tricky to make a tiny fuse resetter - you just need a 12v power source (like a little 12v battery) and a transistor, and you should be able to do the rest with a digispark or an unburnt attiny85 or something like that. The web has instructions on how to make these gadgets on a breadboard.
Title: Re: Building a Digispark compatible breadboard circuit
Post by: dougal on July 19, 2013, 12:31:17 pm
Speaking of HVSP, is there any good source to get one for less than $50?


I might break down and get one eventually in any case. But if I could find one closer to $30, I might do it sooner than later.

Title: Re: Building a Digispark compatible breadboard circuit
Post by: Bluebie on July 23, 2013, 07:16:26 pm
I have no idea. I don't own one. I've only lost five or so chips to this sort of bricking, which is a heck of a lot cheaper than $50... This is one of the problems I made micronucleus to address - so we can use all six pins in a nice simple way, without needing an expensive programmer or dangerously high voltages (to the rest of the components in a circuit)
Title: Re: Building a Digispark compatible breadboard circuit
Post by: dougal on July 24, 2013, 07:40:32 am
Yeah, you're right. I don't know why I'm considering the purchase of a HVSP just to recover one bricked
Digispark (well, and any possible future ones). I could buy 4 or 5 new ones, instead. Or a USBISP and some bare AVR chips.


I think instead, I'll use my bricked Digispark for soldering/desoldering practice. I can extract the power regulator, LEDs and such for other stuff.

Title: Re: Building a Digispark compatible breadboard circuit
Post by: Bluebie on July 30, 2013, 08:16:52 am
How'd you brick a digispark? Were you using flash memory to store data and accidentally wrote over the bootloader or something?


hoping there aren't secretly any horrible bugs in my code which ruined your thingie.
Title: Re: Building a Digispark compatible breadboard circuit
Post by: dougal on July 30, 2013, 10:49:45 am
I tried using the 'Burn bootloader' feature in the 1.04 Digispark Arduino software, with an LCD shield connected. At least, I assume that's what did it.


I might try to make/acquire a fuse resetter. Or, like I said, I might just desolder it, for fun.

Title: Re: Building a Digispark compatible breadboard circuit
Post by: Bluebie on August 01, 2013, 04:11:35 pm
That really shouldn't matter, but now I think I will add a verification thing to the burn bootloader feature, so it verifies that both it has uploaded the bootloader installer correctly, and has installed it correctly before patching the reset vector over. Should make things safer