From charlesreid1

Line 56: Line 56:


===The Breadboard Photo===
===The Breadboard Photo===
Here's a photo of the final breadboard:
[[Image:Photo_CodeGenerator.jpg|500px]]


===The Sketch Code===
===The Sketch Code===

Revision as of 04:28, 20 July 2015

Overview

Here's a block diagram of what this circuit will look like. The Arduino sends voltages through its output pins to control an I2C LCD screen (see , where it prints the letters that it has sent and its current words per minute (WPM) sending speed, and a piezoelectric speaker, which will generate the morse code output:

Diagram MorseCodeGenerator.png

Eventually this will also include an input potentiometer, but for now we're building this to send at a fixed WPM speed.

Let's review each part of this circuit.

The Arduino Pseudocode

The pseudocode running on the Arudino will be picking letters at random, sending them to the speaker, then updating the display with the letter. The pseudocode for the Arduino sketch, then, will look something like this:

Include libraries
Set pins

Setup:
    Set CW speed
    Set fixed messages

Loop:
    Read speed potentiometer (if applicable)
    Set CW speed (if applicable)

    Randomly select character
    Send character to morse code speaker
    Update display message

The Speaker Sub-Circuit

This one's pretty easy - we just hook up one of our pulse width modulation (PWM) output pins to the speaker, so that we can send modulated morse code tones to the speaker. See the Morse Code Beep Arduino Micro article for more on that circuit.

The Display Sub-Circuit

For the LCD display, I will be using a 4-pin, 5-volt Sainsmart LCD display. Here are photos of the front and back:

Front Back
Sainsmart front.jpg Sainsmart back.jpg

I already covered a basic Hello World example with this LCD display in the Arduino LCD Display article, so head over there to check it out. Controlling this display will require an additional two voltage pins. We've still got plenty of room left to expand this project with more pins!


First Pass

The Circuit

The Breadboard Diagram

The Breadboard Photo

Here's a photo of the final breadboard:

Photo CodeGenerator.jpg

The Sketch Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x3F  // Define I2C Address where the PCF8574A is
// Address can be changed by soldering A0, A1, or A2
// Default is 0x27

// map the pin configuration of LCD backpack for the LiquidCristal class
#define BACKLIGHT_PIN 3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

LiquidCrystal_I2C lcd(I2C_ADDR,
                      En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin,
                      BACKLIGHT_PIN, POSITIVE);

#include <Morse.h>

#define MORSE_PIN 9
#define MORSE_WPM 20

Morse morse(MORSE_PIN, MORSE_WPM, 1);

void setup()
{
  lcd.begin(20, 4);       // 20 columns by 4 rows on display

  lcd.setBacklight(HIGH); // Turn on backlight, LOW for off

  lcd.setCursor ( 0, 0 );            // go to the top left corner
  lcd.print("  charlesreid1.com  "); // write this string on the top row
  lcd.setCursor ( 0, 1 );            // go to the 2nd row
  lcd.print("     FB FB 73  "); // pad string with spaces for centering
  lcd.setCursor ( 0, 2 );            // go to the third row
  lcd.print("     DE KC7DBU  "); // pad with spaces for centering
  lcd.setCursor ( 0, 3 );            // go to the fourth row
  lcd.print("XT: ");
}

void loop()
{
  delay(5000);
  
  char msg[] = "V V V";
  
  lcd.setCursor(8,3);
  lcd.print(msg);

  morse.sendmsg(msg);
  
  lcd.setCursor(8,3);
  lcd.print("     ");

  delay(5000);
}