Before I take on the project of taking the user input, of course, I had to learn few things first. I started off with tackling adding an LCD.
I have a bad habit of not following tutorials on the web typically because I usually have my own twist to the problem that makes it complicated. However, I found one that helped immensely.
Here’s how the pins were mapped:
LCD Pin | Connected to |
1 (VSS) | Ground (GRD) (Note the bridge. The actual connection’s behind the LCD panel) |
2 (VDD) | +5v Arduino Pin |
3 (Contrast) | Resistor to GRD (Note Arduino GRD is connected by a small green wire. It’s also connected to the other side of the breadboard by the GRD bridge) |
4 (RS) | Arduino Pin 2 |
5 (RW) | Arduino Pin 3 |
6 (Enable) | Arduino Pin 4 |
7, 8, 9, 10 | No Connection |
11 (D4) | Arduino Pin 6 (5 was skipped as I my leads in the wire didn’t have enough space) |
12 (D5) | Arduino Pin 7 |
13 (D6) | Arduino Pin 8 |
14 (D7) | Arduino Pin 9 |
15 Backlight Power (+) | Arduino Pin 10 |
16 Backlight GRD | Ground (GRD) |
11 is my control pin for the Morse Messenger.
- #include <LiquidCrystal.h>
- // A dot is a '1', A dash '0' -1 is a filler / compensator for the absence of jagged arrays
- int letterMorse[][4] = {
- {1, 0, -1, -1},
- {0, 1, 1, 1},
- {0, 1, 0, 1},
- {0, 1, 1, -1},
- {1, -1, -1, -1},
- {1, 1, 0, 1},
- {0, 0, 1, -1},
- {1, 1, 1, 1},
- {1, 1, -1, -1},
- {1, 0, 0, 0},
- {0, 1, 0, -1},
- {1, 0, 1, 1},
- {0, 0, -1, -1},
- {0, 1, -1, -1},
- {0, 0, 0, -1},
- {1, 0, 0, 1},
- {0, 0, 1, 0},
- {1, 0, 1, -1},
- {1, 1, 1, -1},
- {0, -1, -1, -1},
- {1, 1, 0, -1},
- {1, 1, 1, 0},
- {1, 0, 0, -1},
- {0, 1, 1, 0},
- {0, 1, 0, 0},
- {0, 0, 1, 1}
- };
- int numberMorse[][5] = {
- { 0, 0, 0, 0, 0 },
- { 1, 0, 0, 0, 0 },
- { 1, 1, 0, 0, 0 },
- { 1, 1, 1, 0, 0 },
- { 1, 1, 1, 1, 0 },
- { 1, 1, 1, 1, 1 },
- { 0, 1, 1, 1, 1 },
- { 0, 0, 1, 1, 1 },
- { 0, 0, 0, 1, 1 },
- { 0, 0, 0, 0, 1 }
- };
- //// A dot is a '1', A dash '0'
- //int symbolMorse[][6] = {
- // {0, -1, 0, -1, 0, -1},
- // {0, }
- //}
- int controlPin = 11;
- const int standardPauseInMilliseconds = 500;
- LiquidCrystal lcd(2, 3, 4, 6, 7, 8, 9);
- int backlight = 10;
- void setup() {
- pinMode(backlight, OUTPUT);
- digitalWrite(backlight, HIGH);
- lcd.begin(16, 2);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.display();
- // put your setup code here, to run once:
- doMorse("I LOVE ARDUINO");
- }
- void loop() {
- }
- void doMorse(String message)
- {
- // put your main code here, to run repeatedly:
- for (int i = 0; i < message.length(); i++)
- {
- char letter = message.charAt(i);
- lcd.print(letter);
- Serial.println(letter);
- if (letter == ' ')
- {
- //Words are separated by a space equal to 7 dots
- delay(standardPauseInMilliseconds * 7);
- continue;
- }
- int *component = lookupComponents(letter);
- for (int j = 0; j < 4; j++)
- {
- int number = component[j];
- if (number < 0) continue;
- bool isDot = (number);
- Serial.print(isDot ? "Dot- " : "Dash- ");
- //For the duration of a dash (0) is 3 times the duration of a dot (1)
- blink(isDot ? standardPauseInMilliseconds : standardPauseInMilliseconds * 3);
- beep(isDot ? standardPauseInMilliseconds : standardPauseInMilliseconds * 3);
- //Each dot / dash is followed by a short silence, equal to the dot duration
- delay(standardPauseInMilliseconds);
- }
- Serial.println(' ');
- //The space between letters is three units
- delay(standardPauseInMilliseconds * 3);
- }
- }
- void blink(int delayInMilliseconds)
- {
- pinMode(controlPin, OUTPUT);
- //Turn on the light
- digitalWrite(controlPin, HIGH);
- //For the duration of a dash (0) is 3 times the duration of a dot (1)
- delay(delayInMilliseconds);
- digitalWrite(controlPin, LOW);
- }
- void beep(int delayInMilliseconds)
- {
- pinMode(controlPin, OUTPUT);
- analogWrite(controlPin, 20);
- delay(delayInMilliseconds);
- analogWrite(controlPin, 0);
- }
- int * lookupComponents(char letter)
- {
- int value = ((int)letter) - 65;
- bool isNumber = value < 0;
- Serial.println(value);
- //lcd.print(value);
- return isNumber ? numberMorse[value] : letterMorse[value];
- }
![]() | ![]() |
The issues I had faced were actually numerous. Didn’t get the backlight to light up for a long time. I found pins 12 & 13 wouldn’t work as control pins. Why? They simply ignored analogWrite(). The piezo wouldn’t beep.
The biggest issue I faced was to ensure my programming is matching with the wiring. This was especially complicated by the pin 12 & 13 refusing to work as control pins.
I still don’t understand many things (such as if the resistors were meant to use up energy so component upstream would receive less electricity why would it need to be connected to GRD & not power? I found the 7 segment display brighten up considerably when I attached the ground directly than through the resistor).
5 comments:
The biggest issue I faced was to ensure my programming is matching with the wiring. This was especially complicated by the pin 12 & 13 refusing to work as control pins lcd touch display.
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
LCD (liquid crystal display) is the technology used for displays in notebook and other smaller computers. .The active matrix LCD is also known as a thin film transistor (TFT) display. https://www.stoneitech.com
The article you have shared here is very informative and the points you have mentioned are very helpful. I really appreciate your work which you have shared here. Thank you so much. Outdoor Led Screen.
Well done! I thank you your input to this matter. It has been useful. my blog: how to make a girl like you led futófény
Post a Comment