<-

Morse Code Interpreter Circuit Project

For this project, we used the microcontrollers on our pre-built circuits to create some kind of input-output relationship and genera function. I chose to do a morse code interpreter using a button and an OLED screen, because that requires minimal additional wiring and would provide and interesting and entertaining result.

This project provided me many points of difficult and new challenge throughout. I have never been particularly proficient with electronics and soldering, so this was a great way for me to practice. The finished product works exactly as expected, though, which I am very happy about. Overall, this project was a great success.

Showcase

Fixing Board

The first step was to fix my circuit so that it would run properly. I sat down for multiple hours testing each pad with a multimeter to make sure nothing would short. However, I discovered that basically the entire thing was connected due to my shoddy soldering job. Also, in an attempt to remove some excess solder I scraped off lots of the copper, breaking it beyond repair. So, I reprinted my entire board and resoldered the entire thing, using much less solder. Then, it worked without need for any additional testing, and my soldering job was much more high-level.

Screen

Getting the screen to function was incredibly difficult for me. The tutorials for getting the screen to work were all using different libraries, so I had to go through and try each of them to try and get it to turn on. I spent about four hours testing every pin on my microcontroller and every wire I was using to connect them to understand why it wasn't turning on. I soldered the wires to the board itself to make it easier, but still had no luck. When I woke up the next day, reconnected every wire once again, and tried a new library, it miraculously turned on successfully. I hypothesize that the problem was either an incorrect or incomplete connection I overlooked the previous day, or using the wrong library. Regardless, I then had a working screen!

Input

After I got the screen working, it was time to start programming the board's functionality. I decided to use the button that was already on my circuit for simplicity's sake. Using arduino's string manipulation functions turned out to be very ineffective, and created many problems with the board. Multiple times the port would literally disconnect while I was coding because it was crashing from the functions themselves, and I had to put it in bootloader mode to clear it. Eventually, I figured out a workaround and got it working. Just as I was about to upload the final version, however, the button on my circuit suddenly stopped working. My theory was that it'd shorted, so I had to come in the next day to put in the final touches.

Code

#define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 32 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); const int buttonPin = 3; void setup() { Serial.begin(9600); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever } // Clear the buffer display.clearDisplay(); display.setTextSize(1); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw white text display.setCursor(0, 0); // Start at top-left corner display.cp437(true); // Use full 256 char 'Code Page 437' font // Not all the characters will fit on the display. This is normal. // Library will draw what it can and the rest will be clipped. display.write("ready"); display.display(); } int button_state = 0, hold_length = 0, unhold_length = 0, press = 100; String current_string = "nat"; String total_string = ""; void loop(){ gatherButtonData(); convertToMorse(); } void gatherButtonData(){ int button_state = digitalRead(buttonPin); if(button_state == 1){ unhold_length = 0; hold_length+=1; delay(1); } else if(hold_length > 1){ press = hold_length; hold_length = 0; } else if (unhold_length > 1000 && unhold_length < 1002){ total_string += morseToLetter(current_string); current_string = ""; unhold_length += 1; writetoScreen(total_string); delay(1); } else if (unhold_length < 5000){ unhold_length += 1; delay(1); } else{ total_string = ""; display.clearDisplay(); display.display(); } } void writetoScreen(String string){ int str_len = string.length() + 1; char char_array[str_len]; string.toCharArray(char_array, str_len); display.clearDisplay(); display.display(); display.setCursor(0, 0); display.write(char_array); display.display(); } void convertToMorse(){ if(press > 0){ if(press < 200){ current_string += "."; } else{ current_string += "-"; } writetoScreen(total_string + current_string); press = 0; } } char morseToLetter(String string){ if (string == ".") { return 'e'; } else if (string == "-") { return 't'; } else if (string == "..") { return 'i'; } else if (string == "--") { return 'm'; } else if (string == ".-") { return 'a'; } else if (string == "-.") { return 'n'; } else if (string == "...") { return 's'; } else if (string == "---") { return 'o'; } else if (string == "..-") { return 'u'; } else if (string == ".--") { return 'w'; } else if (string == "-..") { return 'd'; } else if (string == "-.-") { return 'k'; } else if (string == ".-.") { return 'r'; } else if (string == "--.") { return 'g'; } else if (string == "....") { return 'h'; } else if (string == "...-") { return 'v'; } else if (string == "..-.") { return 'f'; } else if (string == ".-..") { return 'l'; } else if (string == ".--.") { return 'p'; } else if (string == ".---") { return 'j'; } else if (string == "-...") { return 'b'; } else if (string == "-..-") { return 'x'; } else if (string == "-.-.") { return 'c'; } else if (string == "-.--") { return 'y'; } else if (string == "--..") { return 'z'; } else if (string == "--.-") { return 'q'; } return '?'; }

Datasheet Analysis: ATTINY45 vs ATTINY412

The attiny45 and attiny412 are similar chips with a few key difference. The 45 represents an older, simpler, cheaper model, using an EEPROM (outdated Electrically Erasable Programmable ROM) system. 412 uses an Event System and supports UDPI makin git a more versatile model. Overall, 45 is more suited for smaller projects while the 412 has a greater features and storage for larger-scale projects.