Morsecode GPT to Allows the Audience to Interact With an AI Program Using Morse Code to Communicate.
by rabbit maker in Circuits > Arduino
44 Views, 1 Favorites, 0 Comments
Morsecode GPT to Allows the Audience to Interact With an AI Program Using Morse Code to Communicate.
I explain "Morsecode GPT" work which allows the audience to interact with an AI program using Morse code to communicate for exhibiting in Orlando Maker Faire 2024.
I liked the idea of wireless communication like Morse code in the movie. I originally wanted to exhibit this idea at there. Since LLM (Large Language Model) is widely open source, I thought I could use it to create a production that looks like people are communicating. I'm sharing the development code here.
I made two program modules using Arduino and Python. I explain about them like below (I will take the time to update the content further).
Before following this, you should install ollama, Llama2, Arduino IDE, Python.
Make Arduino Code: Morse Code Input, Encoding and Communication With Python Program
1. Initialization (setup phase)
• The Arduino initializes the LCD screen and sets up pins for the Morse code button, new text button, and the buzzer.
A welcome message, "Hi. Morse world!" is displayed on the LCD for 3 seconds.
2. Reading Button States (loop phase)
• The main loop() function continuously reads the state of the Morse code button (button_morse) and the new text button (button_new_text).
• If button_morse is pressed, the buzzer emits a tone, simulating the pressing of the Morse key.
• The duration the button is pressed (time_pressed_button) is measured to differentiate between dots (short press) and dashes (long press).
3. Morse Code Conversion
• Once the button is released, the recorded time_pressed_button value determines if it represents a dot (short press) or a dash (long press).
• These Morse symbols are appended to morse_code.
• If there is a pause between button presses (detected via time_not_push_button), the current Morse code is converted to a text character using complate_morse_code() and added to morse_text.
4. Displaying and Resetting
• If the button_new_text is pressed, the current morse_text is sent to the serial monitor for further processing and the code resets (morse_code and morse_text are cleared).
• The LCD screen displays the current Morse code sequence and the resulting text.
Downloads
Python Code: Real-Time Morse Code to LLM Communication
1. Initialize and Setup:
• Initialize pygame for creating a graphical display window.
• Set up the display window size, title, and text fonts.
• Define colors for text rendering.
2. Serial Port Configuration:
• Find available COM ports and open one for serial communication at 9600 baud rate.
• Raise an exception if no COM port is found.
3. Language Model Integration:
• Set up a language model chain using langchain, Ollama, and a joke prompt template.
4. Main Program Loop:
• Enter the main loop, which runs until the user quits.
• Check for user events like window closure.
• Read Morse code data from the serial port.
• If data is received, store it in morse_string.
5. Processing and Display:
• Pass morse_string to the language model to get a response (a joke).
• Clear the display window and render the Morse message.
• Render the generated joke, line by line, on the screen.
• Refresh the display with pygame.display.flip().
6. Loop Control and Exit:
• Add a short delay (time.sleep(0.1)) to control loop speed.
• Repeat the loop to check for new serial data and user events.
• Exit the loop when the user closes the window.
7. Cleanup:
• Close the serial port connection.
• Clean up and close the pygame window with pygame.quit().
P.S. Actually, my grandfather suddenly passed away, so I had to inform this situation to 2024 Orlando Maker faire's staff and go back home. My grandfather loved me, and I had fond memories of going out with him a lot when I was young. For this reason, I shared my work here with regret.