Projects

ATDEV For ATtiny

Programming & Development Shield

Rob Bell & Mike Hansell

Issue 14, August 2018

This article includes additional downloadable resources.
Please log in to access.

Log in

A powerful and versatile programming and breakout shield for ATtiny.

BUILD TIME: 1 HOUR
DIFFICULTY RATING: Intermediate

We love working with ATtiny microcontrollers, in particular the ATtiny85. They have been featured in a few of our recent projects, and likely to be in many more in the near future. They can be a real pain to prototype with though, due to the lack of programming breakout we get used to with a regular Arduino board for instance.

THE BROAD OVERVIEW

There are plenty of great ATtiny programmers out there to help you programme, but there’s one side of development for ATtiny that can be a pain - debugging. Pulling your ATtiny in and out of your programmer and your prototype is tedious, and usually ends up with something damaged after a few runs back and forth.

What if you could leave your ATtiny in place during development? What’s more... what if you could see the logic levels on the GPIO pins? That would be awesome, right?!

That’s where ATDEV comes in. Combine the shield with your favourite UNO and you’ve instantly got a programmer and debugging system in one!

HOW IT WORKS

We’re using the Arduino for two things here. Firstly, we’re using it as an ISP (In System Programming) interface for our ATtiny circuit. You don’t need complex hardware to programme using ISP, and we cover that in the first build. However, when you’re developing code for an ATtiny, it can get a little tedious without the feedback mechanisms we’re all used to having.

Additionally, we’re using it as a logic analyser to provide read functionality on the GPIO (General-purpose Input/Output) of our ATtiny and provide visual feedback to the LEDs via the 74HC595 ICs. The 74HC595 is a shift register which we use to drive multiple LEDs without using up every available GPIO pin.

There were a few ways we could tackle this, and each has their own pros and cons. Initially we wanted a self-contained programmer, but we rapidly turned our attention to using an UNO. After all, what better to use for detecting logic than something using the very same logic in the first place?!

This quickly cut down on the discrete hardware required to get this project running properly, and made it entirely customisable at a code level should you wish to expand things too!

CONFIGURING YOUR ARDUINO IDE

ATtiny uses many standard processes, which makes life easy, so programming an ATtiny via the Arduino IDE is fairly straightforward. However, it’s worth noting that not all functionality of the ATtiny is available natively. For this reason, it’s sometimes necessary to include additional libraries to emulate certain functionality on the ATtiny that may come natively to an UNO for instance.

Fortunately, you don’t have to go it alone. ATtiny hardware is well supported, thanks to loads of work by the Arduino community. This includes libraries for SPI communication, display drivers, and much more. If you’re looking for functionality, simply search “ATTINY” in the Library Manager of your Arduino IDE to see what’s available

ATTINY BOARD SUPPORT

If you haven't played with ATtiny chips before, you'll need to do a little configuration before you can work with ATtiny boards via the Arduino IDE. It's not difficult, but there are a few things you need to do to in order to burn the bootloaders on the ATtiny chips and such.

There is a fantastic guide on how to do this here: http://highlowtech.org/?p=1695

This will enable all the appropriate options so you can get the most of your ATtiny hardware, and the programming shield.

The board support only needs to be done once and you'll have support for the full range of ATtiny chips. Awesome!

Special Pin 1 - Reset

It should be noted that the ATtiny85 has 5 easily manipulated GPIO pins, plus pin 1 which is normally used to reset it. While pin 1 can be set to be an output, how do you reset the ATtiny if you do so? The answer is you’d need to use another programmer, a so-called ‘high voltage programmer’ to rectify this.

As we have left pin 1 as its native reset function, our test sketch does not try to drive it high and low like standard GPIO pins. The bottom line is that in general operation the red LED associated with pin 1 will be illuminated all of the time.

If 5 GPIO pins is just short of your project design goals, instead of using pin 1, you can use 74HC595 shift registers instead.

At the cost of 3 GPIO pins on the ATtiny, you get 8 output pins. Want 16 or more outputs? Simply cascade multiple 74HC595’s as we have with this project and others in the past, it's a great way to expand things out!

prototype

Build 1:

The Prototype

