Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to create a programmable Keyboard with an Arduino. It was actually pretty easy, just using the keyboard library, printing a character when a button is pressed: no problems. I also created an application on the PC to communicate over the serial port with the Arduino, I can send a new configuration and tell the Arduino which character I want when button 1 is pressed: a bit more complicated but still ok.

My problem: I do not want the communication between Arduino and PC to be over serial port.
- serial port number changes sometimes
- another application can "steal" the port and kill the communication
- it is not crypted

What are my options to communicate between Arduino/Microcontroller and PC?

What I have tried:

I looked into HID and CDC protocol, I use HID report so that my Arduino is recognized as a keyboard by the PC. I think CDC is actually currently used for the serial communication of the Arduino.

A perfect solution would be a CDC class which allows me to communicate like a regular serial port, but would somehow be "hidden". I would be able to find the USB device with PID and VID.
Posted
Updated 28-Sep-17 21:18pm

1 solution

Quote:
- serial port number changes sometimes
That might happen when plugging the USB-to-Serial converter into a different connector. But it should not happen when not unplugging the converter.

Quote:
- another application can "steal" the port and kill the communication
COM ports are exclusive resources. That applies to virtual ports too. That means once an application has opened it, it can't be opened anymore by another application (or even the same application). So the communication can't be killed by another application. However, another application may open the port before yours.

Quote:
- it is not crypted
That is not related to the physical interface and low level communication protocol. If necessary, you can use some kind of encryption for data transfers.

Quote:
What are my options to communicate between Arduino/Microcontroller and PC?
There are many depending on the kind of interfaces available or installable. For low speed you can even use SPI and I2C.

I assume that you have an USB-to-Serial converter at the PC side. If that has an FTDI chip, you can use the D2XX Direct Drivers[^] (with other chips there may be similar drivers). Using that you can access the converter by VID and PID instead of the virtual COM port and avoid the problem of changing COM ports. You can even uninstall or disable the virtual COM port driver so that other applications would have to use the same method to access the converter.
 
Share this answer
 
Comments
CPallini 29-Sep-17 3:50am    
5.
Member 12254962 29-Sep-17 15:19pm    
Hi Jochen, thank you for your detailed answer! I want my device to be as plug and play as it gets so deinstalling/deactivating drivers is not an option but the idea with FTDI driver and access the device by VID and PID sounds great. I do not have a FTDI chip since I am working with Arduino Leonardo but I am pretty sure LibUsb/LibUsbDotnet (https://github.com/libusb/libusb, http://libusbdotnet.sourceforge.net/V2/Index.html) can do the same so I will try this. Do you know if there is the possibility to implement a CDC class on the microcontroller so that it will NOT be recognized as a (virtual) COM port by the computer but somehow still be reachable with LibUsb? I am not afraid to go deep in USB protocol for it but I do not want to write a driver ^^
Jochen Arndt 30-Sep-17 5:23am    
So you are connecting the Arduino USB port with your PC (why this did not came to my mind).

As far as I know, the Arduino (at least the original one) uses an FTDI chip. Then you should be able to use the D2XX driver. That is the good news.

The bad news is that the FTDI chip is an USB-to-Serial converter which is controlled via the USB side but the Arduino is connected to the serial side. So you can not create some kind if CDC class on the Arduino.

I suggest to try the D2XX driver creating a test application. If that works it should be possible to write a keyboard device driver that uses the D2XX library for communication. But that is an advanced task (I'm not very familiar with Windows device drivers). Then you would create an INF file for your driver similar to those of the virtual COM port driver but specify it as keyboard driver. That is: Your driver replaces the COM port driver.

LibUSB is very powerful but I have used it only with Linux so far. But using the D2XX library here would be simpler.

If you got all this to work it would make a fine article here at CodeProject.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900