Pages

Wednesday, January 22, 2014

Shrinket, Arduino compatible ATtiny85 development board

If you are into electronics you have probably already heard of Trinket, Digispark or other similar product. They are all devices that provide Arduino compatible development platform in a small size and price. What they actually are is ATtiny85 microcontroller with USB compatible bootloader and some hardware connectors. When I first learned about these I was thrilled. Programming those chips can be very annoying when you have to detach them from the project every time.

I had been thinking of taking on an ATtiny based project but didn't come up with any ideas. After looking closer into these boards I figured building my own development platform would be a great project itself. I thought I could even beat the footprint size of Trinket and named the project Shrinket. I ended up building four.

Three Shrinkets, fourth is in a project.

Adafruit Trinket

Research

I first examined the Trinkets schematics which are available here, and figured I already had everything I needed. Only exception was the voltage regulator, which I replaced with a 78L05 regulator. This means the board can't decide which power source to use, and I have to unplug auxiliary power when connecting to USB.

Note that in the drawing the wires under the chip shouldn't be crossing, as the D+ and D- are inverted!

Here is what I got out of those schematics. On the bottom you can see my first doodles of the component layout. I noticed the pinout on Trinket is the same as inverted ATtiny's, so I decided to use DIP-8 chip soldered to the bottom.

Unfortunately I took no photos during the build, but I will add some if I ever build another Shrinket.

Here is a more detailed drawing of the layout:

I figured using a micro USB connector was the way to go and started by soldering one to a 15x20 mm protoboard. First I had to remove the copper rings from where the connectors pins where going to go since their spacing was completely off. I also removed the fifth NC pin from the connector to give more soldering space and pre-applied solder to remaining four pins.

The wires connected to USB connector should be soldered next as you will need all the space possible. I found the easiest way to do this was to run each wire through the nearest hole and bend it to touch the connectors pin. I then applied heat to the wire which then joined with the pin as the pre-applied solder melted. I saved ground wire last as it doesn't run to the other side.

As can be seen in the layout drawing there are two wires running under the chip. These had to be soldered before the ATtiny85. The mentioned wires are then connected to USB D+ and D- with 68R resistors. You have to be careful not to detach the wires from the USB connector when doing this.

Next I added the zener diodes to the D+ and D- wires on the bottom side and 1K5 resistor between D+ and +5 on the top.

ATtiny85 chip and button were next. I bent the chips legs outward to help connect the pin headers to them easier. Also note the 10uF capacitor between the switches ground and ATtiny's power pin.

Finally I added the LEDs and their 1K resistors, added the 78L05 regulator and 1N4002 diode to form the power supply. When I added the headers I also soldered a 10uF capacitor between the power running to the regulator and the ground pin. They are conveniently next to each other so the cap is easy to add together with the header.

Before doing anything else I ran a visual check and tried to power the board from safe USB power source. The power light came on and the chip didn't fry so I was confident to proceed to programming.

Putting the first Shrinket together took about 90 minutes. Three others I built took some 60 minutes each.

Bootloader

I decided to use the Trinket bootloader since it has good support and at the time I didn't have knowledge of any alternatives.

The bootloader is programmed with an Arduino. The complete instructions are here. First the Arduino is loaded with a special sketch and then connected to the board. I went ahead and built a simple shield to do this. This proved to be very convenient as it turns out it is very easy to brick the bootloader.

The programming took only few seconds as everything is included in the Arduino sketch. This means that the programming works even with the Arduino powered by a battery.

Uploading sketches

Sketches are uploaded with the Arduino IDE which has to be prepared for the Trinket bootloader. Adafruit has done a great job with this as well and you can even download an already modified version of the latest Arduino IDE here. In the program you also have to select the correct board from "Tools > Board" and change the programmer in "Tools > Programmer" to USBTinyISP.

With the bootloader and Arduino IDE ready it was time to upload first sketch. When the board is connected to a computer it flashes the secondary (not power) LED for about ten seconds during which the upload has to be started. If you miss this window you have to briefly press the reset button or reconnect the board. I found the latter more reliable. It has been pointed out that Trinket works better with USB 2.0 than 3.0, but I didn't experience any of the mentioned symptoms with my computer.

A simple blink sketch worked right away. However at this point I figured that whenever the board is powered by a computer it always delays start with that ten seconds waiting for a connection. This can be very frustrating in some applications.

Further testing

One of the benefits of virtual USB connection between the board and computer is the ability to emulate USB devices. This can be done with Adafruits library for this, but I found this to work better. From what I understand they both rely on V-USB project.

I tried some keyboard emulation with timed key presses and it worked well. This could be used in simple multimedia or game controllers.

What else..

This was a great project. I built a total of four Shrinkets, first two one at the time and two more at the same time. If you plan on taking this project I suggest building more than one like I did. You really understand the process better after each one and on something this small there's basically no room for mistakes. After a few it is possible to build several at the same time and probably reduce the build time significally.

You might wonder why I didn't just buy a few Trinkets or Digisparks since they are so cheap. I even found Trinket clones on ebay for under 5$! If you are like me, the build is usually more important than the final product. In this case it just happens to be a really cool Arduino compatible development board.

Ok, i Almost got it. But where does the wire from the left LED go? It disappears under the chip.... It should go to ground i think.. right? And you wrote that you put an "capacitor between the power running to the regulator and the ground pin" but on the picture the capacitor is between the ground pin and the B+ pin, but i doesn't see any connection between the B+ pin and anything else. An answer would be very nice :) .

It goes to GPIO pin 1 (pin 6 on ATtiny), just like in Trinket. I'll add some colorful pictures later (: I also noticed the reset pin is disconnected from the button in the photographed Shrinket (d'oh!). The led's connect to ground in the usb-connector end.

Might I suggest my slightly modified bootloader, to get rid of the 10sec delay.https://github.com/beargun/Adafruit-Trinket-Gemma-BootloaderIt will only go into programming mode if the reset button is pressed, not during power-up.

PS. you project looks awesome. Never thought of using perfboard for this kind of stuff.