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

Thread: Teensy 4.0 not compiling Teensy 3.2 code

  1. #1
    Member
    Join Date
    Jun 2018
    Location
    Northeast USA
    Posts
    42

    Teensy 4.0 not compiling Teensy 3.2 code

    Hello All,

    Apologies to professional programmers for how nasty the attached project code 2BEN2STT40_200120.zip will appear. This project compiles without error for Teensy 3.2 under Arduino IDE 1.8.9 and 1.8.10. And though I can compile 'blinky' for Teensy 4.0, the attached code generates multiple errors. The errors are in an attached file (T4 errs.txt) as well. 2BEN2STT40_200120.zip

    If you are interested in LIDAR, the project has code to run several types of LIDAR, including Garmin LL3, and Benewake, so if you've had any issues with those LIDARs, I'll gladly help.

    Thank you.
    and "duh" in advance, this is probably something stupid I've overlooked!
    Attached Files Attached Files
    Last edited by amensch; 01-20-2020 at 08:11 PM. Reason: forgot an attachment.

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,103
    Probably the main issue, is I don't believe the i2c_t3 library has been ported over to the T4.

    I am not sure your zip file has your code?
    Code:
    #define PIN_led 13
    IntervalTimer Watchdog_Timer;
    unsigned long TimePeriodInMicroSeconds = 1000000;
    volatile int loops = 0 ;
    
    // the setup routine runs once when you press reset:
    void setup() {
    	// initialize the digital pin as an output.
    	pinMode(PIN_led, OUTPUT);
      // Start a serial monitor to watch what's happening..
      Serial.begin(115200);
      // Start the interrupt timer.....
      Watchdog_Timer.begin(INT_Watchdog, TimePeriodInMicroSeconds); 
    }
    
    void INT_Watchdog() {   
      if (digitalRead(PIN_led) != HIGH){  
        digitalWrite(PIN_led, HIGH); 
      }else{    
        digitalWrite(PIN_led, LOW);    
      }
      loops++;
    }
    
    
    // the loop routine runs over and over again forever:
    void loop() {     
      static unsigned int LastLoops = 0;
        // no need to do anything for this program,
         // as the interrupt does all the blinking
         // but print something just for the heck of it...
         if (LastLoops != loops){
            Serial.println(loops);
            LastLoops = loops;
         }
    }
    Which does compile fine for me.

  3. #3
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,211
    Did you upload the wrong file? This compiles fine and shows no errors?

  4. #4
    Member
    Join Date
    Jun 2018
    Location
    Northeast USA
    Posts
    42

    Right files now included.....

    Sorry guys, I did indeed zip & upload the wrong file(s) 1BEN1ST40_200120.zip is the monster messy version. I've since put together a combination of the two, bringing over a bit of code at a time to get a handle on this.

    To that end, I added another .cpp and .h file to the 'blinky' sketch above to bring in some of the code from the big 'monster messy' version and see when compiling would stop. It's called LIDAR_IO.cpp and LIDAR_IO.h LIDAR_IO.cppLIDAR_IO.h. When I compile, I now get error: 'Serial2' was not declared in this scope
    Serial2.write(0x42); Serial2.write(0x57); Serial2.write(0x02); Serial2.write(0x00);
    But before I added the LIDAR_IO code as a new file in the sketch, there was no compiler error for the Serial2.begin(115200); statement that is in "main".

    I sort of wondered if i2c_t3 was part of the problem. Would like to do I2C work off the Teensy4.0 at some point to support the Garmin LL3 lidars. Off topic, but beware, there were two separate problems with those LIDARS that were fixed by Garmin just in Dec 2020. Have not received the updated versions yet to see if the issue I reported is actually fixed, but they are shipping new units now.

    Thanks for any and all insight.

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,616
    TeensyDuino 1.49 presents a good working and mature i2c Wire master library for Teensy 4.0!

    Changing to that may require some edits if any i2c_t3 custom code was used. But that Wire code has been tested to work well with LIDAR hardware.

  6. #6
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,610
    Just a couple of quick comments.

    1. As @KurtE pointed out if you want to use a T4 you have to change from using i2c_t3 to the normal Wire library. Otherwise it will never compile.
    2. The TFmini lidar code doesn't use I2C at all from the look at it, all serial commands.
    3. As for your SerialX errors try adding a #include <Arduino.h> to TFmini.cpp and LIDAR_IO.cpp.

    LidarIO looks like you are using one of Garmin's units as well as the TFmini. If that is that case why now just use one of their libraries instead of trying to incorporate it as part of the sketch?

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,103
    A few things going on...

    The current code sort of relies on the I2C_t3.h file to bring in Arduino.h...

    Since I2C_t3 is not currently ported over to work with T4, it did not bring in Arduino.h... Which is why you get the errors Serail2 (or was it Serial3) is not defined...

    Hopefully at some point I2C_t3 will be ported over, but the owner of the library (nox771) has not made any changes to that library for about 2 years now.
    Hist last forum posting: https://forum.pjrc.com/threads/21680...l=1#post222376

    As @defragster mentioned the Wire library is working reasonably well now, for the standard Wire like things and we have tested it to see if it works with a couple of Lidar Lites. (Lidar Lite V3 and V4 LED).
    What I believe I see in your LIDAR stuff is using DMA transfers, which I don't think is supported in Wire library.


    FYI - I do have a couple of other Lidar units, the Lidar that came with Robotis Turtlebot3, and one from Get Surreal which had a Teensy 2 controller, but now is a LC and I think we played with a T4 in it...

  8. #8
    Member
    Join Date
    Jun 2018
    Location
    Northeast USA
    Posts
    42
    Thanks for looking it over. Very good stuff defragster & mjs513!

    Including Arduino.h did the trick wrt the serial errors! Why did it compile for the T32 and not the T4?

    You're right, the TFmini is all serial, and that's the LIDAR (actually not a LIDAR) and that's the one I'm most committed to in the short term, so I'll temporarily drop the Garmin support till i2c_t3 is working. I used i2c_t3 also for the better timing, that's why I passed on the Garmin libraries. I also had to do a lot of poking and testing using some uncommon Garmin modes which aren't supported by their libraries.

    In the 2017-2019 firmware version of the LL3, they lost the ability to support two LL3's at separate I2C addresses. That was fixed for the 2019 version, but, there were optics problems (they sourced a bandbass optical filter with the the center freq off from 905nM. That's supposed to be fixed now.

  9. #9
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,616
    Good there is a path forward. FYI - Teensy 4 has 3 i2c busses - all are supported with included Wire as Wire, Wire1 and Wire2 so you can use 2 of the same i2c ID if put on a unique bus.

    As far as T_3.2 working - reading KurtE's comment that was because the working i2c_t3 explicitly included it when it worked.

  10. #10
    Member
    Join Date
    Jun 2018
    Location
    Northeast USA
    Posts
    42
    Garmin did get the I2C address issue fixed in March 2019, so as you mention, there's great flexibility with the T4 to solve this. Startup hiccups from when Garmin bought the LL3 design from the startup that developed it.

    Thanks for the help MJS513, KurtE and defragster. I'm glad Paul came out with the Teensy 4.0.....wicked good capability, but it's also very nice of you folks to users from stumbling!

  11. #11
    Member
    Join Date
    Jun 2018
    Location
    Northeast USA
    Posts
    42
    Hmmmm.... closer..... I included Wire.h, but am getting errors like:
    error: 'I2C_PULLUP_INT' was not declared in this scope
    Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_INT, I2C_RATE_400, I2C_OP_MODE_DMA );

    and
    error: 'class TwoWire' has no member named 'resetBus'
    Wire.resetBus();

    Does nox771 have source posted to help figure this out? Thank You.

  12. #12
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,103
    I believe a version of it is installed with Teensyduino - So for example on my machine it is at: C:\arduino-1.8.10\hardware\teensy\avr\libraries\i2c_t3
    i.e. where you install Teensyduino in the libraries\i2c_t3 directory.

  13. #13
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,103
    I believe a version of it is installed with Teensyduino - So for example on my machine it is at: C:\arduino-1.8.10\hardware\teensy\avr\libraries\i2c_t3
    i.e. where you install Teensyduino in the libraries\i2c_t3 directory.

    As I mentioned earlier the i2c_t3 library has some additional feature not part of standard Wire library.

    Example the line: Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_INT, I2C_RATE_400, I2C_OP_MODE_DMA );

    is Saying you are using the Wire object with standard pins 18(SDA) and 19(SCL) My guess is Wire defaults to enable internal Pull ups, but my guess is that most of your device might have their own as well and/or you may want external PU.

    I2C_RATE_400 - I am guessing that is run at 400K?
    You would get that with standard Wire library by doing:
    Wire.setClock(400000);

    Now OP_MODE_DMA - Again I don't think Wire library does DMA operations...


    I am not sure if Wire library has a function like resetBus().

    Note: The sources for Wire library are like i2c_t3: C:\arduino-1.8.10\hardware\teensy\avr\libraries\Wire
    Note: there are separate source files for different platforms in that directory, for T4 they are (wireIMXRT.h and .cpp)

  14. #14
    Member
    Join Date
    Jun 2018
    Location
    Northeast USA
    Posts
    42
    Thanks KurtE. Great context to move ahead.
    BTW, you're right on the 400KHz. Playing with that and using 2.5K external pullup resistors I was able to run the Garmin LL3's at 1MHz, But not 1.2Mhz!
    Again, thanks, and Regards.

Posting Permissions

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