Before we get into the custom programmer, it’s worth covering simple ATtiny programming using an Arduino UNO, breadboard, and a few jumper wires. This isn’t a bad way to get things done in a pinch, or indeed if you’re done with development and simply need to load your code and go.

Unlike some of our prototypes where we try and replicate all of the functionality found in the main build, this one doesn’t. It's really just not feasible to do so. It will allow you to programme an ATtiny from an UNO, but that’s basically it. We could have created a breadboardable version of the full project but it seemed a little much - and the breadboard quickly starts looking like a snake pit.

That said, knowing how to programme using ISP is a valuable skill.

Parts Required:JaycarAltronicsCore Electronics
1 × Arduino UNO or EquivalentXC4410Z6280CE05629
1 × ATtiny85ZZ8721Z5105COM-09378
1 × LED (any size or colour will generally do)ZD0150Z0800COM-09590
1 × 220Ω ResistorRR0556*RR7038*-

Parts Required:

* Quantity shown, may be sold in packs. You’ll also need a breadboard and prototyping hardware.

Follow the wiring shown in the diagrams. It’s fairly straightforward, and power is provided from the Arduino, so no other connections are required (other than USB from your computer to your UNO).

While the ATtiny can use an external crystal, we’re using the internal 8MHz clock. Unless you require ultra fast or precise timing, the internal clock is usually adequate.

Take care with orientation of the ATtiny also or you may apply reverse polarity power and damage the chip.

Note - we have provided an LED in the circuit purely for the purposes of the test circuit. It is not required at all for programming, however the basic output provides a quality way to confirm that the code has loaded and is running as expected.

THE CODE

You can programme whatever you want (within hardware limits) onto your ATtiny using this method. You simply need to tell your connected hardware what to do.

Fortunately for us, ATmega328p programming via ISP is supported, and the method is the same. So you simply need to configure your “programmer” setting. Your board should be whatever Arduino board you’re using (in our case, it’s a regular UNO, so we have the Arduino / Genuino UNO option selected). Then go to Tools › Programmer, and select “Arduino as ISP”. It’s this tiny change that ensures your ATtiny is the chip programmed, and not the Arduino UNO itself.

There is no specific code required on the UNO itself, it’s merely a connectivity buffer for the code you’re loading to the ATtiny. As long as the IDE has the correct “programmer” settings, Arduino IDE should use the UNO purely for ISP.

However we have added a single-LED that flashes, in a similar way the Arduino “blink” tutorial works. This is the best way to determine that your programmer is indeed working.

If you have ATtiny code you’re itching to get going with, you’ll find attiny_isp_blink.ino in the digital resources. Load it into your Arduino IDE and load it onto your ATtiny. As long as you have selected “Programmer” appropriately as shown above, there should be no problems.

OPERATION

While this isn’t exactly a project you’ll keep assembled all the time, this is really a useful skill to have, being able to build a simple ISP programmer in a flash. You may be debugging, recoding, or perhaps even have a faulty programmer you’re trying to work around!

programming shield

Build 2:

Full Programming Shield

Now it’s time to get stuck into our full build, which is going to create a programming shield, with full logic feedback functionality.

The logic feedback is indeterminate, working the same for a logic high or low coming from the ATtiny itself, or the broader circuit. This means that if you have a HIGH signal from a sensor, it will show HIGH on the logic analyser where you have it connected to the ATtiny, regardless of what the ATtiny itself is doing. This is useful for debugging purposes to see what is being set high or low (or not at all). Of course, without a circuit connected, if your sketch sends a pin high or low, it will display the corresponding LED for you too.

Of course pure binary is a wonderful thing, but these pins are tri-state. That means they can be high, low, or floating because they’re unassigned. This can lead to some erratic results.

It’s for this reason, our sketch for the UNO which does the pin sensing work, uses the analogue pins on the UNO, not the digital pins. Sadly, we tried to keep it simple, but depending on the power supply, the load connected, and a variety of other factors, we got a few strange things going on. High or low was an easy thing to cater for, but unassigned pins were something of a challenge.

By using the analogue inputs, we can simply read from a pin and then determine if that equates to a high or low level.

