Hello! I am very new to Arduino programming and I need to interface a Logitech 3D Pro Extreme Controller with an Arduino UNO board for a project. I was able to connect them both via a USB host shield and I found this preliminary sketch on Github that will interface the controller data with the Arduino.
/*
* Simplified Logitech Extreme 3D Pro Joystick Report Parser, ready to go.
*/
#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>
#include "le3dp_rptparser2.0.h"
#include <SPI.h>
USB Usb;
USBHub Hub(&Usb);
HIDUniversal Hid(&Usb);
JoystickEvents JoyEvents;
JoystickReportParser Joy(&JoyEvents);
void setup() {
Serial.begin(115200);
#if !defined(__MIPSEL__)
while (!Serial)
; // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay(200);
if (!Hid.SetReportParser(0, &Joy))
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1);
}
void loop() {
//
int Xval; // 0 - 1023
int Yval; // 0 - 1023
int Hat; // 0 - 15;
int Twist; // 0 - 255
int Slider; // 0 - 255
int Button; // 0 - 12 (0 = No button)
Usb.Task(); //Use to read joystick input to controller
JoyEvents.PrintValues(); //Returns joystick values to user
JoyEvents.GetValues(Xval, Yval, Hat, Twist, Slider, Button); //Copies joystick values to user
C:\Users\bgibs\AppData\Local\Temp\ccZP60DD.ltrans0.ltrans.o:(.data+0x0): undefined reference to `vtable for JoystickEvents'
C:\Users\bgibs\AppData\Local\Temp\ccZP60DD.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_ControllerParsing.ino.cpp.o.11860':
<artificial>:(.text.startup+0x2c4): undefined reference to `JoystickReportParser::JoystickReportParser(JoystickEvents*)'
C:\Users\bgibs\AppData\Local\Temp\ccZP60DD.ltrans0.ltrans.o: In function `loop':
C:\Users\bgibs\OneDrive\Documents\Arduino\Drone Project Code\ControllerParsing/ControllerParsing.ino:48: undefined reference to `JoystickEvents::PrintValues()'
C:\Users\bgibs\OneDrive\Documents\Arduino\Drone Project Code\ControllerParsing/ControllerParsing.ino:49: undefined reference to `JoystickEvents::GetValues(int&, int&, int&, int&, int&, int&)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
Ok, here is the code and error messages with code tags.
After adding the .cpp file to the sketch, I was able to upload the sketch. I have come across another problem though: when I go to the serial monitor and try to move around the joystick, the printed values are registering, but they stay at 0. Is this something that could be fixed with the code, or would it be more of a hardware issue? (I have the UNO connected to the computer and the controller connected to the host shield, with the host shield connected on top of the UNO)
Thank you for your help thus far! Also, I am sorry you had to hunt for that library. I would have given it to you if I knew it would help solve the problem. I assumed that the base code needed to be altered in some way to make it work.
I can't help with the new problem as I don't have the set up.
And don't worry too much about the libraries; it was for future. You just would have had my reply 10 minutes earlier if you would have provided the information
Your error indirectly indicated that you were probably missing a file.