Create a PC version of a RP4 PCB project

I designed a simple PCB in kicad for the Raspberry Pi, it’s a 5 key micropad connected to 5 data GPIO pins, plus a ground and a 3.3v pin for pull up.
For it I wrote a python script that listens these keys for clicks events and sends a different udp command to another software on Raspberry Pi OS. I sent it to PCBway, got it on the mail, tested it and it worked!, this is the first electronic thingy I’ve ever built so I’m super stoked.

Now I want to do a little upgrade to the PCB, I want it to also work on windows vía USB, so switch the current pins header for a micro-usb or type-c connector?
I also want to put the script inside the board, so maybe add a microcontroller with a couple of KB of memory or write a driver?
If I want the PCB to be recognized by window, linux, etc I guess I need to use a usb library or learn about HID and the USB protocol?
I have no idea what I’m getting into, I’m in the dark, but I have the time and thirst to learn so if you could point me to resources, videos, courses or any advices I’d appreciate it a lot

I never did anything like this, but I guess the easiest route is to use an MCU that has USB support. Implementing it by yourself is a pain in the ass. There are many microcontrollers out there that support what you want to do.

As Mineotopia says, it’s easier to start with a MCU that has USB support already. You can probably just buy a cheap dev module with that MCU and not have to pay more and spend time to make your own MCU board and develop software for it.

Have a look at one such project on Github.

Another place to look would be hackaday.io for MCU projects dealing wtih GPIO and USB.

Thus, this is not KiCad related, especially if you can just buy a MCU module cheaper off the shelf, and so is out of scope for this forum.

USB is a quite complicated protocol, it has a gazillion built in features and all these features add complexity to it.
If you want to have fun with low-level USB, you can use:

And they also have a HID device example.

This is a firmware stack. the uC has no hardware USB on board. This was an amazing project when it was first developed, but in these modern times there are plenty of uC’s with built in hardware USB. Doing USB in software has very serious consequences for your software. For example, the USB has to service the USB port every milli second, so all user code must be divided into small sections. On the other hand of the equation, using V-USB can still be relevant for learning how USB works. Because you see everything in front of you in (mostly) C code, it’s easy to study and follow code execution paths. When using hardware USB, you have long datasheets, long USB specifications, USB hardware in an uC that does it’s own magic and trying to fit all those together can be very difficult.

If you just want to get this project “done”, then simply copying one of the many HID examples is probably the best start. After you have verified the example works, you can modify it to add your own code. Don’t look too much at the price. It probably does not matter much whether a chip costs 30ct or EUR10. My own preference is always to start with a development board that fits on a breadboard. I have some "Black Pills (STM32F411) and STM32G431 breakout boards, both from WeAct (and cost < EUR10). STM32 are quite complex uC’s and that does make them less suitable for beginners. I also have a few Teensy 4.1 boards (These cost around EUR30). Also quite complex, just as STM32, but apparently PJRC has made good libraries and examples made available. Another option is ATMEGA32U4 It is used on some of the arduino boards and also has USB. I don’t know if USB is available on the arduino boards though. arduino does weird things with their software stack. USB may be reserved for firmware uploading exclusively for example.

Programming microcontrollers is a wonderful endeavor.You also almost can’t get around it if you want to do anything with building electronics. A lot of the uC manufacturers have uC’s with built in USB hardware so that does not narrow your options down much. I think it’s best to pick some microcontroller family and then stick with that family to get to know how it works quite well. After you know one uC family quite well, you can broaden your knowledge by trying out some other uC family.

RP2040 may be a good starting point. It’s quite popular as it’s from the Raspberry corporation. I have not used it myself, but because of it’s popularity there is probably plenty of examples and help available. Having a community around an uC so you can ask questions is also quite important. With the cheap chinese STM32 clones this can be more difficult. They do have various small differences and incompatibilities, and that is not nice for beginners.

This topic was automatically closed after 18 hours. New replies are no longer allowed.