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

Thread: Using Teensy bootloader w/ VS Code (Version Control)

  1. #1
    Junior Member
    Join Date
    Mar 2020
    Posts
    15

    Using Teensy bootloader w/ VS Code (Version Control)

    Hi all,

    I am trying to get some version control and a somewhat better IDE set up for my Teensy programming and am having a hard time getting going. I usually like to use git for version control w/ VS code. I've installed the Arduino extension for VS code but I don't know exactly how to upload code to Teensy. Could anybody share their workflow with developing for Teensy? Alternatively, is it possible to get Teensy working with VS Code?

    Thanks!

  2. #2
    Senior Member
    Join Date
    Feb 2020
    Posts
    137
    Check out visualteensy.

    https://github.com/luni64/VisualTeensy

  3. #3
    Junior Member
    Join Date
    Mar 2020
    Posts
    15
    Quote Originally Posted by TeensyWolf View Post
    Thanks so much for the help. I installed VisualTeensy and now I am able to load the simple "Blink" example to my Teensy 4.0.

    However, when I attempt to make the program I have been developing for a while now, I am getting a long list of errors that I had not experience when using the Arduino IDE. I've dumped the entire terminal output below. Does any of this make sense to people?

    Code:
    CORE [ASM] memset.S 
    CORE [ASM] memcpy-armv7m.S 
    CORE [CC]  sm_util.c 
    CORE [CC]  sm_calloc.c 
    CORE [CC]  sm_free.c 
    CORE [CC]  clockspeed.c 
    CORE [CC]  usb_keyboard.c 
    CORE [CC]  usb_serial.c 
    CORE [CC]  usb_seremu.c 
    CORE [CC]  sm_malloc.c 
    CORE [CC]  usb.c 
    CORE [CC]  usb_joystick.c 
    CORE [CC]  delay.c 
    CORE [CC]  analog.c 
    CORE [CC]  sm_zalloc.c 
    CORE [CC]  sm_szalloc.c 
    CORE [CC]  interrupt.c 
    CORE [CC]  sm_alloc_valid.c 
    CORE [CC]  usb_serial3.c 
    CORE [CC]  rtc.c 
    CORE [CC]  fuse.c 
    CORE [CC]  startup.c 
    CORE [CC]  debugprintf.c 
    CORE [CC]  eeprom.c 
    CORE [CC]  sm_hash.c 
    CORE [CC]  extmem.c 
    CORE [CC]  sm_realloc_move.c 
    CORE [CC]  nonstd.c 
    CORE [CC]  sm_pool.c 
    CORE [CC]  usb_rawhid.c 
    CORE [CC]  usb_touch.c 
    CORE [CC]  bootdata.c 
    CORE [CC]  tempmon.c 
    CORE [CC]  digital.c 
    CORE [CC]  sm_realloc_i.c 
    CORE [CC]  sm_realloc.c 
    CORE [CC]  usb_midi.c 
    CORE [CC]  keylayouts.c 
    CORE [CC]  pwm.c 
    CORE [CC]  usb_serial2.c 
    CORE [CC]  sm_malloc_stats.c 
    CORE [CC]  usb_mtp.c 
    CORE [CC]  usb_desc.c 
    CORE [CC]  usb_mouse.c 
    CORE [CPP] IntervalTimer.cpp 
    CORE [CPP] HardwareSerial6.cpp 
    CORE [CPP] DMAChannel.cpp 
    CORE [CPP] yield.cpp 
    CORE [CPP] IPAddress.cpp 
    CORE [CPP] HardwareSerial3.cpp 
    CORE [CPP] serialEvent4.cpp 
    CORE [CPP] HardwareSerial7.cpp 
    CORE [CPP] EventResponder.cpp 
    CORE [CPP] usb_inst.cpp 
    CORE [CPP] HardwareSerial5.cpp 
    CORE [CPP] Time.cpp 
    CORE [CPP] serialEventUSB2.cpp 
    CORE [CPP] CrashReport.cpp 
    CORE [CPP] serialEvent5.cpp 
    CORE [CPP] usb_flightsim.cpp 
    CORE [CPP] serialEvent8.cpp 
    CORE [CPP] serialEvent3.cpp 
    CORE [CPP] HardwareSerial2.cpp 
    CORE [CPP] Tone.cpp 
    CORE [CPP] WMath.cpp 
    CORE [CPP] HardwareSerial4.cpp 
    CORE [CPP] main.cpp 
    CORE [CPP] WString.cpp 
    CORE [CPP] serialEventUSB1.cpp 
    CORE [CPP] HardwareSerial1.cpp 
    CORE [CPP] AudioStream.cpp 
    CORE [CPP] serialEvent7.cpp 
    CORE [CPP] serialEvent.cpp 
    CORE [CPP] new.cpp 
    CORE [CPP] serialEvent2.cpp 
    CORE [CPP] usb_audio.cpp 
    CORE [CPP] Stream.cpp 
    CORE [CPP] serialEvent1.cpp 
    CORE [CPP] Print.cpp 
    CORE [CPP] serialEvent6.cpp 
    CORE [CPP] HardwareSerial8.cpp 
    CORE [CPP] HardwareSerial.cpp 
    LIB [CPP] keyboardHIDExtras.cpp 
    LIB [CPP] hub.cpp 
    LIB [CPP] memory.cpp 
    LIB [CPP] digitizer.cpp 
    LIB [CPP] enumeration.cpp 
    LIB [CPP] rawhid.cpp 
    LIB [CPP] joystick.cpp 
    LIB [CPP] Print.cpp 
    LIB [CPP] adk.cpp 
    LIB [CPP] bluetooth.cpp 
    LIB [CPP] antplus.cpp 
    LIB [CPP] SerEMU.cpp 
    LIB [CPP] hid.cpp 
    LIB [CPP] MassStorageDriver.cpp 
    LIB [CPP] midi.cpp 
    LIB [CPP] mouse.cpp 
    CORE [AR] .vsteensy/build/core.a 
    Teensy core built successfully
    
    LIB [CPP] serial.cpp 
    LIB [CPP] ehci.cpp 
    USER [CPP] main.cpp 
    In file included from src/main.cpp:15:0:
    lib/USBHost_t36/USBHost_t36.h:382:55: error: 'DEC' was not declared in this scope
      static void print_(const char *s, int n, uint8_t b = DEC) {}
                                                           ^
    lib/USBHost_t36/USBHost_t36.h:383:64: error: 'DEC' was not declared in this scope
      static void print_(const char *s, unsigned int n, uint8_t b = DEC) {}
                                                                    ^
    lib/USBHost_t36/USBHost_t36.h:384:56: error: 'DEC' was not declared in this scope
      static void print_(const char *s, long n, uint8_t b = DEC) {}
                                                            ^
    lib/USBHost_t36/USBHost_t36.h:385:65: error: 'DEC' was not declared in this scope
      static void print_(const char *s, unsigned long n, uint8_t b = DEC) {}
                                                                     ^
    lib/USBHost_t36/USBHost_t36.h:386:57: error: 'DEC' was not declared in this scope
      static void println_(const char *s, int n, uint8_t b = DEC) {}
                                                             ^
    lib/USBHost_t36/USBHost_t36.h:387:66: error: 'DEC' was not declared in this scope
      static void println_(const char *s, unsigned int n, uint8_t b = DEC) {}
                                                                      ^
    lib/USBHost_t36/USBHost_t36.h:388:58: error: 'DEC' was not declared in this scope
      static void println_(const char *s, long n, uint8_t b = DEC) {}
                                                              ^
    lib/USBHost_t36/USBHost_t36.h:389:67: error: 'DEC' was not declared in this scope
      static void println_(const char *s, unsigned long n, uint8_t b = DEC) {}
                                                                       ^
    lib/USBHost_t36/USBHost_t36.h: In constructor 'USBDriver::USBDriver()':
    lib/USBHost_t36/USBHost_t36.h:434:21: error: 'NULL' was not declared in this scope
      USBDriver() : next(NULL), device(NULL) {}
                         ^
    In file included from src/main.cpp:15:0:
    lib/USBHost_t36/USBHost_t36.h: At global scope:
    lib/USBHost_t36/USBHost_t36.h:537:22: error: 'NULL' was not declared in this scope
      USBHIDInput *next = NULL;
                          ^
    lib/USBHost_t36/USBHost_t36.h:540:23: error: 'NULL' was not declared in this scope
      Device_t *mydevice = NULL;
                           ^
    lib/USBHost_t36/USBHost_t36.h:566:21: error: 'NULL' was not declared in this scope
      BTHIDInput *next = NULL;
                         ^
    lib/USBHost_t36/USBHost_t36.h:572:23: error: 'NULL' was not declared in this scope
      Device_t *btdevice = NULL;
                           ^
    lib/USBHost_t36/USBHost_t36.h:1410:54: error: expected class-name before '{' token
     class USBSerialBase: public USBDriver, public Stream {
                                                          ^
    lib/USBHost_t36/USBHost_t36.h:1437:10: error: 'size_t' does not name a type
      virtual size_t write(uint8_t c);
              ^
    lib/USBHost_t36/USBHost_t36.h:1442:8: error: 'Print' has not been declared
      using Print::write;
            ^
    lib/USBHost_t36/USBHost_t36.h:1580:2: error: 'size_t' does not name a type
      size_t write(const void *data, const size_t size);
      ^
    lib/USBHost_t36/USBHost_t36.h:1581:29: error: 'size_t' does not name a type
      int read(void *data, const size_t size);
                                 ^
    lib/USBHost_t36/USBHost_t36.h:1649:57: error: 'size_t' does not name a type
      static uint8_t * findStreamSync(uint8_t *stream, const size_t rlen, int *pos);
                                                             ^
    lib/USBHost_t36/USBHost_t36.h:1655:33: error: 'size_t' does not name a type
       const uint8_t *payload, const size_t dataLength);
                                     ^
    lib/USBHost_t36/USBHost_t36.h:1657:33: error: 'size_t' does not name a type
       const uint8_t *payload, const size_t dataLength);
                                     ^
    lib/USBHost_t36/USBHost_t36.h:1659:33: error: 'size_t' does not name a type
       const uint8_t *payload, const size_t dataLength);
                                     ^
    lib/USBHost_t36/USBHost_t36.h:1697:61: error: 'size_t' does not name a type
      void payload_HRM(TDCONFIG *cfg, const uint8_t *data, const size_t dataLength);
                                                                 ^
    lib/USBHost_t36/USBHost_t36.h:1707:64: error: 'size_t' does not name a type
      void payload_SPDCAD(TDCONFIG *cfg, const uint8_t *data, const size_t dataLength);
                                                                    ^
    lib/USBHost_t36/USBHost_t36.h:1721:63: error: 'size_t' does not name a type
      void payload_POWER(TDCONFIG *cfg, const uint8_t *data, const size_t dataLength);
                                                                   ^
    lib/USBHost_t36/USBHost_t36.h:1734:64: error: 'size_t' does not name a type
      void payload_STRIDE(TDCONFIG *cfg, const uint8_t *data, const size_t dataLength);
                                                                    ^
    lib/USBHost_t36/USBHost_t36.h:1742:63: error: 'size_t' does not name a type
      void payload_SPEED(TDCONFIG *cfg, const uint8_t *data, const size_t dataLength);
                                                                   ^
    lib/USBHost_t36/USBHost_t36.h:1749:65: error: 'size_t' does not name a type
      void payload_CADENCE(TDCONFIG *cfg, const uint8_t *data, const size_t dataLength);
                                                                     ^
    lib/USBHost_t36/USBHost_t36.h: In member function 'void AntPlus::onHeartRateMonitor(void (*)(int, int, int), uint32_t)':
    lib/USBHost_t36/USBHost_t36.h:1548:30: error: 'memset' was not declared in this scope
       memset(&hrm, 0, sizeof(hrm));
                                  ^
    lib/USBHost_t36/USBHost_t36.h: In member function 'void AntPlus::onSpeedCadence(void (*)(float, float, float), uint32_t)':
    lib/USBHost_t36/USBHost_t36.h:1553:36: error: 'memset' was not declared in this scope
       memset(&spdcad, 0, sizeof(spdcad));
                                        ^
    lib/USBHost_t36/USBHost_t36.h: In member function 'void AntPlus::onSpeed(void (*)(float, float), uint32_t)':
    lib/USBHost_t36/USBHost_t36.h:1558:30: error: 'memset' was not declared in this scope
       memset(&spd, 0, sizeof(spd));
                                  ^
    lib/USBHost_t36/USBHost_t36.h: In member function 'void AntPlus::onCadence(void (*)(float), uint32_t)':
    lib/USBHost_t36/USBHost_t36.h:1563:30: error: 'memset' was not declared in this scope
       memset(&cad, 0, sizeof(cad));
                                  ^
    lib/USBHost_t36/USBHost_t36.h: At global scope:
    lib/USBHost_t36/USBHost_t36.h:1786:56: error: expected class-name before '{' token
     class USBSerialEmu : public USBHIDInput, public Stream {
                                                            ^
    lib/USBHost_t36/USBHost_t36.h:1798:10: error: 'size_t' does not name a type
      virtual size_t write(uint8_t c);
              ^
    lib/USBHost_t36/USBHost_t36.h:1801:8: error: 'Print' has not been declared
      using Print::write;
            ^
    lib/USBHost_t36/USBHost_t36.h:2012:2: error: 'size_t' does not name a type
      size_t write(size_t len, uint8_t *buf);
      ^
    lib/USBHost_t36/USBHost_t36.h:2133:5: error: 'elapsedMillis' does not name a type
         elapsedMillis _emlastRead;
         ^
    lib/USBHost_t36/USBHost_t36.h: In member function 'bool msController::available()':
    lib/USBHost_t36/USBHost_t36.h:2067:28: error: 'delay' was not declared in this scope
      bool available() { delay(0); return deviceAvailable; }
                                ^
    src/main.cpp: In function 'void setup()':
    src/main.cpp:66:11: error: 'Serial' was not declared in this scope
       while (!Serial) ; // wait for Arduino Serial Monitor
               ^
    src/main.cpp:67:3: error: 'Serial' was not declared in this scope
       Serial.println("\n\nUSB Host Testing");
       ^
    src/main.cpp:68:34: error: 'DEC' was not declared in this scope
       Serial.println(sizeof(USBHub), DEC);
                                      ^
    src/main.cpp:74:21: error: 'OUTPUT' was not declared in this scope
       pinMode(ENABLE_1, OUTPUT);
                         ^
    src/main.cpp:74:27: error: 'pinMode' was not declared in this scope
       pinMode(ENABLE_1, OUTPUT);
                               ^
    src/main.cpp: In function 'void loop()':
    src/main.cpp:90:7: error: 'Serial' was not declared in this scope
       if (Serial.available()) {
           ^
    src/main.cpp:114:9: error: 'Serial' was not declared in this scope
             Serial.printf("*** Device %s - disconnected ***\n", driver_names[i]);
             ^
    src/main.cpp:117:9: error: 'Serial' was not declared in this scope
             Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
             ^
    src/main.cpp:133:9: error: 'Serial' was not declared in this scope
             Serial.printf("*** HID Device %s - disconnected ***\n", hid_driver_names[i]);
             ^
    src/main.cpp:136:9: error: 'Serial' was not declared in this scope
             Serial.printf("*** HID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
             ^
    src/main.cpp:172:68: error: 'abs' was not declared in this scope
                 motorSpeed[0][currentSegment] = 2*abs(143 - scaledValue); // motor speed scaled by offset from center
                                                                        ^
    src/main.cpp:172:68: note: suggested alternative:
    In file included from src/main.cpp:17:0:
    c:\progra~2\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\cmath:99:5: note:   'std::abs'
         abs(_Tp __x)
         ^
    src/main.cpp:200:21: error: 'delay' was not declared in this scope
                 delay(10);
                         ^
    src/main.cpp:205:53: error: 'analogWrite' was not declared in this scope
             analogWrite(motorPin[0][j], motorSpeed[0][j]);
                                                         ^
    src/main.cpp:206:54: error: 'digitalWrite' was not declared in this scope
             digitalWrite(motorPin[1][j], motorSpeed[1][j]);
                                                          ^
    src/main.cpp:207:9: error: 'Serial' was not declared in this scope
             Serial.printf("\nSeg%d LR:%d UD:%d ", j, motorSpeed[0][j], motorSpeed[1][j]);
             ^
    src/main.cpp:209:7: error: 'Serial' was not declared in this scope
           Serial.println();
           ^
    src/main.cpp:212:5: error: 'Serial' was not declared in this scope
         Serial.println();
         ^
    src/main.cpp:155:14: warning: unused variable 'buttons' [-Wunused-variable]
         uint32_t buttons = joystick1.getButtons();
                  ^
    src/main.cpp: In function 'void OnHIDExtrasRelease(uint32_t, uint16_t)':
    src/main.cpp:225:3: error: 'Serial' was not declared in this scope
       Serial.print("HID (");
       ^
    src/main.cpp:226:21: error: 'HEX' was not declared in this scope
       Serial.print(top, HEX);
                         ^
    make: *** [makefile:231: .vsteensy/build/src/main.cpp.o] Error 1
    make: *** Waiting for unfinished jobs....
    LIB [CPP] keyboard.cpp 
    The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command C:/Users/fh829e/Documents/VisualTeensy_v1.5.0/make.exe all -j -Otarget" terminated with exit code: 1.
    And the code I am running, using USBHost_t36.h:

    Code:
    #include "USBHost_t36.h"
    #include <iostream>     // std::cout
    #include <cmath>        // std::abs
    
    USBHost myusb;
    USBHIDParser hid1(myusb);
    JoystickController joystick1(myusb);
    
    // PIN DEFINITIONS
    #define PHASE_1   2  // DIGITAL
    #define ENABLE_1  3  // ANALOG
    #define PHASE_4   4  // DIGITAL
    #define ENABLE_4  5  // ANALOG
    #define PHASE_3   6  // DIGITAL
    #define ENABLE_3  7  // ANALOG
    #define ENABLE_5  18 // ANALOG
    #define ENABLE_2  19 // ANALOG
    #define PHASE_5   20 // DIGITAL
    #define PHASE_2   21 // DIGITAL
    #define CAN_TX    22 // CAN BUS TX
    #define CAN_RX    23 // CAN BUS RX
    
    // MISC
    #define BAUDRATE 9600
    
    int user_axis[64];
    uint32_t buttons_prev = 0;
    const uint8_t motorPin[2][5] = {{ENABLE_1,ENABLE_2,ENABLE_3,ENABLE_4,ENABLE_5},
                                    {PHASE_1 ,PHASE_2 ,PHASE_3 ,PHASE_4 ,PHASE_5 }};
    uint8_t motorSpeed[2][5] = {{0,0,0,0,0},{0,0,0,0,0}};
    uint8_t currentSegment = 0;
    int linkNumb = 0;
    
    USBDriver *drivers[] = {&joystick1, &hid1};
    #define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0]))
    const char * driver_names[CNT_DEVICES] = {"JOY1D", "HID1"};
    bool driver_active[CNT_DEVICES] = {false, false};
    
    // Lets also look at HID Input devices
    USBHIDInput *hiddrivers[] = {&joystick1};
    #define CNT_HIDDEVICES (sizeof(hiddrivers)/sizeof(hiddrivers[0]))
    const char * hid_driver_names[CNT_DEVICES] = {"Joystick1"};
    bool hid_driver_active[CNT_DEVICES] = {false};
    bool show_changed_only = false;
    
    uint8_t joystick_left_trigger_value = 0;
    uint8_t joystick_right_trigger_value = 0;
    uint64_t joystick_full_notify_mask = (uint64_t) - 1;
    
    void setup()
    {
      while (!Serial) ; // wait for Arduino Serial Monitor
      Serial.println("\n\nUSB Host Testing");
      Serial.println(sizeof(USBHub), DEC);
      myusb.begin();
    
      //=============================================================================
      // Set OUTPUT pins
      //=============================================================================
      pinMode(ENABLE_1, OUTPUT);
      pinMode(PHASE_1, OUTPUT);
      pinMode(ENABLE_2, OUTPUT);
      pinMode(PHASE_2, OUTPUT);
      pinMode(ENABLE_3, OUTPUT);
      pinMode(PHASE_3, OUTPUT);
      pinMode(ENABLE_4, OUTPUT);
      pinMode(PHASE_4, OUTPUT);
      pinMode(ENABLE_5, OUTPUT);
      pinMode(PHASE_5, OUTPUT);
    }
    
    void loop()
    {
      myusb.Task();
    
      if (Serial.available()) {
        int ch = Serial.read(); // get the first char.
        while (Serial.read() != -1) ;
        if ((ch == 'b') || (ch == 'B')) {
          Serial.println("Only notify on Basic Axis changes");
          joystick1.axisChangeNotifyMask(0x3ff);
        } else if ((ch == 'f') || (ch == 'F')) {
          Serial.println("Only notify on Full Axis changes");
          joystick1.axisChangeNotifyMask(joystick_full_notify_mask);
    
        } else {
          if (show_changed_only) {
            show_changed_only = false;
            Serial.println("\n*** Show All fields mode ***");
          } else {
            show_changed_only = true;
            Serial.println("\n*** Show only changed fields mode ***");
          }
        }
      }
    
      for (uint8_t i = 0; i < CNT_DEVICES; i++) {
        if (*drivers[i] != driver_active[i]) {
          if (driver_active[i]) {
            Serial.printf("*** Device %s - disconnected ***\n", driver_names[i]);
            driver_active[i] = false;
          } else {
            Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
            driver_active[i] = true;
    
            const uint8_t *psz = drivers[i]->manufacturer();
            if (psz && *psz) Serial.printf("  manufacturer: %s\n", psz);
            psz = drivers[i]->product();
            if (psz && *psz) Serial.printf("  product: %s\n", psz);
            psz = drivers[i]->serialNumber();
            if (psz && *psz) Serial.printf("  Serial: %s\n", psz);
          }
        }
      }
    
      for (uint8_t i = 0; i < CNT_HIDDEVICES; i++) {
        if (*hiddrivers[i] != hid_driver_active[i]) {
          if (hid_driver_active[i]) {
            Serial.printf("*** HID Device %s - disconnected ***\n", hid_driver_names[i]);
            hid_driver_active[i] = false;
          } else {
            Serial.printf("*** HID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
            hid_driver_active[i] = true;
    
            const uint8_t *psz = hiddrivers[i]->manufacturer();
            if (psz && *psz) Serial.printf("  manufacturer: %s\n", psz);
            psz = hiddrivers[i]->product();
            if (psz && *psz) Serial.printf("  product: %s\n", psz);
            psz = hiddrivers[i]->serialNumber();
            if (psz && *psz) Serial.printf("  Serial: %s\n", psz);
          }
        }
      }
    
    
      // Collect servomotor input and update
      if (joystick1.available()) {
        uint64_t axis_mask = joystick1.axisMask();
        uint64_t axis_changed_mask = joystick1.axisChangedMask();
        //Serial.print("Joystick: buttons = ");
        uint32_t buttons = joystick1.getButtons();
        //Serial.print(buttons, HEX);
        if (show_changed_only) {
          for (uint8_t i = 0; axis_changed_mask != 0; i++, axis_changed_mask >>= 1) {
            if (axis_changed_mask & 1) {
             //Serial.printf(" %d:%d", i, joystick1.getAxis(i));
            }
          }
        }
        else { // Control snake positions
          for (uint8_t i = 0; axis_mask != 0; i++, axis_mask >>= 1) {
            if (axis_mask & 1) {
              uint8_t axisValue = joystick1.getAxis(i);
              uint8_t scaledValue = (255-32)*(axisValue-0)/(255-0)+32;
    //          uint8_t scaledValue = axisValue;
              //Serial.printf(" %d:%d", i, axisValue);
              if (i==2) { // Use right thumbpad input to set motorspeed and direction
                motorSpeed[0][currentSegment] = 2*abs(143 - scaledValue); // motor speed scaled by offset from center
                if (scaledValue < 143) { // if down, phase of 1 = CW
                  motorSpeed[1][currentSegment] = 1;
                }
                else { // if up, phase of 0 = CCW
                  motorSpeed[1][currentSegment] = 0;
                }
              }
    //          else if (i==5) {
    //            motorSpeed[1][0] = scaledValue;
    //          }
              else if (i==9) {
                if (axisValue==0 && currentSegment < 4) {
                  currentSegment++;
    //              for (int j = currentSegment; j > 0; j--) {
    //                motorSpeed[0][j] = motorSpeed[0][j-1];
    //                motorSpeed[1][j] = motorSpeed[1][j-1];
    //              }
                }
                else if (axisValue==4 && currentSegment > 0) {
                  currentSegment--;
    //              for (int j = 0; j <= currentSegment; j++) {
    //                motorSpeed[0][j] = motorSpeed[0][j+1];
    //                motorSpeed[1][j] = motorSpeed[1][j+1];
    //              }
    //              motorSpeed[0][currentSegment + 1] = 144;
    //              motorSpeed[1][currentSegment + 1] = 144;
                }
                delay(10);
              }
            }
          }
          for (uint8_t j = 0; j < 5; j++) {
            analogWrite(motorPin[0][j], motorSpeed[0][j]);
            digitalWrite(motorPin[1][j], motorSpeed[1][j]);
            Serial.printf("\nSeg%d LR:%d UD:%d ", j, motorSpeed[0][j], motorSpeed[1][j]);
          }
          Serial.println();
          Serial.printf("CS:%d ", currentSegment);
        }
        Serial.println();
        joystick1.joystickDataClear();
      }
    //  for (uint8_t i = 0; i < 5; i++) {
    //    analogWrite(motorPin[0][i], 0);
    //    digitalWrite(motorPin[1][i], 0);
    //  }
    }
    
    
    
    void OnHIDExtrasRelease(uint32_t top, uint16_t key)
    {
      Serial.print("HID (");
      Serial.print(top, HEX);
      Serial.print(") key release:");
      Serial.println(key, HEX);
    }
    Thanks again for the help!

  4. #4
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    756
    I would recommend using Visual Micro(VM) with Visual Studio(VS).
    If you code will compile with the Arduino IDE it will compile with VM ands VS.
    The other major advantage is the VM gives you inbuilt debugging.
    See here and code which is released for the Arduino works straight away with VM and VS, no waiting for it to be ported to PlatformIO.

  5. #5
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,834
    Quote Originally Posted by marks View Post
    Thanks so much for the help. I installed VisualTeensy and now I am able to load the simple "Blink" example to my Teensy 4.0.
    Did you include "arduino.h" in main.cpp? VisualTeensy is using plain cpp and does nothing behind your back (as one of its design goals). I.e., you need to include "Arduino.h", you need to forward declare functions and there is no automatic library dectection.

    If including arduino.h doesn't fix the issue, you can zip your project and post it somewhere. I can have a closer look if you want.

  6. #6
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,834
    I just realized that the code you posted is your complete application. All you need to do is adding an #include "Arduino.h" at top of the file and adding the USB Host library to the project. It then compiles without an issue. (Well, you get a warning about an unused button variable in loop, but that's of course correct)

  7. #7
    Junior Member
    Join Date
    Mar 2020
    Posts
    15
    Quote Originally Posted by luni View Post
    I just realized that the code you posted is your complete application. All you need to do is adding an #include "Arduino.h" at top of the file and adding the USB Host library to the project. It then compiles without an issue. (Well, you get a warning about an unused button variable in loop, but that's of course correct)
    Good call. I have now added that but am still having issues with the build process. Now, I am getting errors from using the USBHost_t36.h library, which is throwing the following errors:

    Code:
    In file included from src/main.cpp:15:0:
    lib/USBHost_t36/USBHost_t36.h:383:55: error: 'DEC' was not declared in this scope
      static void print_(const char *s, int n, uint8_t b = DEC) {}
                                                           ^
    lib/USBHost_t36/USBHost_t36.h:384:64: error: 'DEC' was not declared in this scope
      static void print_(const char *s, unsigned int n, uint8_t b = DEC) {}
                                                                    ^
    lib/USBHost_t36/USBHost_t36.h:385:56: error: 'DEC' was not declared in this scope
      static void print_(const char *s, long n, uint8_t b = DEC) {}
                                                            ^
    lib/USBHost_t36/USBHost_t36.h:386:65: error: 'DEC' was not declared in this scope
      static void print_(const char *s, unsigned long n, uint8_t b = DEC) {}
                                                                     ^
    lib/USBHost_t36/USBHost_t36.h:387:57: error: 'DEC' was not declared in this scope
      static void println_(const char *s, int n, uint8_t b = DEC) {}
                                                             ^
    lib/USBHost_t36/USBHost_t36.h:388:66: error: 'DEC' was not declared in this scope
      static void println_(const char *s, unsigned int n, uint8_t b = DEC) {}
                                                                      ^
    lib/USBHost_t36/USBHost_t36.h:389:58: error: 'DEC' was not declared in this scope
      static void println_(const char *s, long n, uint8_t b = DEC) {}
                                                              ^
    lib/USBHost_t36/USBHost_t36.h:390:67: error: 'DEC' was not declared in this scope
      static void println_(const char *s, unsigned long n, uint8_t b = DEC) {}
                                                                       ^
    In file included from src/main.cpp:15:0:
    lib/USBHost_t36/USBHost_t36.h:1411:54: error: expected class-name before '{' token
     class USBSerialBase: public USBDriver, public Stream {
                                                          ^
    lib/USBHost_t36/USBHost_t36.h:1443:8: error: 'Print' has not been declared
      using Print::write;
            ^
    lib/USBHost_t36/USBHost_t36.h: In member function 'void AntPlus::onHeartRateMonitor(void (*)(int, int, int), uint32_t)':
    lib/USBHost_t36/USBHost_t36.h:1549:30: error: 'memset' was not declared in this scope
       memset(&hrm, 0, sizeof(hrm));
                                  ^
    lib/USBHost_t36/USBHost_t36.h: In member function 'void AntPlus::onSpeedCadence(void (*)(float, float, float), uint32_t)':
    lib/USBHost_t36/USBHost_t36.h:1554:36: error: 'memset' was not declared in this scope
       memset(&spdcad, 0, sizeof(spdcad));
                                        ^
    lib/USBHost_t36/USBHost_t36.h: In member function 'void AntPlus::onSpeed(void (*)(float, float), uint32_t)':
    lib/USBHost_t36/USBHost_t36.h:1559:30: error: 'memset' was not declared in this scope
       memset(&spd, 0, sizeof(spd));
                                  ^
    lib/USBHost_t36/USBHost_t36.h: In member function 'void AntPlus::onCadence(void (*)(float), uint32_t)':
    lib/USBHost_t36/USBHost_t36.h:1564:30: error: 'memset' was not declared in this scope
       memset(&cad, 0, sizeof(cad));
                                  ^
    lib/USBHost_t36/USBHost_t36.h: At global scope:
    lib/USBHost_t36/USBHost_t36.h:1787:56: error: expected class-name before '{' token
     class USBSerialEmu : public USBHIDInput, public Stream {
                                                            ^
    lib/USBHost_t36/USBHost_t36.h:1802:8: error: 'Print' has not been declared
      using Print::write;
            ^
    lib/USBHost_t36/USBHost_t36.h:2134:5: error: 'elapsedMillis' does not name a type
         elapsedMillis _emlastRead;
         ^
    lib/USBHost_t36/USBHost_t36.h: In member function 'bool msController::available()':
    lib/USBHost_t36/USBHost_t36.h:2068:28: error: 'delay' was not declared in this scope
      bool available() { delay(0); return deviceAvailable; }
                                ^
    src/main.cpp: In function 'void loop()':
    src/main.cpp:156:14: warning: unused variable 'buttons' [-Wunused-variable]
         uint32_t buttons = joystick1.getButtons();
                  ^
    make: *** [makefile:231: .vsteensy/build/src/main.cpp.o] Error 1
    make: *** Waiting for unfinished jobs....
    LIB [CPP] ehci.cpp 
    The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command C:/Users/fh829e/Documents/VisualTeensy_v1.5.0/make.exe all -j -Otarget" terminated with exit code: 1.
    Thanks!

  8. #8
    Junior Member
    Join Date
    Mar 2020
    Posts
    15
    Chronicling my journey here for reference. I managed to get the project to build by adding:

    Code:
    #include <cstddef>
    #include "Arduino.h"
    To the file "USBHost_t36.h". I am not experienced in C++ so I'm not sure why this would do it. I guess it's some kind of scope issue that doesn't rear it's head in the Arduino IDE for whatever reason. Any clarification would be nice! Thanks again, all!

    Edit: Just re-read the above comment on automatic library detection. That makes sense. Still wondering if my solution is hacky or non-best practice.

  9. #9
    Junior Member
    Join Date
    Mar 2020
    Posts
    15
    Sorry for the spam, but now a new problem has popped up when I try to upload to the teensy.

    Code:
    Teensy Loader could not find the file DemoSnake
    quitmake: *** [makefile:165: upload] Error 1
    The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command C:/Users/fh829e/Documents/VisualTeensy_v1.5.0/make.exe upload -j -Otarget" terminated with exit code: 1.
    Looking at the verbose output from Teensy:

    Code:
    09:41:54.832 (post_compile 38): Begin, version=1.56, high-res time
    09:41:54.836 (loader): remote connection 1876 opened
    09:41:54.839 (loader): remote cmd from 1876: "comment: Teensyduino 1.56 - WINDOWS (teensy_post_compile)"
    09:41:54.839 (post_compile 38): Sending command: comment: Teensyduino 1.56 - WINDOWS (teensy_post_compile)
    09:41:54.841 (loader): remote cmd from 1876: "status"
    09:41:54.854 (loader): remote cmd from 1876: "dir:.vsteensy/build\"
    09:41:54.854 (post_compile 38): Status: 0, 1, 0, 9, 0, 0, .vsteensy/build\, FOD_Snake.hex
    09:41:54.854 (post_compile 38): Sending command: dir:.vsteensy/build\
    09:41:54.857 (loader): remote cmd from 1876: "file:DemoSnake.hex"
    09:41:54.857 (post_compile 38): Sending command: file:DemoSnake.hex
    09:41:54.860 (post_compile 38): Teensy Loader could not find the file DemoSnake
    09:41:54.860 (post_compile 38): quit
    09:41:54.934 (loader): remote connection 1876 closed
    Running a brand new project created using VisualTeensy works just fine (blinks LED rapidly, no other libraries imported). Lost as to what could be causing this.

  10. #10
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,834
    Quote Originally Posted by marks View Post
    Still wondering if my solution is hacky or non-best practice.
    Yes it is, and it is not necessary. As already written in #6 all you need to do is to place
    #include "Arduino.h" in the very first line of your main.cpp.

    Additionally, add the USBHost_t3.6 library to the Project setup:
    Click image for larger version. 

Name:	Screenshot 2022-06-01 203625.jpg 
Views:	4 
Size:	94.9 KB 
ID:	28564

    Don't forget to save to regenerate you project.

    Regarding your upload issues it looks like you don't have a hex file. I suggest to simply delete the complete project folder and start from scratch again.
    I.e., add the library, save/generate the project, replace the autogenerated code with your code in main.cpp, add 'include "arduino.h" on top of the file and you should be good.


    Normally all that stuff just works out of the box. Only mess around with advanced settings if you know what you do and don't add stuff manually to the generated jsons and makefiles. There are a few videos on my youtube channel (https://www.youtube.com/channel/UCbs...TmvImjA/videos) which might help if you don't have much experience.

    If you like the automatism's of the Arduino IDE but not the Editor, VisualMicro -as recommended by BriComp- might be a better fit.

  11. #11
    Junior Member
    Join Date
    Mar 2020
    Posts
    15
    Quote Originally Posted by luni View Post
    Yes it is, and it is not necessary. As already written in #6 all you need to do is to place
    #include "Arduino.h" in the very first line of your main.cpp.

    Additionally, add the USBHost_t3.6 library to the Project setup:
    Click image for larger version. 

Name:	Screenshot 2022-06-01 203625.jpg 
Views:	4 
Size:	94.9 KB 
ID:	28564

    Don't forget to save to regenerate you project.

    Regarding your upload issues it looks like you don't have a hex file. I suggest to simply delete the complete project folder and start from scratch again.
    I.e., add the library, save/generate the project, replace the autogenerated code with your code in main.cpp, add 'include "arduino.h" on top of the file and you should be good.


    Normally all that stuff just works out of the box. Only mess around with advanced settings if you know what you do and don't add stuff manually to the generated jsons and makefiles. There are a few videos on my youtube channel (https://www.youtube.com/channel/UCbs...TmvImjA/videos) which might help if you don't have much experience.

    If you like the automatism's of the Arduino IDE but not the Editor, VisualMicro -as recommended by BriComp- might be a better fit.
    Thanks for all the help. I recreated a new project but was still having the same issue with uploading. I eventually realized the wrong folder was selected for the uploader. Changing this allowed me to upload successfully.

Posting Permissions

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