Wednesday, January 22, 2014

Shrinket, Arduino compatible ATtiny85 development board

Hackaday feature

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


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.


1x Perfboard - 0.6"x0.8"
1x Mini USB B SMD connector
1x Momentary switch - 4x4x1.5 mm SMD
2x 1x5 male pin header

1x ATtiny85 uC
2x Zener diode - 3.6V / 500mW SMD (doesn't have to be surface mount)
1x Diode 1N4002 SMD
1x 78L05 SMD regulator

Everything below SMD size 0805:
2x 10uF capacitor
2x 68 ohm resistor
1x 1.8 kohm resistor
2x 1 kohm resistor
2x leds

Also some jumper wire or through hole component leads.


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.


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.

Tuesday, January 21, 2014

Electronic boost controller

This is a brief overview of a project I named EBC2013.

About a year ago I started working on one of my longer and more serious projects. Me and my dad share a project car which we like to take to the track. The car has a turbo charger installed and we wanted an electronic boost controller for it.  However there was a problem; they go for about ~250$ and up.. But how hard could it be to just build one?

First I set some goals for this project:
    - Electronics are controlled by Arduino microcontroller platform
    - Finished looks
    - Intuitive and simple user interface
    - Open and closed loop modes for boost control
    - Over boost protection / boost cut
    - < 100$ budget

I started by doing some research since I had no experience on electronic boost controllers (EBC). I read through couple user manuals to get an idea of what features they might have. This also gave me a rough idea on how I wanted the GUI to operate. I also gained an understanding for how the device as a while should work. Basically it has a pressure sensor that monitors the MAP (manifold air pressure) in the engine and drives a solenoid with a varying PWM signal. The solenoid opens and closes the air to a pneumatic actuator on the waste gate of the turbo charger thus controlling the boost. For a better explanation please turn to google, as it could be a blog post on itself.


Inspired by an off the shelf controller I decided to use only three 7-segment displays and two push buttons for the interface. This would provide some challenge in communication, but benefit from compact size. The user would shift up and down menus with the two buttons and proceed by pressing both buttons simultaneously. The menus can be thought as trees that have branches, but at the end the interface always returns to main screen.

Here's a video showing an early experiment with the menus and closed loop control. The potentiometer simulates the MAP sensor.

The code

Before I received any of the parts for this build I had time to work on the code. It quickly expanded to over 1000 lines, which is by far the longest single program I had ever written. When I finally had the chance to burn the program to the finished hardware it had only minor tweaking left.

The commented code is available here: EBC2013. I am more than happy to help if some part is hard to understand. Also NOTE that the PID closed loop control portion is highly experimental!


The EBC consists of two parts; the main unit located near the driver and the solenoid located near the engine. The main unit can be separated to eight blocks.
     - The Arduino Nano; controls and is connected to everything
     - Voltage regulator, everything works with 5V except the solenoid
     - MAP sensor, MPX4250AP
     - The display and push buttons
     - Chips driving the display, 3x TPIC6B595
     - Buzzer speaker
     - FET driving the solenoid, IRLZ44N
     - Connector for power, solenoid and possible auxiliary accessories

All of these are distinguishable in the final circuit board:

Those heatsinks are probably unnecessary, but I didn't want to take any chances as the case is not ventilated.

I would like to point out that I had no previous experience in using 7-segment displays or shift registers, but didn't want to use existing libraries. Each display is driven by its own high power TPIC6B595 shift register and all the digits in the code are created by me painstakingly slow one by one. In the end this was very rewarding as I had the chance to design my own letters and figure out which symbols are possible and which are not. I wrote brief instructions on how to add more symbols to the code.

With the layout I wen't after simplicity as well as robust design. The hardware has to work reliably and withstand shocks and vibration.

The Case

The circuit board was created to fit an aluminum case that has mounting grooves for it. When I received the case I was happy to find the dimension given by the seller correct and the board fit perfectly.

In this photo the hole for the 8-pin connector was not yet cut.

Further development

After finishing this build I started to play around with an idea of manufactured PCB. I also changed the Arduino nano to embedded ATMega328 chip and replaced the three shift registers with a single smd MAX7219 chip that can handle up to eight seven segment displays and already has a good Arduino library written for it. The Eagle files for the layout and schematics can be found in the github repository here. I apologize that I don't have an updated code for this board, but I never got around ordering any. The schematic will however help to build your own controller.

Testing and conclusion

Installing the EBC was straight forward. I mounted the device under the dash with velcro and ran wires to switched power and to the solenoid. The pressure line I spliced from the ECU with an Y-connector.

First test I did was with open loop mode, in which the controller feeds the solenoid with a constant predetermined PWM signal that can be changed in the menu on the go. This was simple and worked like expected, but the closed loop was tricky and showed severe hysteresis. Later I tried PID control. It was easy to implement but very hard to tune. (This was not helped by a jamming wastegate that went unnoticed for quite a while.)

I put the closed loop development to a halt, as it was taking way too much time, but showing very little results. After all the open loop mode works reliably and is fast and easy to alter while driving. I also hit every other goal on my initial list.

I have added all sorts of little tweaks on the way like display brightness, maximum detected boost, atmospheric pressure compensation and "added boost" mode in which the driver can momentarily raise the boost limit with a press of an auxiliary button.

I am very happy with the EBC at the moment, and don't regret going DIY. After all this is a product designed by me for me and open for me to change anything if ever needed.

For those who are interested here is a picture of the engine bay. The solenoid can be seen right above the air filter, installed away from the heat.