Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 16 of 16

Thread: Newbie on PlatformIO with Teensy

  1. #1

    Newbie on PlatformIO with Teensy

    Hi,

    I'm trying to make the joystick with the many axis joystick to work on platfromio but for some reason i cant understand why i get the error "error: 'Joystick' was not declared in this scope"

    So i have 2 options:

    1. Go back to arduino and make 2 joysticks instances (sounds clumsy)
    2. Go to the Arduino IDE to work with the Teensy..

    Neither option is appealing, so i would appreciate any help on understanding the problem.

    Thank you

  2. #2
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    160
    Your need to define the build_flags option in platformio.ini
    As described at https://docs.platformio.org/en/lates...ms/teensy.html

    Example of platformio.ini contents with joystick option:
    Code:
    [env:teensy_hid_device]
    platform = teensy
    framework = arduino
    board = teensy36
    build_flags = -D USB_FLIGHTSIM_JOYSTICK

  3. #3
    Member
    Join Date
    Aug 2018
    Location
    Brisbane, Australia
    Posts
    33

  4. #4
    Quote Originally Posted by manicksan View Post
    Your need to define the build_flags option in platformio.ini
    As described at https://docs.platformio.org/en/lates...ms/teensy.html

    Example of platformio.ini contents with joystick option:
    Code:
    [env:teensy_hid_device]
    platform = teensy
    framework = arduino
    board = teensy36
    build_flags = -D USB_FLIGHTSIM_JOYSTICK
    Thank you Very much for the answer.
    I now release i haven't describe what i tried to do to make it work yesterday before i posted here. (it was really late at night)
    I added the "core" libraries via lib_deps and also included the USB_Joystick.h in the program But that didn't help.
    Then i tried adding the build flag (as you suggested) -D USB_EVERYTHING. But it just made more error when compiling.

    What is the difference between FLIGHTSIM_JOYSTICK and EVERYTHING?

    Can You explain me the build flags purpose?
    Thanks.

  5. #5
    Quote Originally Posted by thebigg View Post

    Hi,

    Thanks for answering. I did found that page (before posting here) but i'm not a programmer so it wasn't making any sense to me...

    If you can give an explanation on the build flags (like i asked from manicksan) it would be highly appreciated.

    Thanks.

  6. #6
    Hi,


    I've tried with suggested flags and here is the outcome:
    (a lot of errors)
    one more thing, I've also copied the many axis joystick desc.h/.c to the core location.

    Do i also need to install the teensyduino? (it seems not, but i dont know...)

    Code:
    Compiling .pio\build\teensy35\FrameworkArduino\usb_keyboard.c.o
    C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_desc_old.c:594:0: warning: "CONFIG_DESC_SIZE" redefined
     #define CONFIG_DESC_SIZE  MULTITOUCH_INTERFACE_DESC_POS+MULTITOUCH_INTERFACE_DESC_SIZE
     ^
    In file included from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_desc_old.c:34:0:
    C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_desc.h:188:0: note: this is the location of the previous definition
       #define CONFIG_DESC_SIZE (9+8 + 9+5+5+4+5+7+9+7+7 + 9+9+7 + 9+9+7 + 9+9+7)
     ^
    In file included from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_dev.h:35:0,
                     from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_audio.cpp:32:
    C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_desc.h:304:3: error: conflicting declaration 'typedef struct usb_descriptor_list_t usb_descriptor_list_t'
     } usb_descriptor_list_t;
       ^
    In file included from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3/usb_serial.h:34:0,
                     from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3/WProgram.h:54,
                     from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3/Arduino.h:6,
                     from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_audio.cpp:31:
    C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3/usb_desc.h:304:3: note: previous declaration as 'typedef struct usb_descriptor_list_t usb_descriptor_list_t'
     } usb_descriptor_list_t;
       ^
    *** [.pio\build\teensy35\FrameworkArduino\usb_audio.cpp.o] Error 1
    C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_joystick.c: In function 'usb_joystick_send':
    C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_joystick.c:78:36: error: 'TX_TIMEOUT' undeclared (first use in this function)
                     if (++wait_count > TX_TIMEOUT || transmit_previous_timeout) {
                                        ^
    C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_joystick.c:78:36: note: each undeclared identifier is reported only once for each function it appears in
    *** [.pio\build\teensy35\FrameworkArduino\usb_joystick.c.o] Error 1
    In file included from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_inst.cpp:32:0:
    C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_desc.h:304:3: error: conflicting declaration 'typedef struct usb_descriptor_list_t usb_descriptor_list_t'
     } usb_descriptor_list_t;
       ^
    In file included from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3/usb_serial.h:34:0,
                     from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3/WProgram.h:54,
                     from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3/Arduino.h:6,
                     from C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3\usb_inst.cpp:31:
    C:\Users\gilie\.platformio\packages\framework-arduinoteensy\cores\teensy3/usb_desc.h:304:3: note: previous declaration as 'typedef struct usb_descriptor_list_t usb_descriptor_list_t'
     } usb_descriptor_list_t;
       ^
    *** [.pio\build\teensy35\FrameworkArduino\usb_inst.cpp.o] Error 1
    ==================================================================================================== [FAILED] Took 3.60 seconds ====================================================================================================
    The terminal process "C:\Users\gilie\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.
    
    Terminal will be reused by tasks, press any key to close it.

  7. #7
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    160
    Which "USB Type" setting are you using in Arduino IDE?

  8. #8
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    160
    when I look at the boards file of Arduino IDE in the hardware\teensy\avr folder there are the following options:

    Code:
    Build-flag             Description (as in Arduino IDE)
    ----------------------------------------------------
    USB_SERIAL               Serial           
    USB_DUAL_SERIAL          Dual Serial   
    USB_TRIPLE_SERIAL        Triple Serial  
    USB_KEYBOARDONLY         Keyboard
    USB_TOUCHSCREEN          Keyboard + Touch Screen
    USB_HID_TOUCHSCREEN      Keyboard + Mouse + Touch Screen
    USB_HID                  Keyboard + Mouse + Joystick
    USB_SERIAL_HID           Serial + Keyboard + Mouse + Joystick
    USB_MIDI                 MIDI
    USB_MIDI4                MIDIx4
    USB_MIDI16               MIDIx16
    USB_MIDI_SERIAL          Serial + MIDI
    USB_MIDI4_SERIAL         Serial + MIDIx4
    USB_MIDI16_SERIAL        Serial + MIDIx16
    USB_AUDIO                Audio
    USB_MIDI_AUDIO_SERIAL    Serial + MIDI + Audio
    USB_MIDI16_AUDIO_SERIAL  Serial + MIDIx16 + Audio
    USB_MTPDISK              MTP Disk (Experimental)
    USB_RAWHID               Raw HID
    USB_FLIGHTSIM            Flight Sim Controls
    USB_FLIGHTSIM_JOYSTICK   Flight Sim Controls + Joystick
    USB_EVERYTHING           All of the Above (only available @ teensy 3.1 3.5 3.6)
    USB_DISABLED             No USB
    the build flags at https://docs.platformio.org/en/lates...ms/teensy.html
    should have the descriptions to clarify what the different options are
    which are not so obvious.
    When I looked at it before I didn't know
    that USB_HID and USB_SERIAL_HID did include Joystick as well.

    Edit. Added USB_EVERYTHING which is according to the boards file only available on teensy 3.1 3.5 3.6
    Last edited by manicksan; 11-02-2020 at 07:31 PM. Reason: Added USB_EVERYTHING

  9. #9
    That's awesome!
    I didn't know you can do that? i'll need to look for myself.

    I did the Serial+Keyboard+Mouse+Joystick, but i guess just the Keyboard+mouse+Joystick (USB_HID) would suffice.

    I kept reading the many axis joystick and saw that i dont need to replace the files any more, just edit them... so maybe that is also the problem because on the arduino and compiled without a problem, and only when i replaced the files (the old one paul recommended) problems started...

    I'll try restore the original files, and do the USB_HID/USB_HID_SERIAL. And yes - they should the description to clarify it...

    I'll report back.

    Thank you for the detailed answer @manicksan.
    I really appreciate it.

    P.S.

    Where did you find the description in the avr folder? i didn't see anything on the .txt files

  10. #10
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    160
    It looks like this in the boards.txt i have separated the two options

    Code:
    teensy41.menu.usb.hid=Keyboard + Mouse + Joystick      <- this is the description (the option that the user see in the IDE)
    teensy41.menu.usb.hid.build.usbtype=USB_HID
    teensy41.menu.usb.hid.fake_serial=teensy_gateway
    
    teensy41.menu.usb.serialhid=Serial + Keyboard + Mouse + Joystick
    teensy41.menu.usb.serialhid.build.usbtype=USB_SERIAL_HID
    this is from the teensy41 part
    if you scroll down there are also for the other teensies

  11. #11
    I understood how to change the joystick.
    But it still doesn't work... for some reason after changing the JOYSTICK SIZE from 12 to 64, I cant get it to compile for some reason...
    It says that
    Code:
    Complete:41: error: 'class usb_joystick_class' has no member named 'sliderLeft'
       Joystick.sliderLeft(analogRead(4));

  12. #12
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    160
    if you look at usb_joystick.h https://github.com/PaulStoffregen/co...usb_joystick.h
    line 124 #elif JOYSTICK_SIZE == 64 <- here begins the code for when JOYSTICK_SIZE == 64
    and at
    line 139
    Code:
    void slider(unsigned int num, unsigned int position) {
    you can see that the slider function takes two parameters

    and according to line 140 the number can be 0 - 17
    position is the analog value 0-1023 (values over 1023 is clipped to 1023) line 180

  13. #13
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    160
    I forgot to read your post completely
    when
    #elif JOYSTICK_SIZE == 64 line 124 to line 169
    there is no function sliderLeft

  14. #14
    Thanks a lot! for the explanation.
    Makes sense...

    I actually got over this problem by going back to PlatfromIO.

    However,

    Even though i've defined the JOYSTICK_SIZE == 64, it still shows me only the regular joystick. I changed the vendor id and the prduct id in usb_dec.h

    Code:
    #elif defined(USB_SERIAL_HID)
      #define VENDOR_ID		0x15A1 //0x16C0
      #define PRODUCT_ID		0x0427 //0x0487
      #define DEVICE_CLASS		0xEF //0xEF
      #define DEVICE_SUBCLASS	0x02
      #define DEVICE_PROTOCOL	0x01
    I cant get that to work....

    Do you have any advice?

    P.S.

    How do you update the slider if the function is available?
    Last edited by giliep; 11-02-2020 at 09:43 PM. Reason: editing

  15. #15
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    160
    Have you tried with the original vendor id and product id

    In PlatformIO only:
    Also make sure that you clean the build. The clean button (Recycle Bin icon) is to the right of the upload button.
    Because changing definitions don't always recompile correctly.

    If you read https://forum.pjrc.com/threads/23681-Many-axis-joystick
    maybe you can find something there, Paul had it working in Linux with 128 buttons, 6 axes, 17 sliders, and 4 hat switches.

    otherwise I don't have any clue
    USB HID game controllers is not really my expertise.

  16. #16
    Yea, The original ID's are not doing anything.

    I'll try the clean option. Thanks.

    I'm going over it through and through...
    but no Luck yet

    Thanks for the help so far!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •