Benewake TF-Mini (new device)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
phealt
New user
Posts: 2
Joined: 04 Jan 2018, 02:17

Benewake TF-Mini (new device)

#1 Post by phealt » 04 Jan 2018, 02:40

Hello all, I'm inquiring if anyone has attempted to add a Benewake TF-mini lidar device. http://www.benewake.com/en/tfmini.html

I have attempted to code a custom device but I'm receiving large numbers. Image I have very little experience with programming, but was able to compile and use this.

Code: Select all

//#######################################################################################################
//#################################### Plugin 129: TFmini LIDAR #########################################
//#######################################################################################################

#define PLUGIN_129
#define PLUGIN_ID_129        129
#define PLUGIN_NAME_129       "TFmini"
#define PLUGIN_VALUENAME1_129 "Distance"
#define PLUGIN_VALUENAME2_129 "Strength"
boolean Plugin_129(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;

  switch (function)
  {

    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_129;
        Device[deviceCount].Type = DEVICE_TYPE_TFMINI;
        Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].PullUpOption = false;
        Device[deviceCount].InverseLogicOption = false;
        Device[deviceCount].FormulaOption = false;
        Device[deviceCount].DecimalsOnly = true;
        Device[deviceCount].ValueCount = 2;
        Device[deviceCount].SendDataOption = true;
        Device[deviceCount].TimerOption = true;
        Device[deviceCount].GlobalSyncOption = true;
        break;
      }

    case PLUGIN_GET_DEVICENAME:
      {
        string = F(PLUGIN_NAME_129);
        break;
      }

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_129));
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_129));
        break;
      }

    case PLUGIN_WEBFORM_LOAD:
      {
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        String plugin1 = WebServer.arg("plugin_129_sensortype");
        Settings.TaskDevicePluginConfig[event->TaskIndex][0] = plugin1.toInt();
        success = true;
        break;
      }
     case PLUGIN_INIT:    
      {
    Serial.begin(115200); // HW Serial for TFmini
    delay (100); // Give a little time for things to start

    
  // Set to Standard Output mode
    Serial.write(0x42);
    Serial.write(0x57);
    Serial.write(0x02);
    Serial.write(0x00);
    Serial.write(0x00);
    Serial.write(0x00);
    Serial.write(0x01);
    Serial.write(0x06);

  
        break;
      }     
 case PLUGIN_TEN_PER_SECOND:
      {    
     while(Serial.available()>=9) // When at least 9 bytes of data available (expected number of bytes for 1 signal), then read
    {
      if((0x59 == Serial.read()) && (0x59 == Serial.read())) // byte 1 and byte 2
      {
        unsigned int t1 = Serial.read(); // byte 3 = Dist_L
        unsigned int t2 = Serial.read(); // byte 4 = Dist_H
        
        t2 <<= 8;
        t2 += t1;
        UserVar[event->BaseVarIndex] = t2;
        String log = F("Dist: ");
        log += t1;
        addLog(LOG_LEVEL_INFO,log); 
    
    
        t1 = Serial.read(); // byte 5 = Strength_L
        t2 = Serial.read(); // byte 6 = Strength_H

        t2 <<= 8;
        t2 += t1;
        UserVar[event->BaseVarIndex + 1] = t2;
        for(int i=0; i<3; i++)Serial.read(); // byte 7, 8, 9 are ignored
      }
  }
    
       
  }
  return success;
}
Any insight on my failure would be appreciated

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Benewake TF-Mini (new device)

#2 Post by TD-er » 04 Jan 2018, 17:00

Code: Select all

        unsigned int t1 = Serial.read(); // byte 3 = Dist_L
        unsigned int t2 = Serial.read(); // byte 4 = Dist_H
        
        t2 <<= 8;
        t2 += t1;
Are you sure this piece of code is actually being executed?
The value of t2 should never get above 65535, given the serial.read() will return an 8 bit value.
So perhaps set the output to 0 before you begin and only return success=true when data is actually being read.

phealt
New user
Posts: 2
Joined: 04 Jan 2018, 02:17

Re: Benewake TF-Mini (new device)

#3 Post by phealt » 04 Jan 2018, 21:48

Thanks I will zero at the onset and maybe add a log entry mid steam.

Seb54
New user
Posts: 2
Joined: 26 May 2019, 18:29

Re: Benewake TF-Mini (new device)

#4 Post by Seb54 » 26 May 2019, 18:34

Hi, Hi @phealt, could you please tell me where am I supposed to paste your code to create a device? Actually I don't manage to use my TF-mini at all
thanks

RaDi
New user
Posts: 1
Joined: 25 Feb 2020, 10:07

Re: Benewake TF-Mini (new device)

#5 Post by RaDi » 25 Feb 2020, 10:39

Hi, I'am an absolute Newbie with ESPEasy. I'am using it since about 4 weeks for instance to count my gas consumption, drive a nextion display via mqtt from iobroker.... . Next step should be a well leveling with the TFMini, because my HM-Sen-Wa-Od(Homematic Level Sensor) i used until now, died. Is there a .bin file existing, wich includes Your TFMini device. I've tried to compile the espeasy myselfe, but I'am to stupide.

Thanks for help
Ralf

Seb54
New user
Posts: 2
Joined: 26 May 2019, 18:29

Re: Benewake TF-Mini (new device)

#6 Post by Seb54 » 19 Apr 2020, 17:28

phealt wrote: 04 Jan 2018, 21:48 Thanks I will zero at the onset and maybe add a log entry mid steam.
Hi, could you please give me the corrected code? Thanks

Post Reply

Who is online

Users browsing this forum: No registered users and 52 guests