T
T
tkirsan4ik2018-08-12 22:25:07
Arduino
tkirsan4ik, 2018-08-12 22:25:07

How to connect USB joystick to arduino via USB-HOST on 376S chip?

Good afternoon, dear experts!
For the second day I have been struggling with the problem of connecting a USB joystick to arduino.
Components:
ARDUINO UNO on MEGA328P
USB-host on CH376S
Universal joystick (Defender, like this: defender.ru/catalog/139/1452 )
Port speed: 9600
Task: read button press codes from this joystick (or any other, only the axis is required learn and 4 main buttons). I found only one manual
for this usb-host . But this is a flash drive. I figured out how to work with her. The only question left is how to get data from the joystick. I'm a complete novice at this and don't even know where to start.
How can I find out the hex codes for initializing and working with the USB host (as in the functions in the flash drive example)? Is it even possible to implement my task on this usb-host? What tools to use and what to read (from the official description of the ch376s chip, I practically did not understand how that information can be applied to arduino)?
I already realized that the official USB-Host-Shield is very well suited for this (and a lot of already written code), but, unfortunately, I don’t have it.
I really look forward to your help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-08-12
@NeiroNx

The joystick is a USB-HID device. To work with it, you need to get its HID descriptor, but before that you need to interrogate it as a USB device and get its input and output nodes, then interrogate how the HID received the descriptor, build the packet format from the descriptor. Then process each sent packet from the desired node according to the specified format.
You need to understand how USB itself works at a low level and how HID works. I once watched how the joystick works on the Arduino Leonardo.
Roughly speaking, you need to tell the joystick that everything is OK and it can send data, and then parse this data.
Perhaps this will help you - here are prepared exchange and poll commands:
https://gist.github.com/project-pp/3307da0145d515c...

E
esaulenka, 2018-08-18
@esaulenka

It seems to me that this way to collect all possible rakes.
The documentation for CH376 does not look perfect, I did not find the second part of the PDF in English at all. You can try to rewrite the official example (see link above) in arduino style, but I'm afraid you'll have to do it yourself.
Required skills - knowledge of USB in Nutshell by heart. Additional hardware - a simple logic analyzer (to compare the premises of this product and a normal OS).
Option 2 - some kind of thicker controller with a USB host. There at least the documentation is more detailed and there are examples from the manufacturer "how to connect a USB mouse". Another question is that the USB host in the STM32 is highly original (and if their example does not take off, tinkering there for a long time ...). The USB host in the NXP LPC43xx is at least standard EHCI (but I have no idea where to get a debug board inexpensively).
Requirements for additional hardware and additional knowledge are not removed, but there are at least living people who work for this.
Option 3. Throw it all away, buy the cheapest raspberry and enjoy life. The USB stack has been written there for a long time and is well written. Additional knowledge - the ability to write a script like "interrogate /dev/something, jump /dev/bulb".
SYNC'i, ACK'i, PID'y from the low level of USB cease to be at night.
Option X. I don't know what a playstation is, but your joystick has some kind of interface for it. Fans connect it to LPT (there was such a thing in the 20th century). 100% problem for arduino, if I'm not confused.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question