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

Thread: Teensy 4.0 w/ TF Mini LIDAR issue

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

    Teensy 4.0 w/ TF Mini LIDAR issue

    Hi all, I am having issues getting a Benewake TF mini lidar unit to work on a teensy 4.0. I am using the library https://github.com/opensensinglab/tfmini . The following code works just fine on an arduino uno but I cant get this code to work on the teensy. I tried pins 0 and 1 on the teensy and putting said changes in the code as well to no avail. All i see on the serial monitor is "initializing...". Is this a library issue? Any guidance in getting this Lidar to work on the teensy is much appreciated. Thank you all for your time.

    #include <SoftwareSerial.h>
    #include "TFMini.h"
    SoftwareSerial mySerial(10, 11); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
    TFMini tfmini;

    void setup() {
    Serial.begin(115200);
    Serial.println ("Initializing...");
    mySerial.begin(TFMINI_BAUDRATE);
    tfmini.begin(&mySerial);
    }


    void loop() {
    // Take one TF Mini distance measurement
    uint16_t dist = tfmini.getDistance();
    uint16_t strength = tfmini.getRecentSignalStrength();

    // Display the measurement
    Serial.print(dist);
    Serial.print(" cm sigstr: ");
    Serial.println(strength);

    delay(25);
    }

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,563
    Not sure if this page is current: pjrc.com/teensy/td_libs_SoftwareSerial.html

    From that page … any better with ::
    Code:
    #define rxPin 0
    #define txPin 1
    
    // set up a new serial port
    SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
    
    void setup()  {
      // define pin modes for tx, rx, led pins:
      pinMode(rxPin, INPUT);
      pinMode(txPin, OUTPUT);
    // ...

  3. #3
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,144
    When you said you tried to use pins 0 and 1, were you still trying to use SoftwareSerial? Also not sure software serial has been updated to work with T4.0 yet. However with that said you would probably be better off using one of H/W serial ports. So, for instance if you want to use Serial1 (pins 0 and 1):
    Code:
    #include <SoftwareSerial.h>
    #include "TFMini.h"
    TFMini tfmini;
    
    #define mySerial  Serial1
    
    void setup() {
    Serial.begin(115200);
    Serial.println ("Initializing...");
    mySerial.begin(TFMINI_BAUDRATE);
    tfmini.begin(&mySerial); 
    }

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,691
    As mentioned, if you are free to use other pins.
    Example pin 0, 1 than you should use the hardware serial port. As @mjs513 mentioned would be Serial1

    If you have fixed pins like pins 10 and 11, than you might be able to use my FlexIO stuff, where I have Serial port emulation using Flex IO pins.

  5. #5
    Junior Member
    Join Date
    Mar 2020
    Posts
    8
    I put the rx and tx on the respective 0 and 1 pins and included the code you recommend. On the serial monitor it did not even display "initializing".

    Code:
    #include <SoftwareSerial.h>
    #include "TFMini.h"
    TFMini tfmini;
    #define mySerial Serial1
    
    
    void setup() {
    
    Serial.begin(115200);
    Serial.println ("Initializing...");
    mySerial.begin(TFMINI_BAUDRATE);
    tfmini.begin(&mySerial); 
    
    }
    
    void loop() {
      // Take one TF Mini distance measurement
      uint16_t dist = tfmini.getDistance();
      uint16_t strength = tfmini.getRecentSignalStrength();
    
      // Display the measurement
      Serial.print(dist);
      Serial.print(" cm      sigstr: ");
      Serial.println(strength);
    
      // Wait some short time before taking the next measurement
      delay(25);  
    }

  6. #6
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,144
    Did you attach rx-tx and tx to rx? or did you match rx-rx and tx-tx?

  7. #7
    Junior Member
    Join Date
    Mar 2020
    Posts
    8
    Quote Originally Posted by defragster View Post
    Not sure if this page is current: pjrc.com/teensy/td_libs_SoftwareSerial.html

    From that page … any better with ::
    Code:
    #define rxPin 0
    #define txPin 1
    
    // set up a new serial port
    SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
    
    void setup()  {
      // define pin modes for tx, rx, led pins:
      pinMode(rxPin, INPUT);
      pinMode(txPin, OUTPUT);
    // ...
    I put the tx and rx on the respective pins and tried your code with...
    Code:
    #include <SoftwareSerial.h>
    #include "TFMini.h"
    #define rxPin 0
    #define txPin 1
    TFMini tfmini;
    
    SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
    
    void setup() {
    
    pinMode(rxPin, INPUT);
    pinMode(txPin, OUTPUT);
    Serial.begin(115200);
    Serial.println ("Initializing...");
    mySerial.begin(TFMINI_BAUDRATE);
    tfmini.begin(&mySerial); 
    
    }
    
    void loop() {
      // Take one TF Mini distance measurement
      uint16_t dist = tfmini.getDistance();
      uint16_t strength = tfmini.getRecentSignalStrength();
    
      // Display the measurement
      Serial.print(dist);
      Serial.print(" cm      sigstr: ");
      Serial.println(strength);
    
      // Wait some short time before taking the next measurement
      delay(25);  
    }
    I couldn't get anything on serial monitor.

  8. #8
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,691
    Again as suggested, you might want to do it more like:
    Code:
    #include "TFMini.h"
    TFMini tfmini;
    
    void setup() {
      // wait up to 4 seconds for serial monitor to be valid
      while (!Serial && millis() < 4000) ; 
      Serial.begin(115200); 
      Serial.println ("Initializing...");
      Serial1.begin(TFMINI_BAUDRATE);
      tfmini.begin(&Serial1); 
    
    }
    
    void loop() {
      // Take one TF Mini distance measurement
      uint16_t dist = tfmini.getDistance();
      uint16_t strength = tfmini.getRecentSignalStrength();
    
      // Display the measurement
      Serial.print(dist);
      Serial.print(" cm      sigstr: ");
      Serial.println(strength);
    
      // Wait some short time before taking the next measurement
      delay(25);  
    }
    Note: the added while (!Serial...
    It waits up to 4 seconds for the USB serial object to be initialized and connected to the pc before it continues. Unlike Arduinos like UNOs which have a separate processor (or interface chip) that does USB, the Teensy itself does serial (like Arduino Leonardo), so if you print something out at startup time before your PC has registered the usb object you might miss the output.

    Also note, I am using the Serial1 hardware setup and not the Software Serial code.

  9. #9
    Junior Member
    Join Date
    Mar 2020
    Posts
    8
    White wire to pin 0 (RX1) , green wire to pin 1 (TX1) , red wire to 5 volt Vin, black wire to GND next to VIN.

    Click image for larger version. 

Name:	14588-TFMini_-_Micro_Infrared_Module-03_Pinout_small.png 
Views:	5 
Size:	219.2 KB 
ID:	19508

  10. #10
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,144
    Think you have Rx and Tx wired in correctly.

    Code:
    Green wire (Tx) -> pin 0 (Rx) on T3.6
    While wire (Rx) -> pin 1 (Tx) on T3.6
    Red (5v) -> Vin on T3.6
    GND -> GND on T3.6 (pin right before pin 0).  GND next to Vin is for Audio Gnd.
    This might help with the wiring:
    https://www.instructables.com/id/Ben...ith-Teensy-35/

  11. #11
    Junior Member
    Join Date
    Mar 2020
    Posts
    8
    I was not aware that the teensy itself does serial. I copied your code verbatim. The serial monitor didn't print the "initializing" and is blank.

    Appreciate all of your help. Relatively new to Arduino and completely new to teensy.

  12. #12
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,144
    Did you see my post on the wiring and try it in that configuration. Post #10

  13. #13
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,563
    Quote Originally Posted by cbennett View Post
    I was not aware that the teensy itself does serial. I copied your code verbatim. The serial monitor didn't print the "initializing" and is blank.

    Appreciate all of your help. Relatively new to Arduino and completely new to teensy.
    Indeed Teensy LC, 3.2, 3.5 and 3.6 and 4.0 all have 3 or more native Serial UART ports. As noted in the P#2 'out of date link':

    The hardware UART Serial port should always be used, if possible, before considering SoftwareSerial. On Teensy, the hardware UART serial port completely separate from the USB port.
    Some Arduino software seems to still rely on or require software Serial - but where possible using the Native Serial hardware results in better performance with less processor overhead, especially on those ports with a FIFO.

    When using Serial the Rx on one side must be connected to the Tx on the other side in both directions and they must share a common GND connection. And the UART signals are delivered and expected from Teensy at 3.3 volts - and on LC, and 3.6 and 4.0 voltage must be limited to 3.3V.

  14. #14
    Junior Member
    Join Date
    Mar 2020
    Posts
    8
    Quote Originally Posted by mjs513 View Post
    Did you see my post on the wiring and try it in that configuration. Post #10
    Yes, was unaware tx -> rx and vice versa. Thanks for all your help!

Posting Permissions

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