TFMini Plus does not work at all

I am using the library and example supplied here (Arduino.cc) and it does not work on a Mega2560. The 4 wires are in correctly. Does anyone have a good TFMini Plus sample sketch I can use? Thank you in advance!

Please supply full descriptions and links, don't force us to sit and research. That is recommended in the forum guidelines, it's not my advice. Why do you think the example sketch doesn't work because it's a Mega? Couldn't something else be wrong? What testing and troubleshooting have you done up to now?

It's extremely unlikely that anyone will just have and post the code you are asking for. Better give details of the problem, and let people analyze and help you.

Here is the top part of the code. I have changed a few things but it should still run. The `sensor begin returns a value of one so it is wired correctly and responding. The next step (soft reset) and all others fail. The commands and how they are sent / responses are stock unchanged from the example in the downloaded library.




#include <TFMPlus.h>  // Include TFMini Plus Library v1.5.0
TFMPlus tfmP;         // Create a TFMini Plus object

                                    
void setup()
   {
   Serial.begin( 9600  );   // Intialize terminal serial port
   delay(20);               // Give port time to initalize
   //printf_begin();          // Initialize printf.
   Serial.println(   F(   "TFMPlus Library Example - 10SEP2021"   )  );  

   Serial1.begin( 115200)    ;  // Initialize TFMPLus device serial port.
   
   delay(1000);               // Give port time to initalize
   
   Serial.print(  F("Status of   tfmP.begin( &Serial1 ) is : " ) ) ;
    
    
   Serial.println(  tfmP.begin( &Serial1 )   );   // Initialize device library object and...
                             // pass device serial port to the object.

   // Send some example commands to the TFMini-Plus
   // - - Perform a system reset - - - - - - - - - - -

   Serial.println(  ""  ) ;
   Serial.println(  ""  ) ;
   Serial.println(  ""  ) ;
   Serial.print( "status of Soft reset: ");




   if( tfmP.sendCommand( SOFT_RESET  , 0  ))
       {
       Serial.println( "   passed  ");
       }
   else 
       {
       Serial.println( F(" *********** failed soft reset ****************" ) ) ;  
       tfmP.printReply();
       }
   delay(1000);  // added to allow the System Rest enough time to complete
  

I think you must know that the entire sketch is required.

You didn't say whether you posted the example code, where it came from exactly, or whether it is your own code.

You haven't posted any links to, or information about, the device.

Read my OP. Its clearly stated there where the code came from. As for "links" the source of the code is clearly stated in my OP.





                                    
void setup()
   {
   Serial.begin( 9600  );   // Intialize terminal serial port
   delay(20);               // Give port time to initalize
   //printf_begin();          // Initialize printf.
   Serial.println(   F(   "TFMPlus Library Example - 10SEP2021"   )  );  

   Serial1.begin( 115200)    ;  // Initialize TFMPLus device serial port.
   
   delay(1000);               // Give port time to initalize
   
   Serial.print(  F("Status of   tfmP.begin( &Serial1 ) is : " ) ) ;
    
    
   Serial.println(  tfmP.begin( &Serial1 )   );   // Initialize device library object and...
                             // pass device serial port to the object.

   // Send some example commands to the TFMini-Plus
   // - - Perform a system reset - - - - - - - - - - -

   Serial.println(  ""  ) ;
   Serial.println(  ""  ) ;
   Serial.println(  ""  ) ;
   Serial.print( "status of Soft reset: ");




   if( tfmP.sendCommand( SOFT_RESET  , 0  ))
       {
       Serial.println( "   passed  ");
       }
   else 
       {
       Serial.println( F(" *********** failed soft reset ****************" ) ) ;  
       tfmP.printReply();
       }
   delay(1000);  // added to allow the System Rest enough time to complete
  
   
   Serial.println(  ""  ) ;
   Serial.println(  ""  ) ;
   Serial.println(  ""  ) ;
   
   // - - Display the firmware version - - - - - - - - -
   Serial.print( "status of Firmware version:    ");
   if( tfmP.sendCommand( GET_FIRMWARE_VERSION, 0))
      {
      Serial.print(  F( "Version   " ) ) ;
      Serial.print(  tfmP.version[ 0]); // print three single numbers
      Serial.print(  F( "." ) ) ;
      Serial.print(  tfmP.version[ 1]); // each separated by a dot
      Serial.print(  F( "." ) ) ;
      Serial.println(  tfmP.version[ 2]);
      }
   else
      { 
      Serial.println( F(  "*************  Failed version data  **********************" ) ) ; 
      tfmP.printReply();
      }
   delay(1000);   

   Serial.println(  ""  ) ;
   Serial.println(  ""  ) ;
   Serial.println(  ""  ) ;

   
   // - - Set the data frame-rate to 20Hz - - - - - - - -
   Serial.print( "status of Data-Frame rate: ");
   if( tfmP.sendCommand( SET_FRAME_RATE, FRAME_20))
      {
      Serial.print(  F( "  Frame rate:  " ) ) ;
      Serial.println(  FRAME_20);
      }
   else 
      {
      Serial.println(  F(  "****************  Failed set frame rate  ***********************" ) ) ; 
      tfmP.printReply();
      }
   delay(1000) ; 













    /********************  
    // The next two commands may be used to switch the device 
    // into I2C mode.  This sketch will no longer receive UART
    // (serial) data.  The 'TFMPI2C_example' sketch in the 
    // TFMPI2C Library can be used to switch the device back
    // to UART mode.
    // Don't forget to switch the cables, too.
    // - - - - - - - - - - - - - - - - - - - - - - - -
    Serial.println( "Set I2C Mode: ");
    if( tfmP.sendCommand( SET_I2C_MODE, 0))
    {
        Serial.println( "mode set.\r\n");
    }
    else tfmP.printReply();
    Serial.println( "Save settings: ");
    if( tfmP.sendCommand( SAVE_SETTINGS, 0))
    {
        Serial.println( "saved.\r\n");
    }
    else tfmP.printReply();
    // - - - - - - - - - - - - - - - - - - - - - - - -    
    ************/

  
   }


















// Initialize variables
int16_t tfDist = 0;    // Distance to object in centimeters
int16_t tfFlux = 0;    // Strength or quality of return signal
int16_t tfTemp = 0;    // Internal temperature of Lidar sensor chip















// Use the 'getData' function to pass back device data.
void loop()
{
    delay(50);   // Loop delay to match the 20Hz data frame rate

    if( tfmP.getData( tfDist, tfFlux, tfTemp)) // Get data from the device.
    {
      Serial.print(  F( "   distance   " ) ) ;
      Serial.println(  tfDist);   // display distance,
      Serial.print(  F( "   flux   " ) ) ;
      Serial.println(  tfFlux);   // display signal strength/quality,
      Serial.print(  F( "   temp     " ) ) ;
      Serial.println( tfTemp );   // display temperature,
      //Serial.println( "\r\n");                   // end-of-line.
    }
    else                  // If the command fails...
    {
      tfmP.printFrame();  // display the error and HEX dataa
    }
}







My bad, you did say it was your code in reply #3. However you are still forcing us to Google. Please provide URLs.

Also many of my questions remain unanswered. Other people will just wonder the same things...

The web site I got the library and the example code is called "arduino.cc" If you Google "Arduino" I think you will find the web site. Usually the people on this web site are very friendly and eager to help newbies like me who are not technical and struggling to understand and get their sensors, etc, working.

So this code is the example code from this Arduino.cc website (who ever these people are). I simply downloaded and installed this library, opened the example and it did not work. I added some Serial.print() s to help me zero in on where the problem appears.

I did not say it's "my code" Its the code from "Arduino.cc" and I just added some prints and such to try and zero in on where the problem arises.

As far as the two devices are concerned: The sensor is called a "TFMini Plus" and is available from Benewake in China. The microcontroller is called "Arduino Mega2560" and is made by the same people who provided the library: again the "Arduino.cc" website has both microcontroller boards you can purchase as well as libraries you can download.

I have used also 3 different Mega2560 boards on the off chance one might have been bad. I tried switching the Tx and Rx wires on the chance I may have had them backwards (the sensor begin works when the wires are correct, does not when they are backwards as expected). The set up is powered by the laptop USB cable to the Mega2560. There are no other components involved.

The TFMini Plus gets it's power from the 5V VCC rail, 3.3 will not power it properly (I tried).

My apologies: I thought my OP ("Original Post" / "Original Poster") was clear where the library came example came from.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.