Atmel AVR TinyISP

TinyISP has a useful function extension for the ArduinoISP sketch, see here, in order to allow an Arduino Serial Monitor display serial data from the connected ATtiny, for debug purpose only (send only).

It was a bit difficult to setup, therefore I like to document it here.



The sketch zip archive ( can be downloaded from here. When you have unpacked the zip archive, copy the content to the sketch book folder under the folder name TinyISP. The path of the Sketch Folder can be found in the Arduino IDE under Preferences. Then start the Arduino Application and select under open the file TinyISP.pde, compile it and upload it to your Arduino board.

The Arduino version was 1.0.2.

Now make a 4 wire connection from the Arduino board to the ATtinyx5 processor for ISP (In System Programming). Because I own just ATtinyx5 processors (8 pins), I can only tell about this type, see picture on the right.

ATtinyx5 pin signal    Arduino pin (NANO3)
5 PB0        MOSI      D11
6 PB1        MISO      D12
7 PB2        SCK       D13
1 PB5 Reset- SS        D10
2 PB3, A3
3 PB4
4            GND
8            VCC (same as Arduino board)

When the Arduino board does have the sketch TinyISP programmed, it should program the slave processor (ATtiny) instead of the Arduino board, but it must be avoided to auto-reset the master (Arduino board) with the Upload program. This can be achieved by placing a 120 Ohm resistor from VCC to Reset-. Another option is to put a large capacitor from the Reset- input to GND. After that change the upload program will program the slave processor, via the program TinyISP in the Arduino board.

But the useful Serial Monitor function of the Arduino IDE is lost for the slave processor. Now the special feature of the program TinyISP will come into the game. It routes the serial transmit data (MISO) from the slave processor through the Arduino board to the Serial Monitor of the Arduino IDE.

In order to do so, the source code of TinyISP must be changed:

File: TinyISP_BuildOptions.h

# Enable relay function
#define RELAY_SERIAL_ENABLED              1

# should be so
#define RELAY_BAUD_RATE                   9600

Then compile and upload the program to the Arduino board. The 120 Ohm resistor must be removed before be able of programming the Arduino board.

The commands in using the Serial Monitor are:

# ATTENTION: select baudrate to 19200 in Serial Monitor

# With the character "!" + ENTER you toggle the "Serial Relay" function

# Commands for manipulation the slave processor ATtiny (+ ENTER)
 @  Toggle between holding the target in reset after programming and 
    allowing the target to run immediately
 #  Reset the target now or allow the target to run if it is held in reset
 $  Hold the target in reset
 ?  Print help text
 \\ debug ???



In order to be able to use the ATtiny processors you have to setup a new core (tiny).

You have to download archive (2012-07-31) from here, or a newer version. When you unpack the zip archive you get two folders, tiny and tools. They have to be copied or moved to the Arduino Sketch Folder under the folder hardware. The path of the Sketch Folder can be found in the Arduino IDE under Preferences.

The software TinyDebugSerial has the benefit to be small in footprint (1.1 KB), so it will fit even in an ATtiny25. The standard software SoftwareSerial needs about 2.4 KB of the flash ROM.

Because I needed in my application program for the ATtinyx5 the delay() function, only a clock frequency of 1 MHz does the job right. At 8 MHz clock speed the delay is much longer, I do not know why.

Unfortunately the header file TinyDebugSerial.h defines at about line 608 onwards the output pin for the ATtiny different, than the standard ISP setup, pin 3 instead of 1. Therefore the Serial Monitor did not work at first. Changing the pin:

    // at Arduino D12 is Serial Input connected to TinyISP PB1 MISO (pin 6)
    #define TINY_DEBUG_SERIAL_BIT         1

makes it work. The Serial Monitor baudrate must be set to 19200 baud.

The application program must have the following statements for debug output, for example:

# declaration
#include <TinyDebugSerial.h>
TinyDebugSerial mySerial = TinyDebugSerial(); // PB1 = TX pin 6

# in function setup()
  mySerial.begin( 9600 );    // for tiny_debug_serial 

# in function loop()
  mySerial.println( "Testing...");  // debug output

Another possibility to display the serial output is to connect an USB-Serial converter, like described in Software_Arduino.

# connect ATtiny85 pin 6 to USB-Serial pin TXT
# connect ATtiny85 pin 4 to USB-Serial pin GND

# On Linux look at /dev/ttyUSB0 if it is the only plugged in USB-Serial converter

KnockBang serial protocol

In order to use the benefit of the TinyDebugSerial protocol, but minimize the code length Coding Badly has written an efficient KnockBang serial protocol, which takes also into account the not so accurate RC-oscillator of the ATtiny processor.

It can be used for transmit only. The hex code length is 250 bytes only.

The different code length for the ATtinyx5 is:

First you have to modify the TinyISP program, file TinyISP_BuildOptions.h:

// enable KnockBang protocol

Compile the program, remove the 120 Ohm resistor, and upload it to the Arduino unit. Then plug again the 120 Ohm resistor, in order to use the TinyISP function.

Next download the ZIP file with the TinyDebugKnockBang program, unzip it, and insert into the Arduino library:

{Arduino Sketch Root}\libraries\TinyDebugKnockBang\

In order to check if it is OK, look at the Arduino menu: Sketch/Import Library

Last, the source code of Sketch Blink_Debug in order to test the Debug protocol:

  Blink_Debug for ATtinyx5 
  Turns on an LED on for one second, then off for one second, repeatedly.
  Use either "TinyDebugSerial" or "KnockBang" serial protocol for Debug
  2012-12-08 RudolfReuter
  This example code is in the public domain.
 // use KnockBang protocol from "Coding Badly", or comment out for TinyDebugSerial
#define KNOCK_BANG 1
#include <TinyDebugKnockBang.h>
// pin for LED
int led = 4;  // ATtiny25

// clock must be 1 MHz

// change in TinyDebugSerial.h line 613 from 3 -> 1 for TinyISP
//  #define TINY_DEBUG_SERIAL_BIT         1
  #define Serial Debug

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);  
  Serial.begin( 9600 );    // for tiny_debug_serial  

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  #ifdef KNOCK_BANG
    Serial.print( "KnockBang-");
    Serial.print( "Serial-");
  Serial.println( "Testing...");  // debug output

List of pages in this category:

-- RudolfReuter 2012-12-02 18:02:23

Go back to CategoryAVR or FrontPage ; KontaktEmail (ContactEmail)

AVRTinyISP (last edited 2013-12-26 08:17:25 by RudolfReuter)