MHeironimus / ArduinoJoystickLibrary

An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
GNU Lesser General Public License v3.0
2.06k stars 403 forks source link

Serial Port and Joystick library on Leonardo #235

Closed AdriGuillaume closed 2 years ago

AdriGuillaume commented 2 years ago

Hello,

I would like to use temporaly Serial port for monitoring my Leonardo before initiliazing the joystick class in Setup(). but it seems that Serial.begin() disable definitly joystick HID for the rest of my program even if i use Serial.end() at the end of my instruction.

someone can help me ?

Thanks a lot ! Adrien

fbrinker commented 2 years ago

It seems to work for me. I use the Serial monitoring for debugging purposes.

My setup looks like the following:

void setup()
{
   Serial.begin(115200);
//...
  Joystick.begin(false);
//...

And the loop:

void loop()
{
  Serial.println("Hello");
//...
  Joystick.sendState();

Note that I don't use the auto-sending of Joystick states. But I guess that shouldn't be the problem. But you may want to give it a try.

Also note that you may want to use a delay() with Serial.prints, so you don't spam over the port.

GO63-samara commented 2 years ago

You can also do this:

You need to use Serial1 instead of Serial. Then debug will go through the TX and RX pins and through the USB-UART module. HID will work independently.

You can put in the first line: #define Serial Serial1

MHeironimus commented 2 years ago

Question appears to be answered above.