With the world in lockdown, you’d think there’s plenty of time for hobbies. Somehow, it’s been 4 months since my last post – time flies in a crisis! I’ll admit that I’ve been somewhat lax in working on the CPC2, but with the project so close to completion, I need to re-commit to finishing this 5-year project! Today’s post is about my CPC Bluetooth joystick!
I bought one of these cheap Atari 2600 DB9 joysticks on eBay for about $10. There’s very little to these, so the case is nice and big and the internals are nice and simple. I opened up the case and removed the wire and DB9 connector, then removed the internal plastic structures around the cable exit, although not particularly neatly as you can see from the photograph below. This left plenty of space for an ESP32 Feather and a LI-PO battery that would take the simple digital output from the switching board and provide a Bluetooth-LE service supplying the state of the buttons. The inside of the modified joystick can be seen below:
Yes, it’s messy, but it will never be opened up again and it works. The LI-PO battery is directly connected to the Feather board as I didn’t want to cut the LI-PO wires to add a switch. The power regulator has a convenient power-off facility that reduces the current draw to microamps when connecting an enable pin to ground, so the blue switch on the top side controls this pin.
Recharge power is provided by a barrel jack socket on the bottom and connected to the USB power in pin on the board. Connecting this to 5V will recharge the battery, regardless of the enable pin. The blue backlight of the switch is connected to IO13 of the feather as that also is connected to the on-board LED. This allows me to light up the LED when the power is enabled, but also do things like flash the LED when the battery is low.
The other connections you see in the image above are to the five controller pad switches for the joystick; up, down, left, right and fire. As each one is pressed, it is connected to the common line. Using ESP32 software-enabled pull-ups on the input lines, I can simply connect the common pin to ground and look for input-low on each of the ESP32 control pins.
The firmware for the ESP32 turned out to be fairly simple. The sample programs that come with the ESP32 development framework have a Bluetooth-LE service that I simply tailored to suit my application. Here’s how it looks in Bluetooth LE Explorer:
With Bluetooth LE, it’s possible to ‘subscribe’ to events called notifications, which is perfect for this application as the CPC2 will not need to poll the joystick for its status. As the button state changes, the framework will publish the new button state and the CPC2 will convert this into a correct input state for the joystick scanning.
I also added battery level monitoring so that the CPC knows when the battery is about to run out and warn the user.
The CPC2 will be the client for this joystick service, and so I’m hoping that the example LE-client in the ESP32 framework will work with just a little tweaking. I’ll be adding this in at a later date. If there’s any interest, I can share the ESP32 code. Let me know in the comments.
For now, this project was just the kick start I needed to reinvigorate my enthusiasm and commitment to the CPC2 project. I’ll be working on the CPC2 sound quality issues for the rest of today and I need to finish the new revision of the CPC2 board, without the build issues I experienced in the last iteration.
Let’s get this project DONE!
Previous Post <====> Next Post