Hello, I have been building my own DDR dance mat to accompany Outfox running on my Raspberry Pi 4 (along with all of the other games and systems I am running with retropie). To accomplish this, I am using an Arduino Micro with the ATmega32u4 and a simple circuit with pull-up resistors. No matter the libraries I use, and no matter how well the system works on my Windows machine, all of the inputs into the Raspberry Pi are random.
I have tried setting up the Arduino as a keyboard, as well as a HID controller. The pi recognized the Arduino as a HID controller properly, and I am writing 4 buttons on the Arduino and there are only 4 buttons changing on the pi. However, when doing jstest the 4 buttons just randomly turn on and off (and the same deal when the Arduino is set to be a keyboard). It works perfectly when plugged into my windows laptop, but on the pi it freaks out.
I have tried plugging the Arduino into a powered USB bus, a USB 3.0 port, and a USB 2.0 port. I have looked everywhere for anyone having a similar problem, but I can't find anything online. Because of the powered USB port, I don't think it's related to power-drawing issues from the raspberry pi, as that was the most likely cause of weirdness like this. I know that linux (in this case Debian) handles keyboard and other usb inputs differently than Windows, but I am not sure how that would cause random inputs to be constantly streaming into the pi. I have also tried newer and older usb cables to connect to the Arduino to no avail. Do any of you know about an issue like this, or anything that I can try? I'm at somewhat of a dead end from things I can figure out myself.
Please read and use How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum
Interesting question but hard to follow. Lets start with an annotated schematic as to how you are connecting all of this . Post links to technical information on the hardware devices. Show values of external components and any level translators you are using.
Sorry for the lack of useful information. Thanks for pointing me towards what I should be providing:
Here's a quickly drawn schematic of what's going on (pretend like it's an Arduino micro, they didn't have one in the software I was using):
Here's a pastebin to the code written for the Arduino: DanceMat Code - Pastebin.com
It's a very simple code that watches for the pins to get pulled high, and writes a button press with some level of debouncing (the buttons I am using are the pads on the dancemat so there is quite a bit of bouncing when pressed).
I want to reiterate that on Windows, this code and my wiring works PERFECTLY. It never miss-inputs, it always triggers when I expect it to, etc. I have also tried using Keyboard.h, and that also works on my windows machine perfectly, but no matter what on my raspberry pi I just get all of the buttons pressing randomly.
Specifically, I am getting the buttons I have programmed pressing randomly. In this code, buttons 1,5,7, and 3 are coded, and only those buttons are going haywire when plugged into the raspberry pi 4. The same is true when I write code that was meant to press up/down/left/right on the keyboard. Only those were being pushed, so the communication protocol over usb is transmitting the button codes properly.
It is important to note that the buttons are self-made, and they are two metal bars (~1in wide, and ~3 in long and ~.25 in apart, and there are 4 switches in parallel per pin) that are separated by foam, and when the pad is pressed, the metal bars touch to complete the circuit. So hypothetically I could see those buttons working as a weak capacitor, so if there is a difference in how a raspberry pi (or my powered usb hub) would power the +5v pin from how a Windows laptop would drive it, I could see current getting through the pads when they are not pressed.
Hope that explains things better, I am not the best communicator when writing out issues I'm dealing with.
an alternative approach maybe to plug the arduino into a RPi USB port where it would create a serial device, e.g. /dev/ttyUSB0
the arduino outputs commands to Serial when are received by the RPi via /dev/ttyUSB0 and forwarded to Outfox
I believe I tried this approach, but the details are escaping me, so sorry about that. I have successfully downloaded and installed the Arduino IDE in hopes that the drivers necessary to view the arduino would be installed too. I will need to check to see if the IDE recognizes the arduino as a serial device or not, but in the case that it does, would I simply write different keys to the serial port, and then read that in Outfox as each button press?
A follow up question to that: If the arduino is on a COM port, wouldn't I need to run some sort of application to start reading it as a serial device? I can handle scripting something, but are there tools for doing that from the command line on linux?
Heh, I just started a similar process for the same reason. I have a few of the Impact wireless dance pads but no drivers or receiver, so I'm ripping out the guts and using a micro as well.
I have a simple sketch that reads the pads as button presses and sends keyboard presses. It all works well on my MacOS machine, but as soon as I plug the micro in to the Pi (Pi5 for me), it acts like it's completely frozen. dmesg
shows the arduino being recognized with the HID Keyboard, but my activity LED doesn't activate and the TX light doesn't activate. Only way it works is if I power it separately, plug the micro in to my macOS machine first, then change it over to the pi. It seems like something in the handshaking goes wrong with the pi.
Also, as a side-note, you probably don't need to use separate resistors if you initiate the pins with INPUT_PULLUP
instead of INPUT
. It handles the pull-up resistors internally. Note: it will swap open and closed in doing so.
Interesting to hear that you are having similar problems, but that does give me more confidence that it is something that the Pi is messing up, as you said about the handshake possibly being messed up.
As an update to this thread, I have not found a solution but decided to try on a whim a Raspberry Pi pico to see if that helped anything. The answer was no. I do not know the details, but for the drivers on the pico all I need to do is short the pin to ground and it successfully detects that. It once again works great on my windows machine but will input random presses when plugged into the pi. What really bothers me though is there is still only the four programmed buttons actually being pressed (up, down, left right), so the USB protocol is being respected. It's almost as if somehow in the code the detection pins are being read when they're not supposed to only when plugged into the pi.
I've switched to a nano esp32 and made sure it's in debug hardware mode. That seemed to make things work for me. The downside is i have to manually put the board in to DFU mode and upload sketches that way (bit of a hassle when things are in a case).
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.