morse decoder / generator

A morse decoder on various microcontrollers


Edsard Boelen, 09-april-2014
For a presentation I am giving at the end of the year about the prototyping platform arduino and the raspberry pi. some demo projects would be nice. In the monthly magazine I receive a PIC course is including a morse generator project. I could bould on on that. So here are 3 morse generators, made on a pic, an arduino and a raspberry pi.



PIC

6 years ago, I switched from PIC to AVR as my default microcontroller. But because a lot of radio amateurs use the pic microcontroller, I thought I could give the PIC another chance.



get the code here

Arduino


For most of my projects, I use the arduino board, it is a low power, low price prototype board.


Then download and install the arduino IDE.

The code :
Untitled
#define dotPeriod (analogRead(A4))
#define dashPeriod (dotPeriod*3)
#define relaxTime (dotPeriod)
#define letterSpace (dotPeriod*2)
#define wordSpace (dotPeriod*4)
#define buzz (analogRead(A5)+200)

#define tonePin A0
#define ledPin 13

void setup(){
  
  pinMode(tonePin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  //pinMode(tonePin, OUTPUT);
}

void loop(){
 
   playLetter('P');
   playLetter('D');
   playLetter('1');
   playLetter('C');
   playLetter('F');
   delay(4000);
}

void di()
{
  tone(tonePin, buzz);
  digitalWrite(ledPin, HIGH);
  delay(dotPeriod);
  noTone(tonePin);
  digitalWrite(ledPin, LOW);
  delay(relaxTime);
}

void dah()
{
  tone(tonePin, buzz);
  digitalWrite(ledPin, HIGH);
  delay(dashPeriod);
  noTone(tonePin);
  digitalWrite(ledPin, LOW);
  delay(relaxTime);
}

void playLetter(char x)
{
	switch (x){
		case 'E':
			di(); break;
		case 'T':
			dah(); break;
		case 'A':
			di();dah(); break;
		case 'O':
			dah();dah();dah(); break;
                case 'P':
			di();dah();dah();di(); break;
                case 'D':
			dah();di();di(); break;
		case '1':
			di();dah();dah();dah();dah(); break;
		case 'C':
			dah();di();dah();di(); break;
                case 'F':
			di();di();dah();di(); break;
		case ' ':
			delay(wordSpace);
        }
}  
  
  




raspberry pi



for the raspberry pi, i didn't use an ide, and I developed on the board itself as it runs debina linux.
I had to download a gpio library, I used wiringpi just compile it and it will be installed
The code is written in vi
compiled with: > gcc morse.c -lwiringPi


get the code here

Also a nice way to make it work is with python, it doesn't need to be compiled, and my tnc_pi utils are also written in python.