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

    One Input 20-key Keypad Interface


    6th July 2018

    This article shows how to interface a 5 x 4 matrix of 20 keys to a single analogue input on a processor such as the ATmega328 or ATtiny85.

    This saves several I/O lines, as a multiplexed 5 x 4 keypad will usually require nine I/O lines. It's also easier to wire up, and the interface program is significantly simpler.

    For an example of a project using this circuit see Tiny Machine-Code Monitor.

    Introduction


    For another project I'm working on I needed a matrix of 16 hexadecimal keys plus four control keys, or 20 keys in total. I decided to try the same approach as my earlier article One Input Keypad Interface, where I gave circuits for a matrix of 12 or 16 keys.

    As before, I used a program (written in Lisp) [1] to search for a set of standard resistor values that would give 20 distinct voltages at the analogue input, and chose the one with the largest minimum spacing between values, to make the design as tolerant of variations in the resistor values as possible.

    The circuit


    Here's the circuit of the keypad interface:

    Matrix20.gif

    The program


    Here's the routine ReadKeypad() to interface to the keypad matrix. It should be suitable for any processor with an analogue input; change the variable Matrix to the input you want to use.

    The program uses two arrays:


    AnalogVals[] stores the analogue values given by each pin, in descending order;

    Buttons[] stores the corresponding button for each voltage. 


    The routine reads the analogue input, and then checks the value against each value in AnalogVals[] until it's larger; it then returns the corresponding button from Buttons[]. To avoid key bounce a do  while loop checks for three equal analogue voltages before returning with a key:
    // Matrix keypad *******************************************************
    
    const int Matrix = A2;
    const int SmallestGap = 24;
    int AnalogVals[] = {1023, 728, 693, 657, 632, 605, 567, 541, 517, 477, 439,
                        404,  371, 316, 290, 264, 220, 186, 151, 93,  0,   -100};
    int Buttons[] =    {-1,   1,   2,   3,   10,  17,  4,   7,   14,  5,   8,
                        0,    6,   9,   11,  15,  12,  18,  13,  19,  20};
    
    // Returns the keypad character or -1 if no button pressed
    int ReadKeypad() {
      int val, lastval=0, count = 0;
      do {
        val = analogRead(Matrix);
        if (abs(val-lastval)<2) count++;
        else { lastval = val; count = 0; }
      } while (count <3);
      int i = 0;
      val = val - SmallestGap/2;
      while (val < AnalogVals[i]) { i++; }
      return Buttons[i - 1];
    }

    The routine ReadKeypad() returns with a value of -1 is no key is being pressed. You could test the routine on an Arduino Uno with the following program:
    void loop() {
      int key;
      // Wait for key
      do { key = ReadKeypad(); } while (key == -1);
      
      Serial.println(key);
    
      // Wait for key released
      do { key = ReadKeypad(); } while (key != -1);
    }

    Further suggestions


    The pushbutton S20 is connected directly to GND, with the 27kΩ pullup resistor to Vcc, so you can use this in a project to wake the processor up from sleep. Before putting the processor to sleep define a pin change interrupt on the input connected to the keypad; pressing S20 will then cause an interrupt and wake the processor from sleep.

    Update


    12th July 2018: I've slightly improved the routine to decode the keypad matrix to make it more tolerant of voltage variations.



    (一)^ Calculating a resistor network on Lispology.




    Next:  Tiny Machine-Code Monitor

    Previous:  Programmable Signal Generator


    blog comments powered by Disqus


    Copyright © 2014-2023