Parts Required:JaycarAltronicsCore Electronics
6 × 3mm Green LEDsZD0120Z0701POLOLU-1071
6 × 3mm Red LEDsZD0100Z0700POLOLU-1070
12 × 330Ω 1/4W ResistorsRR0560*R7546*PRT-14490*
4 × 100Ω 1/4W ResistorsRR0548*R7034*PRT-14493*
6 × 1MΩ 1/4W ResistorsRR0644*R7630*PRT-14494*
2 × 74HC595 ICsZC4895Z8924COM-13699
2 × 100nF Ceramic CapacitorRC5360*R2865*CEO5188
2 × 10µF/16 Volt Electrolytic CapacitorRE6066R5065CEO5274
2 × 16 pin IC SocketsPR6456P0534PRT-07938
1 × 8 pin IC SocketPR5452P0530PRT-07937
1 × Arduino Stackable Header SetHM3208-CEO4496
1 × Female Header StripHM3230P5390POLOLU-1014
1 × Custom PCB (Files available as a digital download)--

Parts Required:

* Quantity shown, may be sold in packs. You’ll also need a breadboard and prototyping hardware.

NOTE: Altronics don’t carry a set of stackable headers but have individual parts available as follows: 1 × 6pin P5380, 2 × 8pin P4381, 1 × 10pin P5382, 1 × 2x20pin P5387 (will be trimmed)

PWM DETECTION

While not really an intentional feature, but more of a byproduct of the way it works, the shield will also display PWM (Pulse-width modulation) signals to a degree. The “detection loop” on the UNO is quick enough that you will see a flutter between the high and low indication LEDs when a PWM signal is presented. It would be possible to do some tuning on the software to implement deliberate support for PWM reading. However we see the logic LEDs as a notable debugging / fine tuning tool, so didn’t feel there was substantial benefit in doing so.

THE PCB

The PCB

As with all our PCB-based projects, it is not essential to use the PCB; however it makes construction easier. We prototyped this PCB using our Bantam Tools Desktop PCB Milling Machine. Due to the complex nature of the PCB, with small tracks and such, we decided to run a professional prototype to help iron out any bugs too. The professional PCB has solder masks and silkscreens. If you order a PCB through a manufacturer you’ll likely have these features too.

The PCB itself is a double-sided design. It is built to a standard UNO footprint, to work as a direct plugin shield using stackable headers.

Check your PCB for broken tracks, corrosion, or other manufacturing defects. Give it a good clean with some isopropyl alcohol or circuit board cleaner, to help remove any grease or residue that may exist. This will help reduce the incidence of dry joints and other problems.

Use the lowest temperature possible for the solder you’re using, to help avoid overheating the PCB and components, which can be easily damaged with excessive heat.

Top Overlay
Top Overlay.
Top Layer
Top Layer.
Bottom Layer
Bottom Layer.

As with all PCB builds, we follow a hardware, passives, semiconductors type construction pattern. This means you should install IC sockets (if you’re using them, though one for the ATtiny itself is mandatory), stackable headers for connection to the Arduino (including the ICSP header), and pin headers for the breakouts. Then move on to the resistors and capacitors (take care to orient the two electrolytic capacitors correctly).

Next insert the LEDs taking care of their orientation. It’s important to know that we have elected to keep high / low pairs alongside their respective pin. You can easily put all the high LEDs on one side and low LEDs on the other side, if you prefer - you’ll just need to update the sketch we run on the UNO.

With all hardware installed (except for the ICs), take a careful look over the PCB, looking for poor solder joints, bridged tracks, or anything else out of place. Rework anything you’re not entirely confident about. Once you’re satisfied, you can move onto testing.

IMPORTANT: Depending on the height of the stackable headers being used, you may need a little electrical tape on the top of the USB socket on the UNO, to protect against electrical shorts when pressed in hard to the UNO. A few pins on the 74HC595 may short, producing erratic results. Many stackable header pins are quite long, but a small piece of electrical tape (or any other type of insulating material) is easy insurance.

TESTING

With no ICs inserted into the shield, carefully push it into the UNO, taking care to align everything as you would with any shield. Push it firmly to ensure all the pins are well seated. Connect your UNO to its power source.

We’re going to make a few electrical tests to ensure we have power where we expect it. This helps reduce the likelihood of shorted tracks, and we know we’re getting power to the shield.

Grab your multimeter and check for power on the IC sockets as shown in the following three images. Pay special attention to the voltage (should be very close to 5V), and polarity (you shouldn’t see a negative mark next to the voltage reading, provided your probes are used the same way as shown).

