Joystick Library conflicts (perhaps) with serial connection through Processing

I've encountered a peculiar issue using the Joystick library and using the Serial port for transmitting 'commands' from the computer to the Arduino. In this case a Pro Micro.

I wanted to create an interface for adjusting settings on my Pro Micro board. I've used Processing and ControlP5 to build the interface and use 'command' strings that are send through the serial port to the Pro Micro. These commands are read and parsed by the Pro Micro to adjust a few variables, depending on the command name.

I've tested everything on my Mac using the very useful site html5gamepad.com, which displays button presses and axis etc. It worked fine on my Mac. But, when testing it out on PC, the buttons are properly working, but the axis aren't being updated. This is also true when I try to use the axis in game. They aren't being registered.

Could anybody hint me as to why this only works on Mac? Or why this is expected to be buggy?

You can find my project at:
https://github.com/mohragk/Shifter_Handbrake_DIY/tree/master/New_Handbrake_update

Please post your Arduino program here.

...R

Here is my Arduino sketch!

New_Handbrake_update.ino (5.21 KB)

..and my full project because of dependancies.

New_Handbrake_update.zip (11.2 KB)

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

However, for the moment anyway, if the Arduino program works when the MAC sends data it is unlikely that the use of the String class is preventing it from working with the PC.

Perhaps the MAC and the PC are applying different line-endings when they send a message?

You don't seem to have any code to print the full message that is received before any attempt is made to parse it?

If this was my project I would have the PC (and MAC) send messages like <S,134> and <Z,23> and <T,109>. Sending "SKEW" does not provide any more information than sending 'S'

...R

No, that's not the issue. The commands are sent correctly, both on Mac and PC.

The problem I'm having is that the X-axis of the Joystick does not get updated on PC, only on MAC... Which I find very strange.

Now, I haven't hooked up a potentiometer on pin A0, so it's still floating. But this is useful for testing because the X-axis get's updated 'automatically'.
In the meantime I'll add another test, a sine sweep to update the X-axis. See if that produces anything.

mohragk:
No, that's not the issue. The commands are sent correctly, both on Mac and PC.

The problem I'm having is that the X-axis of the Joystick does not get updated on PC, only on MAC...

Maybe I have misunderstood.

Do you mean that the Arduino is receiving data correctly from your Mac and your Windows PC but the Arduino is not sending data correctly to the PC?

...R

Robin2:
Maybe I have misunderstood.

Do you mean that the Arduino is receiving data correctly from your Mac and your Windows PC but the Arduino is not sending data correctly to the PC?

...R

I guess it was just a bug on the site html5gamepad.com which doesn't update the X-axis correctly.... I've run a test with what is basically a sine sweep that sets the X-axis. It does register in the properties pane in Windows and in game, so it works!

I've also converted my command system to use cstrings instead of the String class. Thank you for that recommendation :wink: