budryerson / TFLuna-I2C

Arduino library for the Benewake TFLuna LiDAR distance sensor in the I2C communication mode
29 stars 9 forks source link

TF Luna I2C distance in MM #4

Open alecir4 opened 2 years ago

alecir4 commented 2 years ago

Hi Bud,

Thank you for your wonderful libraries! I was previously using the TFMPlus library with my TF Luna and it was working great, however I am now switching to I2C and using the tca9548A mux such that I can gather data from 4 Lunas on one board (Arduino Mega or Nano).

In the TFMPlus library, I was able to set the settings to MM and noticed there was no function for MM in the TFLuna-I2C library. Did I not look carefully enough in the .cpp / README files?

If there is no function, could you help guide me on how to switch the settings to MM? I see on the data sheet from Benewake that you can change output format using different hex inputs, but I'm not the strongest with this type of coding. Thanks in advance for any help!

Cheers, Alec

alecir4 commented 2 years ago

Out of curiosity, I tried setting the board settings to mm in serial communication before switching to I2C. To no surprise, this did not work and returned "Status = I2C WRITE".

I have now been trying to use your function I2C_FORMAT_MM in the following way during the setup() function of the TFMini-Plus library (I am still using my TF Luna):

`printf("Set format in mm: ");
if (tfmP.sendCommand(I2C_FORMAT_MM, 0))
{
  printf("Units in mm.\r\n");
}
else tfmP.printReply(); 

delay(500); 

tfmP.sendCommand(SAVE_SETTINGS ,0); 
delay(500);

printf( "Set I2C Mode: ");
if( tfmP.sendCommand( SET_I2C_MODE, 0))
{
    printf( "mode set.\r\n");
}
else tfmP.printReply();

delay(500); 

printf( "Save settings: ");
if( tfmP.sendCommand( SAVE_SETTINGS, 0))
{
    printf( "saved.\r\n");
}
else tfmP.printReply();

delay(500);  // added to allow the System Rest enough time to complete

`

The commands do work and I see the success messages in the serial monitor, but then it continues to gather data through UART communication on the same script, printing the distance in default cm. When I then change the wires to I2C pins and run the TFLI2C script, I get the same "status: I2C WRITE" error mentioned above. In my setup function there is only serial.begin and wire.begin (no change in settings or resets that could undo the "I2C_FORMAT_MM" command).

I am not sure if I am doing everything correctly and am getting quite lost. In the keywords.txt file for TFLuna-I2C, I do not see anything to switch to mm, thus do I need to switch to a TFMini-Plus to achieve I2C in mm? I noticed in your TFLuna-I2C description how this device is different than any other...so it seems like I do not have a way to obtain mm while using I2C communication. Sorry for the double comment, should've made sure to read everything thoroughly before posting!

Any help or further details would be greatly appreciated! :)