I would like to build a steering wheel for my PC. I have bought an Arduino Leonardo for this purpose, as it can output as an HID. Now I am faced with the problem that I have too few analog ports. I need: one for the steering wheel itself, 3 for the pedals, and another 2 - 4 for one or two joysticks. I still have an Arduino Mega lying around and have heard that you can program it so that the Mega sends its inputs to the leonardo, which then processes them. The only problem I have now is that it only talks about the digital inputs, but not the analog ones. Is it possible to do the same with the analog inputs, or will it not work?
(The pedals and the steering wheel use just potentiometers).
If you have any further questions, please write to me.
The solution with the MEGA could work, you send over a Serial (for example) communication the information from the sensors (analog and digital values) packed into a payload following some sort of protocol you define.
The Leonardo receives and decodes the payload and transforms the information into HID commands.
I would suggest to study Serial Input Basics to handle the Serial communication part.
That was my intention. But when I send for an example two values then the leonardo doesnt know for wich input pin they are. So the Mega must send always all values, not only the ones that are changed right? And then at the leonardo I must make the program, that the leo always takes as an example the first value for pin A0 and so on. Or am I making things too complicated?
(If my english is bad, sorry I'm not a native speaker)
The protocol could take care of that like sending the text <A0=227,A1=457,D3=H> if only A0 and A1 have changed and D3 went to HIGH
or you could indeed pack everything together and send the whole information and let the Leonardo detect what has changed from the previous message
PS:
Budget is indeed a constraint like others . It comes with programming constraints and possible technical difficulties (having a robust communication link between two MCUs is more complicated than dealing with only one MCU)
Does it make a noticeable difference in speed if I only send the changed values or all the values? Because if i have to make an if query for every pin (to look if it has changed) (I also want to add some pushbuttons later) then the code will be really long I think.
Also I saw in a Video, that you can send integers. But does it send the whole integer (with name) or only the value of the integer?
reading the pins is super fast (like you could do that a few thousand times per second)
sending the data over the serial line depends on the baud rate and the size of the payload
if both arduino are close to each other and you can use a hardware serial link, you could use 500,000 bauds or more for the UART - that's about 50,000 bytes per second.
even if you encode everything in ASCII rather than have a binary protocol (more compact) and send every thing the payload would be may be (say) 250 bytes long, so you could still update everything at 200Hz... (200x per second) which is likely too often for your steering wheel and human reaction time when pressing buttons...
➜ the question is what update rate do you need to have ?