Technoblogy



Electronics and microcontroller projects



 






Most popular posts



Tiny Time 2 Watch

Sound Lab - a Simple Analogue Synthesiser

Minimal RP2040 Board

Programming the ATtiny10 [Updated]

RA4M1 Nano Board





Recent posts

 2024




Sound Lab - Example Sounds

Sound Lab - a Simple Analogue Synthesiser

Logic Lab 1G

Secret Maze 2

Building Gates with the AVR Event System

RA4M1 Nano Board

Silver Dollar Game: How to Win


 2023

  • Lisp Badge LE
  • CAN Bus Monitor
  • Logic Lab Problem Answers
  • Logic Lab
  • I2S Speaker for QT Py
  • Adjustable Load
  • Harder Number Maze Game
  • Power Deliverer with Current Monitor
  • Tiny UPDI-HV Programmer
  •  2022

  • Minimal GIF Decoder
  • Lisp Star
  • Graphical Analogue Clock
  • The ATtiny 2-Series
  • Power Deliverer
  • Drawing Filled Quadrilaterals and Triangles
  • Reading from a TFT Display
  • I2C SD-Card Module PCB
  • I2C SD-Card Module
  • Monochrome Low-Power Display Library
  • Three-Channel Chart Plotter
  • Adding File Storage to an Arduino
  • Universal TFT Display Backpack
  • Tiny TFT Graphics Library 2
  • On Bytes and Pins
  • Tiny I2C Routines for all AVR Microcontrollers
  • Minimal RP2040 Board
  • Printing to a Serial LED Display
  • 16 LEDs Kishi Puzzle Solution
  • Twinkling Pendant
  • Morse Code Message Pendant
  • Controlling RGB LED Strips with a Single Function
  • 16 LEDs Solution and a New Puzzle
  •  2021

  • AM Morse-Code Transmitter
  • 16 LEDs Puzzle
  • Low-Power LCD Clock
  • Measuring Your Own Supply Voltage
  • 100MHz Frequency Meter
  • Pocket Op Amp Lab PCB
  • Frequency Divider Using CCL
  • Pocket Op Amp Lab Cookbook
  • I2C Detective
  • Pocket Op Amp Lab
  • Five LEDs Puzzle Solution
  • Five LEDs Puzzle PCB
  •  2020

  • Five LEDs Puzzle
  • Frequency Probe
  • Combination Lock Using CCL
  • Diffusion Clock
  • Smooth Big Text
  • Simple Sprite Routines for the Wio Terminal
  • Saving Screenshots from a TFT Display
  • Simple Sprite Routines for the PyGamer/PyBadge
  • Reading the PyBadge Display
  • Minimal ATmega4809 on a Breadboard
  • Big Time
  • Four Sample Player
  • Mega Tiny Time Watch [Updated]
  •  2019

  • Festive Lights Programming Challenge
  • UPDI Programmer Stick
  • New ATtiny Low Power
  • Nano Current Meter
  • ATtiny Running Lisp
  • Minimal I2C for the New AVR Microcontrollers
  • Getting Started with the New ATtiny Chips
  • Visible Lisp Computer
  • Simple DataFlash Board
  • Magic 3D Clock
  • Tiny TFT Graphics Library
  • Illuminated Button Matrix
  • Two-Digit Thermometer
  • Minimal ATSAMD21 Computer 2
  • Minimal ATSAMD21 Computer
  • Tiny Thermocouple Thermometer
  • Twelve PWM Outputs from an ATtiny85
  • Tiny Function Generator PCB
  • ATtiny10 Thermometer PCB
  • ATtiny10 Thermometer
  • Lisp Badge [Updated]
  •  2018

  • Widget Dashboard
  • Tiny MIDI Player
  • Colour Graphics Library
  • I2C GPS Module PCB
  • Tiny Terminal 2
  • Tiny Function Plotter
  • I2C GPS Module
  • Simple LCD Character Display
  • Alcohol Unit Counter
  • Tiny Machine-Code Monitor
  • One Input 20-key Keypad Interface
  • Programmable Signal Generator
  • Minimal Tiny I2C Routines
  • ATtiny85 20MHz Internal Clock
  • ATtiny10 POV Pendant
  • IR Remote Wand
  • IR Remote Control Detective [Updated]
  • Harmonic Function Generator
  • Tiny Graphics Library
  • Secret Maze PCB
  • Tiny Function Generator Sine Wave
  • Tiny Function Generator
  • Secret Maze
  • Playing Notes on the ATtiny85
  • Tiny Colour Watch
  •  2017

  • Programming the ATtiny10 [Updated]
  • Proto Power Supply
  • Using an ATmega328 without a crystal
  • Bounce-Free Rotary Encoder
  • Four-Channel Thermometer
  • Flexible GPS Parser
  • Tiny Face Watch
  • Driving Four RGB LEDs from an ATtiny85
  • Big Text for Little Display
  • ATtiny85 Graphics Display
  • Tiny Time 2 Watch
  • 10 or 12-bit DAC from the ATtiny85
  • Simple 1-Wire Interface
  • Audio Pitch Shifter
  • Tiny Lisp Computer 2 PCB
  • GameBone Simple Electronic Game
  •  2016

  • Tiny Lisp Computer 2
  • Tiny Lisp Computer
  • Text Display for the Arduino Uno
  • Simple PS/2 Keyboard Interface
  • Making Your Own I2C Peripherals
  • Using the ATmega1284 with the Arduino IDE
  • Digital Clock Using Lisp
  • Making millis() tell the time
  • A Lightweight Alternative to tone
  • Adjustable Load
  • Programming ATtinys with Arduino 1.6.8 [Updated]
  • Digital Music Box [Updated]
  • Using the Arduino IDE Without Cores
  • Flashing Thermometer
  • Portable Lab Power Supply
  • ATtiny85 Sound Level Meter
  •  2015

  • TinyNav Simple GPS Navigator [Updated]
  • Dot Matrix Clock
  • Simple Rotary Encoder Interface [Updated]
  • Driving LED Displays with Fewer I/O Lines
  • Infrared Controlled Buggy
  • Powering Projects from a 1.5V Battery
  • IR Remote Control Switch
  • Odometer/Speedometer Pendant [Updated]
  • Push-Button On/Off Switches
  • Simple ATtiny USI UART 2
  • Sony NEX/Alpha Remote Control
  • IR Remote Control Receiver
  • Bulls & Cows Game 2
  • IR Remote Control Tool (NEC)
  • IR Remote Control Tool
  • Bulls & Cows Game
  • Tiny Terminal
  • Choosing a Friendly AVR Chip
  •  2014

  • Simple Compass Display
  • Tiny GPS Speedometer [Updated]
  • Minimal GPS Parser [Updated]
  • Simple ATtiny USI UART
  • Timescale Clock
  • Tiny Synth
  • Waveform Generation using an ATtiny85
  • Audio Sample Player
  • ATtiny85 Analogue Clock
  • Radio Time Code Clock
  • Four PWM Outputs from the ATtiny85
  • ATtiny-Based Beginner's Kit
  • MINIL Machine-Code Monitor
  • One Input Keypad Interface
  • Conundrometer Game
  • Getting Extra Pins on ATtiny
  • Simple Tones for ATtiny
  • ATtiny Low Power


  • Topics

     Games

  • Bulls & Cows Game
  • Bulls & Cows Game 2
  • GameBone Simple Electronic Game
  • Secret Maze
  • Secret Maze PCB
  • Five LEDs Puzzle
  • Five LEDs Puzzle PCB
  • 16 LEDs Puzzle
  • 16 LEDs Solution and a New Puzzle
  • 16 LEDs Kishi Puzzle Solution
  • Number Maze Game
  • Harder Number Maze Game
  • Silver Dollar Game
  • Secret Maze 2
  •  Sound & Music

  • Simple Tones for ATtiny
  • Waveform Generation using an ATtiny85
  • Tiny Synth
  • ATtiny85 Sound Level Meter
  • Digital Music Box [Updated]
  • A Lightweight Alternative to tone
  • Audio Pitch Shifter
  • Playing Notes on the ATtiny85
  • Tiny Function Generator
  • Tiny Function Generator Sine Wave
  • Harmonic Function Generator
  • Tiny MIDI Player
  • Tiny Function Generator PCB
  • Four Sample Player
  • I2S Speaker for QT Py
  • Sound Lab - a Simple Analogue Synthesiser
  •  Watches & Clocks

  • ATtiny85 Analogue Clock
  • Timescale Clock
  • Dot Matrix Clock
  • Digital Clock Using Lisp
  • Tiny Time Watch
  • Tiny Time 2 Watch
  • Tiny Face Watch
  • Tiny Colour Watch
  • Magic 3D Clock
  • Mega Tiny Time Watch [Updated]
  • Big Time
  • Diffusion Clock
  • Low-Power LCD Clock
  • Graphical Analogue Clock
  •  GPS

  • Simple ATtiny USI UART 2
  • Minimal GPS Parser [Updated]
  • Tiny GPS Speedometer [Updated]
  • Simple Compass Display
  • Simple GPS Odometer
  • Odometer/Speedometer Pendant [Updated]
  • TinyNav Simple GPS Navigator [Updated]
  • Flexible GPS Parser
  • I2C GPS Module
  • I2C GPS Module PCB
  •  Power Supplies

  • Portable Lab Power Supply
  • Proto Power Supply
  • Power Deliverer
  • Power Deliverer with Current Monitor
  •  Computers

  • Tiny Lisp Computer
  • Tiny Lisp Computer 2
  • Tiny Lisp Computer 2 PCB
  • Tiny Machine-Code Monitor
  • Lisp Badge [Updated]
  • Minimal ATSAMD21 Computer
  • Minimal ATSAMD21 Computer 2
  • Visible Lisp Computer
  • ATtiny Running Lisp
  • Minimal ATmega4809 on a Breadboard
  • Minimal RP2040 Board
  • Lisp Badge LE
  • RA4M1 Nano Board
  •  Graphics

  • ATtiny85 Graphics Display
  • Big Text for Little Display
  • Tiny Graphics Library
  • Tiny Function Plotter
  • Tiny Terminal 2
  • Colour Graphics Library
  • Widget Dashboard
  • Tiny TFT Graphics Library
  • Reading the PyBadge Display
  • Simple Sprite Routines for the PyGamer/PyBadge
  • Simple Sprite Routines for the Wio Terminal
  • Smooth Big Text
  • Compact TFT Graphics Library
  • Tiny TFT Graphics Library 2
  • Universal TFT Display Backpack
  • Three-Channel Chart Plotter
  • Monochrome Low-Power Display Library
  • Reading from a TFT Display
  •  Thermometers

  • Simple 1-Wire Interface
  • Four-Channel Thermometer
  • Tiny Graphics Library
  • ATtiny85 Weather Station [Updated]
  • ATtiny10 Thermometer
  • ATtiny10 Thermometer PCB
  • Tiny Thermocouple Thermometer
  • Two-Digit Thermometer
  •  Wearables

  • ATtiny10 POV Pendant
  • ATtiny10 Thermometer PCB
  • Morse Code Message Pendant
  • Twinkling Pendant
  • Lisp Star
  •  Test Equipment

  • IR Remote Control Tool (NEC)
  • IR Remote Control Receiver
  • Sony NEX/Alpha Remote Control
  • IR Remote Control Switch
  • ATtiny85 Bargraph Voltmeter
  • Adjustable Load
  • Continuity Tester
  • IR Remote Control Detective [Updated]
  • IR Remote Wand
  • Programmable Signal Generator
  • Alcohol Unit Counter
  • Illuminated Button Matrix
  • Simple DataFlash Board
  • Nano Current Meter
  • UPDI Programmer Stick
  • Frequency Probe
  • Pocket Op Amp Lab
  • I2C Detective
  • Pocket Op Amp Lab PCB
  • 100MHz Frequency Meter
  • Three-Channel Chart Plotter
  • I2C SD-Card Module
  • I2C SD-Card Module PCB
  • Tiny UPDI-HV Programmer
  • Adjustable Load
  •  Tutorials

  • Getting Extra Pins on ATtiny
  • One Input Keypad Interface
  • ATtiny-Based Beginner's Kit
  • Four PWM Outputs from the ATtiny85
  • Choosing a Friendly AVR Chip
  • Push-Button On/Off Switches
  • Powering Projects from a 1.5V Battery
  • Driving LED Displays with Fewer I/O Lines
  • Simple Rotary Encoder Interface [Updated]
  • Using the Arduino IDE Without Cores
  • Programming ATtinys with Arduino 1.6.8 [Updated]
  • Using the ATmega1284 with the Arduino IDE
  • Making Your Own I2C Peripherals
  • Simple 1-Wire Interface
  • 10 or 12-bit DAC from the ATtiny85
  • Driving Four RGB LEDs from an ATtiny85
  • Bounce-Free Rotary Encoder
  • Using an ATmega328 without a crystal
  • Programming the ATtiny10 [Updated]
  • ATtiny85 20MHz Internal Clock
  • Minimal Tiny I2C Routines
  • One Input 20-key Keypad Interface
  • Simple LCD Character Display
  • Twelve PWM Outputs from an ATtiny85
  • Minimal I2C for the New AVR Microcontrollers
  • New ATtiny Low Power
  • Saving Screenshots from a TFT Display
  • Smooth Big Text
  • Pocket Op Amp Lab Cookbook
  • Frequency Divider Using CCL
  • Measuring Your Own Supply Voltage
  • Using a Timer on the Arduino Uno or Arduino Zero
  • Printing to a Serial LED Display
  • Tiny I2C Routines for all AVR Microcontrollers
  • On Bytes and Pins
  • Building Gates with the AVR Event System
  •  Libraries

  • Minimal Tiny I2C Routines
  • Colour Graphics Library
  • Minimal I2C for the New AVR Microcontrollers
  • Compact TFT Graphics Library
  • Tiny I2C Routines for all AVR Microcontrollers
  • Tiny TFT Graphics Library 2
  • Monochrome Low-Power Display Library
  • Minimal GIF Decoder
  •  PCB-Based Projects

  • GameBone Simple Electronic Game
  • Tiny Time 2 Watch
  • Tiny Face Watch
  • Proto Power Supply
  • Continuity Tester
  • Tiny Colour Watch
  • Secret Maze PCB
  • Tiny Machine-Code Monitor
  • ATtiny10 POV Pendant
  • I2C GPS Module PCB
  • Lisp Badge [Updated]
  • ATtiny10 Thermometer PCB
  • Tiny Function Generator PCB
  • Two-Digit Thermometer
  • Illuminated Button Matrix
  • Simple DataFlash Board
  • UPDI Programmer Stick
  • Eight-Character Alphanumeric Display
  • Mega Tiny Time Watch [Updated]
  • Big Time
  • Frequency Probe
  • Five LEDs Puzzle PCB
  • Pocket Op Amp Lab PCB
  • Low-Power LCD Clock
  • 16 LEDs Puzzle
  • Morse Code Message Pendant
  • Twinkling Pendant
  • Minimal RP2040 Board
  • Universal TFT Display Backpack
  • I2C SD-Card Module PCB
  • Power Deliverer
  • Lisp Star
  • Number Maze Game
  • Power Deliverer with Current Monitor
  • Harder Number Maze Game
  • Adjustable Load
  • I2S Speaker for QT Py
  • Logic Lab
  • Lisp Badge LE
  • Silver Dollar Game
  • RA4M1 Nano Board
  • Secret Maze 2
  • Logic Lab 1G
  • Sound Lab - a Simple Analogue Synthesiser
  • By processor


    AVR ATtiny

     ATtiny10

  • ATtiny10 POV Pendant
  • ATtiny10 Thermometer
  • ATtiny10 Thermometer PCB
  • Morse Code Message Pendant
  • Twinkling Pendant
  •  ATtiny2313

  • Driving LED Displays with Fewer I/O Lines
  • Dot Matrix Clock
  •  ATtiny84

  • Timescale Clock
  • IR Remote Control Tool
  • IR Remote Control Tool (NEC)
  • Simple ATtiny USI UART 2
  • Odometer/Speedometer Pendant [Updated]
  • Adjustable Load
  • Alcohol Unit Counter
  • Two-Digit Thermometer
  • Nano Current Meter
  • Frequency Probe
  • Adjustable Load
  • Silver Dollar Game
  •  ATtiny841

  • I2C GPS Module
  • I2C GPS Module PCB
  •  ATtiny85

  • Simple Tones for ATtiny
  • MINIL Machine-Code Monitor
  • Four PWM Outputs from the ATtiny85
  • ATtiny85 Analogue Clock
  • Audio Sample Player
  • Waveform Generation using an ATtiny85
  • Tiny Synth
  • Simple ATtiny USI UART
  • Tiny GPS Speedometer [Updated]
  • Simple Compass Display
  • Tiny Terminal
  • IR Remote Control Receiver
  • Sony NEX/Alpha Remote Control
  • Simple ATtiny USI UART 2
  • Push-Button On/Off Switches
  • IR Remote Control Switch
  • Infrared Controlled Buggy
  • Simple Rotary Encoder Interface [Updated]
  • TinyNav Simple GPS Navigator [Updated]
  • ATtiny85 Bargraph Voltmeter
  • ATtiny85 Sound Level Meter
  • Flashing Thermometer
  • Digital Music Box [Updated]
  • Tiny Time Watch
  • GameBone Simple Electronic Game
  • Audio Pitch Shifter
  • Simple 1-Wire Interface
  • 10 or 12-bit DAC from the ATtiny85
  • Tiny Time 2 Watch
  • ATtiny85 Graphics Display
  • Big Text for Little Display
  • Driving Four RGB LEDs from an ATtiny85
  • Tiny Face Watch
  • Flexible GPS Parser
  • Four-Channel Thermometer
  • Bounce-Free Rotary Encoder
  • Continuity Tester
  • Tiny Colour Watch
  • Playing Notes on the ATtiny85
  • Secret Maze
  • Tiny Function Generator
  • Tiny Function Generator Sine Wave
  • Secret Maze PCB
  • Tiny Graphics Library
  • Harmonic Function Generator
  • IR Remote Control Detective [Updated]
  • IR Remote Wand
  • ATtiny85 20MHz Internal Clock
  • Programmable Signal Generator
  • Tiny Machine-Code Monitor
  • Tiny Function Plotter
  • Tiny Terminal 2
  • Colour Graphics Library
  • Tiny MIDI Player
  • Widget Dashboard
  • ATtiny85 Weather Station [Updated]
  • Tiny Function Generator PCB
  • Twelve PWM Outputs from an ATtiny85
  • Tiny Thermocouple Thermometer
  • Tiny TFT Graphics Library
  • Magic 3D Clock
  • Four Sample Player
  • Diffusion Clock
  • Five LEDs Puzzle
  • Five LEDs Puzzle PCB
  • Printing to a Serial LED Display
  • Tiny TFT Graphics Library 2
  • Secret Maze 2
  •  ATtiny861

     ATtiny88


    AVR ATmega

     ATmega328

  • Bulls & Cows Game
  • Bulls & Cows Game 2
  • A Lightweight Alternative to tone
  • Digital Clock Using Lisp
  • Simple PS/2 Keyboard Interface
  • Text Display for the Arduino Uno
  • Tiny Lisp Computer
  • Using an ATmega328 without a crystal
  • Proto Power Supply
  • Simple LCD Character Display
  • UPDI Programmer Stick
  • Using a Timer on the Arduino Uno or Arduino Zero
  •  ATmega1284

  • Tiny Lisp Computer 2
  • Tiny Lisp Computer 2 PCB
  • Lisp Badge [Updated]

  • AVR 0-series and 1-series

     ATmega4809

  • Logic Lab
  •  ATtiny1604

  • Power Deliverer with Current Monitor
  •  ATtiny1614

  • I2C SD-Card Module PCB
  •  ATtiny3216

  • Big Time
  •  ATtiny3227

     ATtiny402

  • Printing to a Serial LED Display
  • Tiny TFT Graphics Library 2
  • Three-Channel Chart Plotter
  • Monochrome Low-Power Display Library
  •  ATtiny404

  • 16 LEDs Solution and a New Puzzle
  •  ATtiny414

  • 100MHz Frequency Meter
  • Measuring Your Own Supply Voltage
  • Universal TFT Display Backpack
  •  ATtiny814


    AVR DA/DB-series

     AVR128DA28

  • Frequency Divider Using CCL
  • Measuring Your Own Supply Voltage
  • Minimal GIF Decoder
  • Building Gates with the AVR Event System
  •  AVR128DA32

  • Harder Number Maze Game
  •  AVR128DA48

  • Logic Lab
  •  AVR128DB28

  • Pocket Op Amp Lab Cookbook
  • Pocket Op Amp Lab PCB
  • Measuring Your Own Supply Voltage
  • Minimal GIF Decoder
  • ► AVR128DB48


    ARM

     ATSAMD21

  • Minimal ATSAMD21 Computer 2
  • Visible Lisp Computer
  • Using a Timer on the Arduino Uno or Arduino Zero
  •  RP2040

     RA4M1

    About me



    About me



    Twitter

    Mastodon

    Feeds


    RSS feed

    Getting Extra Pins on ATtiny


    4th June 2014

    Part of the fun of designing with the ATtiny85 and ATtiny84 ranges is trying to shoehorn your project into the tiny package. I'm sure I'm not the first person who has run out of I/O pins while trying to use one for a project. Here are some tips I've discovered for making better use of the existing pins, or finding an extra pin. 

    Sharing inputs


    How many inputs do you need to use to sense n pushbuttons?

    The simplest method is to connect each pushbutton to a separate input. This requires n inputs.

    For more than four pushbuttons it is better to arrange the pushbuttons into a x by y matrix, and multiplex them. This requires x+y inputs, so for 16 pushbuttons you need 8 inputs, or for n pushbuttons you need about root n inputs.

    A less obvious trick is to connect several pushbuttons to a single analogue input using a resistor ladder to give each button a different voltage. Here's an example with five buttons:

    ResistorLadder.png
    Connecting five pushbuttons to a single input.

    The 1kΩ resistors form a voltage divider, giving outputs of 0V, 1V, 2V, 3V, and 4V. With no button pressed the analogue input A0 is floating, so the internal pullup resistor should be enabled. Pressing a button sets A0 to the corresponding voltage.

    To read which pushbutton is pressed we just need to do:
    button = (analogRead(A0)*5+512)/1024;

    which returns a number between 0 and 5.

    The advantage of the above design is that it uses five identical resistors, so it's easy to construct. The disadvantage is that it draws current even when no button is pressed; in this case 1mA. Here's an alternative design that solves this problem:

    ResistorLadder3.png
    Connecting five pushbuttons to a single input.

    Again, this gives voltages of 0V, 1V, 2V, 3V, and 4V, or 5V with no button pressed, but has the advantage that it draws no current when no button is pressed, and no pullup is needed. The resistors need to be in the ratios 12, 3, 5, 10, 30, but can be any suitably close values. I ran a program to find the best values from the E6 series; the values shown above produce voltages within 10% of the required values. Again, to read which pushbutton is pressed just do:
    button = (analogRead(A0)*5+512)/1024;

    Using a pin as both an input and an output


    Suppose you've got one pin available and you need to display status on an LED, and sense a pushbutton. One option is to use the same pin as both an input and an output:

    InputOutput.png
    Using a pin as both an input and an output.

    Set the output low when you want to turn on the LED. Program it as an input when you want to turn off the LED, or read the pushbutton. You shouldn't set the output high since the pushbutton could then short the output to ground; to protect against this connect a second 220Ω resistor in series with the switch.

    The only limitation is that the LED lights up while the pushbutton is pressed, but if the LED is showing the status of an option selected by the pushbutton that may actually be appropriate.

    Here's a simple program that demonstrates this circuit; the LED is normally off, but pressing the pushbutton latches it on for one second:
    int led = 3;
    
    void setup() {                
      digitalWrite(led, LOW);
      pinMode(led, INPUT);
    }
    
    void loop() {
      // Read input
      if (digitalRead(led) == LOW) {
        // Turn LED on
        pinMode(led, OUTPUT);
        delay(1000);
        // Turn LED off
        pinMode(led, INPUT);
      }
    }

    Using the reset pin on the ATtiny85 


    As is well known you can reprogram the internal fuses to reclaim the reset pin as an extra I/O pin. What is less well-known is that you can actually use the reset pin in a limited way on the ATtiny85 without having to reprogram the fuses, provide you avoid taking it below about 2.5V which will reset the chip.

    Here's the program I used to test this on an ATtiny85 using the 1MHz internal clock:
    /* Using the Reset pin as ADC0 */
    
    const int Speaker = 3;
    
    // Beep out a 10-bit binary number, LSB first
    void debug (unsigned int thing) {
      for (unsigned int b=1; b!=1024; b = b<<1) {
        for (unsigned int i=0; i<1250; i++) {
          if (thing &b) digitalWrite(Speaker, (i &16));
          else digitalWrite(Speaker, (i &32));
        }
        for (unsigned int i=0; i<1250; i++) digitalWrite(Speaker, 0);
      }
    }
    
    void setup() {
      pinMode(Speaker, OUTPUT);
    }
    
    void loop() {
       debug(analogRead(0));
       delay(2000);
    }

    To reveal the ADC reading I've connected a piezo speaker between PB3 and ground, and I'm using a simple debug routine which beeps out the ten-bit ADC value as a series of low and high beeps, LSB first, with a low beep representing a 0 and a high beep representing a 1.

    I tested it by connecting a potentiometer across the supply, with the wiper connected to the reset pin. Here are the results:


    5v - reading 0b11111111 or 1023

    2.2V - reading 0b0111000011 or 451

    Below 2.2V - ATtiny85 reset


    This corresponds to the datasheet, and gives us a range of 2.8V over which we can use the reset pin for analogue measurements.

    One simple application is to sense a pushbutton that switches ADC0 between 3v and 5v:

    ResetADC0.png
    Using the reset pin on the ATtiny85.

    Reprogramming the fuses to use the reset pin as an I/O pin


    If all else fails you can reprogram the fuses to use the reset pin as another I/O pin. This will enable you to use it as a digital or analogue input, or as an output to flash an LED:

    ResetLED.png
    Reprogramming the fuses to use the ATtiny85 reset pin as an I/O pin.

    The problem is that once you have done that you will no longer be able to upload a program using an ISP programmer without first resetting the fuses using a high voltage programmer.

    Here's the full procedure. First upload the program that will use the Reset pin. I'm using a simple Blink program to blink an LED, using the Reset pin as an output:
    /* Blink Reset pin */
    
    int led = 5; // Reset pin
    
    void setup() {                
      DDRB = 1<<led;     
    }
    
    void loop() {
      PINB = 1<<led;
      delay(1000);
    }

    To program the ATtiny85 I used Sparkfun's Tiny AVR Programmer [1]. To use this with the Arduino IDE install the ATtiny microcontroller support for the Arduino IDE.

    You now need to reprogram the High Fuses to 0x5f rather than 0xdf, to set the RSTDISBL fuse.

    The simplest way is to use a high-voltage programmer, which lets you set the fuses to anything you want. You can use an Arduino Uno as a high-voltage programmer [2]. Alternatively Proto-Pic in the UK used to sell a high-voltage programmer shield which used a 12V external power supply. Unfortunately this is no longer available.

    HighVoltage.jpg
    In the fuse reset program change the desired fuse configurations to:
    // Desired fuse configuration
    #define  HFUSE  0x5F
    #define  LFUSE  0x62    

    and run the program to set the RSTDISBL fuse.

    Now if you put the ATtiny85 back in the circuit the LED connected to pin 1, the reset pin, should flash as required. Note that the reset pin doesn't have such a high drive capability as the other pins, so the LED will be dimmer than an LED on pins 0 to 4.

    Resetting the fuses to their defaults


    If you've set the RSTDISBL fuse ISP programming will no longer work; next time you try to upload a program using the Tiny AVR Programmer you'll get the error:
    avrdude: initialization failed, rc=-1

    You will need to reset the fuses to their default values using the High-Voltage Programmer again before proceeding.



    (一)^ Tiny AVR Programmer Hookup Guide on SparkFun.

    (二)^ ATtiny Fuse Reset on Wayne's Tinkering Page.




    Next:  Conundrometer Game

    Previous:  Simple Tones for ATtiny


    blog comments powered by Disqus


    Copyright © 2014-2023