7

Suppose we have a computer mouse , now when we connect it to a computer then computer understands it is a mouse which is been connected to it. Same thing happens for keyboard and many other devices. As per my understanding, the mouse has a microcontroller and a TTL serial converter which is programmed a certain way that enable computer's default mouse driver to understand the instructions coming from the connected device.

Let me to talk about one of my projects where I build a device driver for my own device. Like arduino send serial instructions to a port say COM3 and the driver which is a java program reads those instructions and performs accordingly.

As we all know that the arduino library provides support for Mouse and keyboard which works fine. Mouse operations are performed without a custom driver.

Now what I want is when arduino connects to a computer it gets detected as a Joystick or as a pendrive or something like that.

I go through different header files of mouse and keyboard which are present in arduino library but those are very complex and without proper documentation hard to understand.

Can you tell me where I could find study materiel regarding the existing library? Arduino website provides documentations only on different methods not on how it works.

Or if I think of building my own library then how I should start?

One more thing where I can find the information regarding the protocols that a conventional device like mouse, keyboard, pendrive, CD-ROM follows during communication (like the code or the algorithm that is burn into the microcontroller of the device) ?

I know it is a out of the box question but still if you help me, I will be grateful to you.

  • Try Google - look for something like Arduino zero HID - I know I have seen people do such things. (HID is Human Input Device) – SDsolar Jun 17 '17 at 15:19
  • 1
    Yes, I know there are several headers including HID for usb interfacing in library but without proper documents difficult to understand. But still I will give a try. If you have any useful links regarding this please mention those in comment – Siddhartha Sadhukhan Jun 17 '17 at 15:25
2

As per my understanding, the mouse has a microcontroller and a TTL serial converter which is programmed a certain way that enable computer's default mouse driver to understand the instructions coming from the connected device.

No, the mouse's microcontroller is a USB device.

Like arduino send serial instructions to a port say COM3 and the driver which is a java program reads those instructions and performs accordingly.

No, that is the application you are talking about. The driver is what you install in Windows to make COM3 appear (that is, in any version of Windows before windows 10. Every other operating system, and Windows 10, has the driver built in already).

Now what I want is when arduino connects to a computer it gets detected as a Joystick or as a pendrive or something like that.

There is no support for that in the Arduino API.

I go through different header files of mouse and keyboard which are present in arduino library but those are very complex and without proper documentation hard to understand.

Even with proper documentation and understanding of how USB works it's hard to understand.

Can you tell me where I could find study materiel regarding the existing library? Arduino website provides documentations only on different methods not on how it works.

Or if I think of building my own library then how I should start?

Don't. Trying to do what you want without an in-depth understanding of how USB works is nigh on impossible. I understand how USB works and struggle with writing USB driver code for microcontrollers.

Instead invest in a device that already does what you want (such as a Teensy 3.x), or move away from Arduino and use a professional environment with professional tools and examples to work with.

One more thing where I can find the information regarding the protocols that a conventional device like mouse, keyboard, pendrive, CD-ROM follows during communication (like the code or the algorithm that is burn into the microcontroller of the device) ?

From the USB Implementer's Forum Inc.

Mouse or pendrive have a special type of microcontroller which are capable of direct communication to pc ? if so then is their any programmable microcontroller in market?

Yes, and there are plenty. Any of the Arduino boards based around the ATMega32U4 (such as the Leonardo) are that kind of microcontroller. The "serial" interface chip on the Uno is that kind of microcontroller (it is capable of being reprogrammed so it looks like a completely different device, and if you google around you will find people that have done it).

What is the difference between actual driver and my java program which reads COM port?

The driver is what makes the COM port. Your program is what uses the COM port.

[USB device]---->[USB)- Driver -(COM3]<-----[Your program]
  • Thank you for your valuable advice. Couple of more thing to clarify... – Siddhartha Sadhukhan Jun 16 '17 at 20:32
  • 1) Mouse or pendrive have a special type of microcontroller which are capable of direct communication to pc ? if so then is their any programmable microcontroller in market? 2) What is the difference between actual driver and my java program which reads COM port? – Siddhartha Sadhukhan Jun 16 '17 at 20:39
  • See my edits... – Majenko Jun 16 '17 at 20:42
  • you talked about teensy. just guide me whether I am going in right the direction or not. In teensy there is one method namely USB: Raw HID, now if I know how mouse does request and respond and code the teensy as per the mouse communication protocol then I am done – Siddhartha Sadhukhan Jun 16 '17 at 20:57
  • Raw HID is the basis of the mouse protocol. Over that is laid a "HID Report" that describes the data. The same thing is done for both keyboard and joystick as well. Teensyduino (the Teensy 3.x API) has Mouse, Keyboard, Joystick, etc objects to use: pjrc.com/teensy/td_mouse.html – Majenko Jun 16 '17 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.