voltage reading with probes

If all three sockets show power as expected, remove power from the Arduino and commence installation of the ICs. While the ATtiny85 and 74HC595 ICs aren’t the most fragile chips around, they’re still potentially damaged easily, so take care to ground yourself before handling them. Be careful to orient them correctly (refer to the overlay on the PCB and the images).

Re-apply power to your Arduino, and check the onboard “on” LED is illuminated. If not, it often indicates a short circuit somewhere. Switch it off and go back over everything. Otherwise, continue on to the code.

OPTIONAL BREAKOUTS

It’s important to note that not all pins are used by the shield, and are left isolated / pass-through. If you use stackable headers you can easily expand on the shield in whatever way you see fit. If you don’t want (and don’t anticipate) this feature, you can use standard headers. Just ensure your headers are tall enough - or you may short out one of the 74HC595 ICs on the USB port of the UNO.

THE CODE

Obviously the code for the ATtiny85 is your own, however we’ve created a sketch which toggles the GPIO in order to test functionality of the UNO and feedback portion of the shield, which we’ll do shortly.

There are a few steps you need to follow in order to set the pass-through (Arduino as ISP) functionality up, and also to add our software to the UNO to perform our logic reads and such.

If you have followed the first build already, you’ll be familiar with the “Arduino as ISP” programming mode. But before we do that, you will need to load the UNO with the analyser code.

CODE THE UNO

Grab the “atdev_uno_reader.ino” from the digital resources. With your Arduino IDE programmer mode set to AVR ISP (the default), check your board is set to UNO, then hit the upload button to load it onto your UNO.

As soon as it’s loaded and your Arduino starts up, you’ll notice an initialisation sequence on the LEDs. You’ll see the high / low LEDs for each of the 6 pins we’re monitoring. This is the self test in the UNO code so you can visually check for any issues with the onboard LEDs.

If something doesn’t llluminate during this self test, it’s easier to find the problem now than later. The self test can be performed without the ATtiny inserted into its socket also - the UNO takes no readings from the ATtiny during this stage.

CODE THE ATTINY

Now it’s time to get some code on your ATtiny85! Download the atdev_attiny_example.ino from the digital resources, and load it into your Arduino IDE.

Set your Arduino IDE programming mode to “Arduino as ISP” (Tools › Programmer › Arduino as ISP).

Click Upload on the sketch. After a brief moment, you should start seeing the logic LEDs shifting around. This is the sample sketch running on the ATtiny and the UNO reading the values as it’s designed to do.

While the ATtiny doesn’t have serial, you can use serial monitor for an insight into what you’re seeing and how the UNO is detecting the pin states.

DEBUGGING

If you have any difficulty getting reliable readings from the shield, there are a few potential issues and solutions below:

SELF TEST - ONE BANK FAILS TO ILLUMINATE: if you see no illumination from a group of 6 × LEDs on either side of the ATtiny, it’s likely that there’s an issue with the 74HC595 driving them. Check the solder connections for open circuit or shorts. If you skipped the power check before inserting the ICs, complete that test now.

SELF TEST - ONE LED: if you find that the self-test doesn’t illuminate all LEDs, you either have a problem with the LED itself, or the connection between the 74HC595 and the LED. If all other LEDs on that side of the board are working, you can virtually rule out an issue with the 74HC595.

LOGIC ANALYSIS INCORRECT: While we have spent a reasonable amount of time assessing and selecting threshold values in our circuits and environment, there are adjustable threshold levels in the Arduino UNO analyser code for what determines a high or low pin range. Remember, we’re doing this with analogue reads to increase the flexibility and reduce false / missed reads. These can be configured in the sketch if you wish to adjust them for your own purposes.

WHERE TO FROM HERE?

This is a fairly comprehensive project, and will give you a powerful ISP programmer with a versatile debugging / development breakout. You can safely jumper the pins from the headers right into your development project, and update code with the same convenience you would when using an Arduino UNO!

Perhaps you’d like to make a larger version for coding ATmega328p chips in the same way, or you could adapt the analyser code in the UNO into a web-based interactive display.

Whatever you choose to do, this project should get you deploying ATtiny chips in no time!