ATtiny84/85 Transmit Only Serial Output


Introduction: ATtiny84/85 Transmit Only Serial Output

This instructable corrects/updates/amends a previous instructable which used the SoftwareSerial class to implement serial output for the Atmel ATtiny84 and ATtiny85 devices. There are a couple of significant issues associated with use of the SoftwareSerial class:

  1. It requires use of 2 pins, 1 for transmit and 1 for receive, even though serial output requires only transmit
  2. It uses a Pin Change interrupt for receive, therefore tying up a device Port. In fact, it allocates ALL the device ports to the receive pin change ISR.

Fortunately, Nick Gammon modified the SoftwareSerial class to create a transmit only version, SendOnlySoftwareSerial, which requires only 1 device pin and no interrupts. This instructable follows the steps of the previous SoftwareSerial instructable pointing out the differences in use of the SendOnlySoftwareSerial class for serial output. Differences are highlighted in red; the original instructable is referenced where text/procedures are the same.

Step 1: Software Overview

Serial communication support is added to the standard Blink Arduino example program using the SendOnlySoftwareSerial class and one device pin assigned for transmit.

The remainder of this section is the same as for the previous instructable.

Step 2: Required Hardware

This section is the same as for the previous instructable.

Step 3: Tiny AVR Programmer Setup

This section is the same as for the previous instructable.

Step 4: BreadBoard Layout for ATtiny84

As depicted in the fritzing diagram above all differences in setup for the ATtiny84 are in connection of the USB to TTL cable since the receive signal is no longer connected. The updates to that paragraph are shown below:

Two of the four signals on the USB to Serial cable are connected:

  • Ground (black) to breadboard ground rail
  • Transmit(green) is not connected
  • Receive (white) to transmit pin assigned to SendOnlySoftwareSerial (pin 10)
  • Power (red) should not be connected since power is being supplied by the Programmer

The rest of this section is the same as for the previous instructable.

Step 5: Program Explanation

The serial output example program (listed below) is based on the Arduino Blink example program with additions for serial output support. The following table explains the additional serial support statements:

#include <SendOnlySoftwareSerial.h>Gain access to the Serial class functionality
#if defined...#elseThis section assigns device specific I/O pins
#errorProgram only supports tiny84/85 so stop compile if not one of these
SendOnlySoftwareSerial mySerial(txPin);Create a Serial class instance to be used for serial output
mySerial.begin(9600);Initialize/start SoftwareSerial communication at 9600 baud
mySerial.println(text);Send text to the serial output window for display
  • To indicate Setup is complete
  • To indicate Led just turned on
  • To indicate Led just turned off

SoftwareSerial is replaced by SendOnlySoftwareSerial in the program but not highlighted in red since that would add html markup to the program listing:

//  PART 1: Serial output setup and example output:
//  .  Modifies the example Blink code to illustrate serial output
//  .  Common code for ATtiny85 and ATtiny84
#include <SendOnlySoftwareSerial.h>   // Arduino SendOnlySoftwareSerial class
// While the processing code is common, the pins used are device specific
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny84A__)
  #define ledPin  4               // Toggle to turn connected Led on/off
  #define txPin   10              // Pin used for Serial transmit
#elif defined(__AVR_ATtiny85__)
  #define ledPin  1
  #define txPin   3
  #error Only ATiny84 and ATtiny85 are Supported by this Project
// Create instance of the Software Serial class specifying which device
// pins are to be used for receive and transmit
SendOnlySoftwareSerial mySerial(txPin);
// Initialize processing resources
void setup() 
  mySerial.begin(9600);       // Start serial processing      
  delay(2000);                // Give Serial class time to complete initialization.
                              // otherwise, 1st output likely missing or garbled
  pinMode(ledPin, OUTPUT);    // Configure led pin for OUTPUT  
  mySerial.println("SETUP Complete - Attiny84/85 Serial Example");
// Toggle the led; document HIGH/LOW with serial output messages
void loop() 
  // Turn led on; display "it's on" message
  digitalWrite(ledPin, HIGH);   
  mySerial.println("LED ON");
  // Turn led off; display "it's off" message
  digitalWrite(ledPin, LOW);      
  mySerial.println(" LED OFF");

Step 6: Run the Program

This section is essentially the same as for the original instructable with the exception that the setup debug output has a minimal change:

SETUP Complete - Attiny84/85 Serial Example

Step 7: Setup and Run Program for ATtiny85

As for ATtiny84, the hardware changes are in the connection of the USB to TTL Serial cable (as shown in the above fritzing diagram) to connect only the device transmit signal. The same software program is used as for the ATtiny84 for this instructable.

Step 8: Miscellaneous

  1. The Arduino UNO can be used for Serial output instead of the Serial cable:
    • Connect the UNO's dedicated receive (pin 0) and transmit (pin 1) pins to the microcontrollers receive and transmit pins. Note that the connections are receive-receive, transmit-transmit instead of receive-transmit, transmit-receive as they are when using the Serial cable.
    • Run the Arduino examples Minimum program (empty setup; empty loop) on the UNO
    • Launch the (already available) COM window from the IDE (COM3 on my laptop)
    • Upload and run the Serial output program on the tiny84/tiny85
    • The serial output messages will appear in the Arduino COM window

The remainder of this section is the same as for the original instructable.



    • Oil Contest

      Oil Contest
    • Clocks Contest

      Clocks Contest
    • Water Contest

      Water Contest