12. Embedded Networking and Communications¶
My Board¶
I used the same board seen in Weeks 9, 10, and 11.
Each of the five switches was connected to GPIO pins 26, 27, 28, 29, and 6, and I enabled internal pull-up resistors in the code. The buttons were wired to short the pin to ground when pressed. This made the setup very clean, and I didn’t need to add any external resistors.
I also added LEDs (wired to pins D6, D5, D9, D8, and D7) to give visual feedback when each switch is pressed. This helped during debugging and added a simple user interface.
Coding¶
At first, I tried using the Adafruit_TinyUSB
library to define a custom gamepad report. Although the serial monitor worked and button state changes were detected, no game controller was recognized by websites like hardwaretester.com/gamepad.
Even after some troubleshooting and switching libraries, I was not able to get my RP2040 with the websites. I’m not too worried as it still worked perfectly with Joy.cpl; and I’m pretty sure I can solve this by using a different micro controller.
Final Code¶
Here is the final working sketch with serial monitoring:
#include <Joystick.h>
// Define your switch pins
int switchPins[5] = {26, 27, 28, 29, 6};
void setup() {
Serial.begin(115200);
while (!Serial); // Wait for serial monitor
for (int i = 0; i < 5; i++) {
pinMode(switchPins[i], INPUT_PULLUP);
}
Joystick.begin(); // Start HID gamepad
}
void loop() {
for (int i = 0; i < 5; i++) {
bool pressed = digitalRead(switchPins[i]) == LOW;
Joystick.setButton(i, pressed);
if (pressed) {
Serial.print("Switch ");
Serial.print(i + 1);
Serial.println(" is ON");
}
}
delay(10);
}
This code continuously monitors the state of the five buttons and sends button states to both the computer (as HID gamepad buttons) and the serial monitor.
Reflection¶
This week was one of the most technically intense so far, but also very rewarding. I learned the difference between multiple USB HID libraries and how they integrate with different Arduino cores. Debugging HID functionality was tough, especially when the serial monitor worked but HID didn’t. I learned to:
- Properly configure the USB HID device for the RP2040 using the Philhower core.
- Read and interpret serial data to confirm button states.
- Recognize when HID descriptors might be the issue and pivot to more compatible libraries.
- Use Joy.cpl and gamepad testing websites to validate HID behavior.
While I originally struggled with the Adafruit TinyUSB configuration, I now understand how to use the built-in gamepad emulation more reliably. I also appreciated the power of internal pullups for simplifying button wiring.
Group Assignment¶
Member | Role |
---|---|
Kathryn, Amalia, Andrew | Documentation |
Kathryn and Amalia | Breadboard and coding |
Andrew Puky | PCB and Soldering |
Useful Links¶
Software Used¶
- Arduino IDE
- Joy.cpl (Windows Game Controller Panel)
People Who Helped Me¶
- Mr. Dubick
- ChatGPT (for troubleshooting and code reviews)