Introduction: Intel Edison Morse Code Trainer
What you need:
Parts:
- Intel Edison Arduino IoT
- 12v power supply, optionally with battery backup. This may not be needed.
- Grove expansion board connected to Edison Arduino Board
- Grove Buzzer connected to port 5
- WiFi connection
Software:
- Current Yocto or Ubilinux
- SSH client on desktop system (ssh native on most linux, Putty on windows)
This Instructable assumes you have a basic knowledge of ssh, assembled the Edison, updated Linux, and connected it to the WiFi.
Step 1: Easy Setup
Remember we are assuming you have some knowledge of linux(or can google).
- Connect your Edison to the arduino expansion board(probably done already)
- Connect the Grove Board expansion to the arduino board
- Connect the Grove Buzzer to the pin D5 of the Grove expansion
- Plug in your Arduino(I am going to assume you have already done initial setup)
- Install mraa
- On ubilinux follow these instruction:
- Download the included files
- morse.c
- pins.h
- Use your favorite tool to get those files onto your Edison
- We used btsync from my other build
- SSH pull or ssh push could do the job(from linux machines) .
- scp /path/to/file username@addressToPi:/path/to/destination
- I will include the plain text in the next step and you can just vi your own files
- Make sure both files are in the same folder.
Step 2: Code Pins.h
/*
* pins.h
*
* Created on: Jan 31, 2015
*/
#ifndef PINS_H_
#define PINS_H_
#include<stdio.h>
#include<unistd.h>
#include<errno.h>
#include<signal.h>
#include<stdlib.h>
#include<time.h>
#include "mraa.h"
void delay(int milliseconds);
bool PinPulse(int pin, int time){
mraa_result_t r = MRAA_SUCCESS;
mraa_init();
mraa_gpio_context gpio;
gpio = mraa_gpio_init(pin);
if ( gpio == NULL ) {
fprintf(stderr, "Error opening GPIO\n");
exit(1);
}
r = mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
if ( r != MRAA_SUCCESS ) {
mraa_result_print(r);
mraa_result_print(r);
}
//turn on
r = mraa_gpio_write(gpio, 1);
if ( r != MRAA_SUCCESS) {
mraa_result_print(r);
}
delay(time);
//turn off
r = mraa_gpio_write(gpio, 0);
if ( r != MRAA_SUCCESS) {
mraa_result_print(r);
}
/* Clean up GPIO and exit */
r = mraa_gpio_close(gpio);
if ( r != MRAA_SUCCESS ) {
mraa_result_print(r);
}
}
void delay(int milliseconds)
{
long pause;
clock_t now,then;
pause = milliseconds*(CLOCKS_PER_SEC/1000);
now = then = clock();
while( (now-then) < pause )
now = clock();
}
#endif /* PINS_H_ */
Step 3: Code 2 Morse.c Pasted Wrong.
//Looks like a lot of code but it is not
//Tried to clean up the parsing from the bad copy and paste
//Downloading it is a lot easier
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<unistd.h>
#include<errno.h>
#include<signal.h>
#include<iostream>
#include "mraa.h"
#include "pins.h"
//Global declarations
void delay(int milliseconds);
void A();
void B();
void C();
void D();
void E();
void F();
void G();
void H();
void I();
void J();
void K();
void L();
void M();
void N();
void O();
void P();
void Q();
void R();
void S();
void T();
void U();
void V();
void W();
void X();
void Y();
void Z();
void Zero();
void One();
void Two();
void Three();
void Four();
void Five();
void Six();
void Seven();
void Eight();
void Nine();
void Period();
void Comma();
void Question();
void Apostrophe();
void Exclamation();
void Slash();
void Open();
void Close();
void Ampersand();
void Colon();
void Semicolon();
void Equals();
void Plus();
void Minus();
void Quote();
void Dollar();
void At();
void Underscore();
void Space();
void dot();
void dash();
void pa();
void endOf();
int tim = 500; //Currently set for half a second
//Main function
int main() {
printf("Hello World\n"); char s [256];
printf("enter the string : ");
scanf("%[^\n]", s);
printf("you entered %s\n", s);
int i;
//Switch statement to pick the letter and sound the pulses
for(i=0;s[i]!=0;i++){
printf("%c\n", s[i]); char sw = s[i];
switch(sw){
case 'A':
case 'a':
A();
break;
case 'B':
case 'b':
B();
break;
case 'C':
case 'c':
C();
break;
case 'D':
case 'd':
D();
break;
case 'E':
case 'e':
E();
break;
case 'F':
case 'f':
F();
break;
case 'G':
case 'g':
G();
break;
case 'H':
case 'h':
H();
break;
case 'I':
case 'i':
I();
break;
case 'J':
case 'j':
J();
break;
case 'k':
case 'K':
K();
break;
case 'L':
case 'l':
L();
break;
case 'M':
case 'm':
M();
break;
case 'N':
case 'n':
N();
break;
case 'O':
case 'o':
O();
break;
case 'P':
case 'p':
P();
break;
case 'Q':
case 'q':
Q();
break;
case 'R':
case 'r':
R();
break;
case 'S':
case 's':
S();
break;
case 'T':
case 't':
T();
break;
case 'U':
case 'u':
U();
break;
case 'V':
case 'v':
V();
break;
case 'W':
case 'w':
W();
break;
case 'X':
case 'x':
X();
break;
case 'Y':
case 'y':
Y();
break;
case 'Z':
case 'z':
Z();
break;
case '0':
Zero();
break;
case '1':
One();
break;
case '2':
Two();
break;
case '3':
Three();
break;
case '4':
Four();
break;
case '5':
Five();
break;
case '6':
Six();
break;
case '7':
Seven();
break;
case '8':
Eight();
break;
case '9':
Nine();
break;
case '.':
Period();
break;
case ',':
Comma();
break;
case '?':
Question();
break;
case '\'':
Apostrophe();
break;
case '!':
Exclamation();
break;
case '/':
Slash();
break;
case '(':
Open();
break;
case ')':
Close();
break;
case '&':
Ampersand();
break;
case ':':
Colon();
break;
case ';':
Semicolon();
break;
case '=':
Equals();
break;
case '+':
Plus();
break;
case '-':
Minus();
break;
case '_':
Underscore();
break;
case '"':
Quote();
break;
case '$':
Dollar();
break;
case '@':
At();
break;
case ' ':
Space();
break;
default:
break;
}
}
//free(s);
return 0;
}
//Functions for each letter and symbol
void A(void){
printf(".-\n");
dot();
dash();
pa();
}
void B(void){
printf("-...\n");
dash(); dot(); dot(); dot(); pa();
}
void C(void){
printf("-.-.\n");
dash(); dot(); dash(); dot(); pa();
}
void D(void){
printf("-..\n");
dash(); dot(); dot(); pa();
}
void E(void){
printf(".\n");
dot(); pa();
}
void F(void){
printf("..-.\n");
dot(); dot(); dash(); dot(); pa();
}
void G(void){
printf("--.\n");
dash(); dash(); dot(); pa();
}
void H(void){
printf("....\n");
dot(); dot(); dot(); dot(); pa();
}
void I(void){
printf("..\n");
dot(); dot(); pa();
}
void J(void){
printf(".---\n");
dot(); dash(); dash(); dash(); pa();
}
void K(void){
printf("-.-\n");
dash(); dot(); dash(); pa();
}
void L(void){
printf(".-..\n");
dot(); dash(); dot(); dot(); pa();
}
void M(void){
printf("--\n");
dash(); dash(); pa();
}
void N(void){
printf("-.\n");
dash(); dot(); pa();
}
void O(void){
printf("---\n");
dash(); dash(); dash(); pa();
}
void P(void){
printf(".--.\n");
dot(); dash(); dash(); dot(); pa();
}
void Q(void){
printf("--.-\n");
dash(); dash(); dot(); dash(); pa();
}
void R(void){
printf(".-.\n");
dot(); dash(); dot(); pa();
}
void S(void){
printf("...\n");
dot(); dot(); dot(); pa();
}
void T(void){
printf("-\n");
dash(); pa();
}
void U(void){
printf("..-\n");
dot(); dot(); dash(); pa();
}
void V(void){
printf("...-\n");
dot(); dot(); dot(); dash(); pa();
}
void W(void){
printf(".--\n");
dot(); dash(); dash(); pa();
} void X(void){
printf("-..-\n");
dash(); dot(); dot(); dash(); pa();
}
void Y(void){
printf("-.--\n");
dash(); dot(); dash(); dash(); pa();
}
void Z(void){
printf("--..\n");
dash(); dash(); dot(); dot(); pa();
}
void Zero(void){
printf("-----\n");
dash(); dash(); dash(); dash(); dash(); pa();
}
void One(void){
printf(".----\n");
dot(); dash(); dash(); dash(); dash(); pa();
}
void Two(void){
printf("..---\n");
dot(); dot(); dash(); dash(); dash(); pa();
}
void Three(void){
printf("...--\n");
dot(); dot(); dot(); dash(); dash(); pa();
}
void Four(void){
printf("....-\n");
dot(); dot(); dot(); dot(); dash(); pa();
}
void Five(void){
printf(".....\n");
dot(); dot(); dot(); dot(); dot(); pa();
}
void Six(void){
printf("-....\n");
dash(); dot(); dot(); dot(); dot(); pa();
}
void Seven(void){
printf("--...\n");
dash(); dash(); dot(); dot(); dot(); pa();
}
void Eight(void){
printf("---..\n");
dash(); dash(); dash(); dot(); dot(); pa();
}
void Nine(void){
printf("----.\n");
dash(); dash(); dash(); dash(); dot(); pa();
}
void Period(void){
printf(".-.-.-\n");
dot(); dash(); dot(); dash(); dot(); dash(); pa();
}
void Comma(void){
printf("--..--\n");
dash(); dash(); dot(); dot(); dash(); dash(); pa();
}
void Question(void){
printf("..--..\n");
dot(); dot(); dash(); dash(); dot(); dot(); pa();
}
void Apostrophe(void){
printf(".----.\n");
dot(); dash(); dash(); dash(); dash(); dot(); pa();
}
void Exclamation(void){
printf("-.-.--\n");
dash(); dot(); dash(); dot(); dash(); dash(); pa();
}
void Slash(void){
printf("-..-.\n");
dash(); dot(); dot(); dash(); dot(); pa();
}
void Open(void){
printf("-.--.\n");
dash(); dot(); dash(); dash(); dot(); pa();
}
void Close(void){
printf("-.--.-\n");
dash(); dot(); dash(); dash(); dot(); dash(); pa();
}
void Ampersand(void){
printf(".-...\n");
dot(); dash(); dot(); dot(); dot(); pa();
}
void Colon(void){
printf("---...\n");
dash(); dash(); dash(); dot(); dot(); dot(); pa();
}
void Semicolon(void){
printf("-.-.-.\n");
dash(); dot(); dash(); dot(); dash(); dot(); pa();
}
void Equals(void){
printf("-...-\n");
dash(); dot(); dot(); dot(); dash(); pa();
}
void Plus(void){
printf(".-.-.\n");
dot(); dash(); dot(); dash(); dot(); pa();
}
void Minus(void){
printf("-....-\n");
dash(); dot(); dot(); dot(); dot(); dash(); pa();
}
void Underscore(void){
printf("..--.-\n");
dot(); dot(); dash(); dash(); dot(); dash(); pa();
}
void Quote(void){
printf(".-..-.\n");
dot(); dash(); dot(); dot(); dash(); dot(); pa();
}
void Dollar(void){
printf("...-..-\n");
dot(); dot(); dot(); dash(); dot(); dot(); dash(); pa();
}
void At(void){
printf(".--.-.\n");
dot(); dash(); dash(); dot(); dash(); dot(); pa();
}
void Space(void){
printf("\n\n\n");
endOf();
}
//sound the dot plus a pause
void dot(void){
printf(".");
PinPulse(5, tim);
printf("pause\n");
delay(tim);
}
//sound the dash and pause
void dash(void){
printf("-");
PinPulse(5, 3*tim);
printf("pause\n");
delay(tim);
}
//the pause at the end of a letter
void pa(void){
delay(2*tim);
}
//the pause at the end of a word
void endOf(void){
delay(tim*4);
}
//tried to clean up the parsing from the bad copy and paste.
Step 4: Execution:
SSH into the edison
type:
g++ -lmraa morse.c -o test
then:
chmod 777 test
then:
./test
You will get:
Hello World
enter the string :
Then enter a string such as hello world( takes most punctuation and caps):
Hello World
enter the string : hello
you entered hello
h
....
.pause
.pause
.pause
.pause
e
.
.pause
l
.-..
.pause
-pause
.pause
.pause
l
.-..
.pause
-pause
.pause
.pause
o
---
-pause
-pause
-pause
It shows you the letter and the pattern and shows what sound it is making. The buzzer is a bit loud but not unbearably so.