edgar-bonet / tiny-morse-decoder

A Morse code to logic-level serial converter for ATtiny13A/25/45/85
MIT License
7 stars 2 forks source link
attiny attiny13a attiny25 attiny45 attiny85 avr morse-code

tiny-morse-decoder: Morse decoder for ATtiny13A

This program translates Morse code, read directly from a [straight key][], into a stream of ASCII characters delivered as a logic-level asynchronous serial signal. It was inspired by the Morse challenge for ATtiny experts by Tom Boyd, but I slightly bent the rules of the challenge:

  1. Whereas the challenge requires the somewhat overpowered ATtiny85 microcontroller, this program targets the much smaller ATtiny13A, although it does also work on the attinies 25, 45 and 85.
  2. It's written in plain C and compiled with gcc, instead of going through the Arduino IDE.

Features

Usage

Connect:

Optionally, pins PB0 and/or PB1 can be connected to ground in order to select a keying speed as per the following table:

PB1 PB0 speed (wpm)
floating floating 5
floating grounded 8
grounded floating 12
grounded grounded 18

In order to facilitate changing the selected speed, it is suggested to add:

Below is the schematic of the suggested circuit:

The circuit can be easily breadboarded. If, however, you want something more durable, check this kit sold by Tom Boyd, which is based on a professionally built PCB.

The “logic-level serial monitor” mentioned above can be anything that is able to process a logic-level asynchronous serial signal. It should be configured to 9600/8N1, i.e. 9600 baud, 8 data bits, no parity, one stop bit. Typically one would use a USB to TTL serial cable connected to a computer running a serial terminal emulator, like putty or GNU screen. On a Linux terminal, one can simply type something like

stty -F /dev/ttyUSB0 raw 9600 && cat /dev/ttyUSB0

An Arduino running a “do nothing” sketch can be used as an alternative to the USB to TTL serial cable: power the ATtiny from the Arduino GND and 5V pins, then connect the ATtiny serial output (PB2) to the Arduino TX pin. When doing this, it is important that the Arduino sketch does not initialize its serial port. The Arduino serial monitor can then be used as an alternative to the serial terminal emulator.

Compiling and uploading

You need GNU make, avr-gcc, avrdude and an ISP programmer. An Arduino can be used as an ISP programmer.

To compile, type

make MCU=<mcu name>

where <mcu_name> should be either attiny13a, attiny25, attiny45 or attiny85. Simply typing

make

compiles for the default target, which is the ATtiny13A.

To upload, edit the Makefile, set the PROGRAMMER variable to match your programmer, connect the programmer to the microcontroller and to the computer, then type

make MCU=<mcu_name> upload

If uploading to an ATtiny13A, you can omit MCU=attiny13a.

Alternatively, gcc and avrdude can be called directly as:

avr-gcc -mmcu=attiny13a -std=gnu11 -fshort-enums -Os \
    tiny-morse-decoder.c -o tiny-morse-decoder.elf
avrdude -p attiny13 -c usbasp -U tiny-morse-decoder.elf

But make sure to replace -c usbasp by the avrdude options appropriate for your programmer.

Another alternative is to open the dummy file tiny-morse-decoder.ino with the Arduino IDE. For this, you will need a board support package matching the microcontroller you are using, in order to be able to select it in the “Board” menu. The code provided by the board support package will not be used.

Files

This repository contains the following files and directories: