Objective
The goal for week three is to gain and understanding of embedded programming by using simulations for working with microcontrollers. I’ll primarily be using WokWi.
Choosing a Microcontroller
As a group assignment, we all analyzed a variety of embedded architectures and the workflows around them to help determine the best microcontrollers for each of our respective uses. For my final project, I’m now leaning towards creating a blackberry-styled case for an Apple Wtch with a Bluetooth QUERTY keyboard. So when looking at microcontroller options, I was prioritizing:
- small form factor
- Bluetooth capable
- low power requirements
This led me to the ESP32-C3 microcontroller and the Nordic nRF5840. Both are available in a XAIO form factor, which streamlines the programming workflow. Between the two, the nRF5840 is roughly double the price and reportedly more difficult to program. For that reason, I am leaning towards using the ESP32. It also doesn’t hurt that ESP32s are available to simulate in WokWi!
WokWi Simulation
I started on WokWi by choosing the ESP32-C3 setup. I played around a little with connecting a button and a light to make sure I could reproduce some of the basic setups we saw in class, and then decided to simulate something more applicable to my final project. I hooked up a keypad to the microcontroller, using the closest General Purpose Input/Output pins to create a streamlined look. I then setup a script that broke the keys down into rows and columns, and assigned each row and column to a GPIO. Finally, I set up a script to recognize the output. It mostly worked the first time through, but the keys were reversed left-to-right; if I pressed ‘1’, the output was ‘A’, and vice versa. I decided to try remedying this a few ways.
Reversed L/R
First, I changed the layout of my rows and columns and reversed them:
{‘1’, ‘2’, ‘3’, ‘A’} > {‘A’, ‘3’, ‘2’, ‘1’}
{‘4’, ‘5’, ‘6’, ‘B’} > {‘B’, ‘6’, ‘5’, ‘4’}
{‘7’, ‘8’, ‘9’, ‘C’} > {‘C’, ‘9’, ‘8’, ‘7’}
{’’, ‘0’, ‘#’, ‘D’} > {‘D’, ‘#’, ‘0’, ‘’}
Flipped Keypad in Code: Success!
This worked, but in hindsight seemed silly. I changed the layout of the rows and columns back to normal, and then instead quickly reversed the pins I assigned to each row and column…
Extra Silly: Flipped All Pins in Code
…which in hindsight was also silly, because only the columns were backwards, not the rows. Finally I set things to normal, and also converted the project to micropython to get practice in that instead of C++.
At this point I achieved the basic functionality I was after. I decided to take things a step further to see if I could simulate a Bluetooth connection and have my inputs type onto a screen.
Sadly, this was unsuccesful; when I try to initialize Bluetooth in the ESP32-C3, I get a server build error from WokWi (not in the code output). From talking with classmates, this is a limitation of WokWi and not a code issue. If You would like to examine my attempts, however, you can see them here: https://wokwi.com/dashboard/projects
© 2024 Nathan Keene Wiegand