Doc capteur lidar BENEWAKE TF02-PRO

Bonjour, j'utilise des capteurs TF02-PRO sur la même liaison I2C.
Dans la doc il parle de 3.3V pour la liaison et dans une de leur doc il relit directement SDA/SCL à un Arduino, je leur ai envoyé un courrier pour savoir si 5V c'était bon ou pas, réponse c'est BON, ouf.
Ils m'ont aussi donné un petit programme pour gérer 2 capteurs sur la même liaison I2C.
Je n'avais rien trouvé sur le net à ce sujet.
Faites en bonne usage.
A plus.

/*This is a reference code about Arduino UNO receive TFseries Lidar I²C Data from I²C bus
 * Arduino is Master, TFseries Lidar-I²C is slave. Master send command to TFmini Plus
 * Before test IIC,you should config TFminiPlus from TTL default to IIC mode.
 * Update date:2021.6.26
 * This is for free.
 */
#include <Wire.h>

void setup() {
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(115200);  // start serial for output print
  pinMode(LED_BUILTIN, OUTPUT);//LED
//  GetLidarVersionFromIIC(0x10);//Get #0x10 Lidar's firmware version.
//  delay(100);
//  SetLidarFrequenceFromIIC(0x10 , 100);//Set #0x10 Lidar's output frame rate to 100Hz. //If you don't need to set the frame rate, please comment this line.
//  delay(100);
 
// You can set the slave ID via below codes
/*
  ChanegLidarSlaveID(0x19,0x10);
  delay(100);
  SaveLidarSetFromIIC(0x10);//Save #10 Lidar`s set.
  delay(100); */
}

void loop() {
  Get_LidarDatafromIIC(0x10);//Get #10 Lidar measurment result from IIC;
  delay(125);
  Get_LidarDatafromIIC(0x11);//if you connect
  delay(125);
  
 // delay(250);
// digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
//  delay(250); 
//  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
}

void Get_LidarDatafromIIC(unsigned char address){
  char i = 0; 
  unsigned char rx_buf[9] = {0}; 
  unsigned char check_sum = 0;
  Wire.beginTransmission(address); // Begin a transmission to the I2C Slave device with the given address. 
  Wire.write(0x5A); // see product mannual table 11:Obtain Data Frame
  Wire.write(0x05); // 
  Wire.write(0x00); // 
  Wire.write(0x01); // 
  Wire.write(0x60); // 
  Wire.endTransmission();  // Send a START Sign
  Wire.requestFrom(address, 9 , 1); // request 9 bytes from slave device address

  //Read IIC data and save to rx_buf[]
  Serial.print("Address=0x");
  Serial.print(address,HEX);
  Serial.print(":   ");
  memset( rx_buf, 0, sizeof( rx_buf));
   while ( Wire.available()) 
  { 
    rx_buf[i] = Wire.read(); // received one byte 
    Serial.print("0x");
    Serial.print(rx_buf[i],HEX);
    Serial.print(";");
    i++; 
  }
  //Judge and print result via serial
    for(i=0;i<8;i++)
      check_sum += rx_buf[i];
   if(rx_buf[0] == 0x59 && rx_buf[1] == 0x59 &&  rx_buf[8] == check_sum)
   {
      Serial.print("---------->");
      Serial.print("Distance=");
      Serial.print(rx_buf[3]*256+rx_buf[2]);
      Serial.print(";");
      Serial.print("Strength=");
      Serial.print(rx_buf[5]*256+rx_buf[4]);
   }
   else
   {
      Serial.print("Maybe something wrong to Get Lidar`s data.");   
   }
  Serial.print("\r\n"); 
}

void GetLidarVersionFromIIC(unsigned char address)
{
  char i = 0; 
  unsigned char rx_buf[7] = {0}; 
  unsigned char check_sum = 0;
  Wire.beginTransmission(address); // Begin a transmission to the I2C Slave device with the given address. 
  Wire.write(0x5A); // see product mannual table 11:Obtain Data Frame
  Wire.write(0x04); // 
  Wire.write(0x01); // 
  Wire.write(0x5f); // 
  Wire.endTransmission();  // Send a START Sign 
  Wire.requestFrom(address, 7 , 1); // request 9 bytes from slave device address
  //Read IIC data and save to rx_buf[]
   while ( Wire.available()) 
  { 
    rx_buf[i] = Wire.read(); // received one byte 
    Serial.print("0x");
    Serial.print(rx_buf[i],HEX);
    Serial.print(";");
    i++;
   }
   //Judge and print result via serial
   for(i=0;i<6;i++)
      check_sum += rx_buf[i];
   if(rx_buf[0] == 0x5A && rx_buf[1] == 0x07 && rx_buf[2] == 0x01 && rx_buf[6] == check_sum)
   {
      Serial.print("    The Lidar firmware version is v");
      Serial.print(rx_buf[5],HEX);
      Serial.print(".");
      Serial.print(rx_buf[4],HEX);
      Serial.print(".");
      Serial.print(rx_buf[3],HEX);    
   }
   else
   {
      Serial.print("Check version error!");
   }

    
  Serial.print("\r\n"); 
}

void SetLidarFrequenceFromIIC(unsigned char address,byte frequence)
{
  char i = 0; 
  unsigned char rx_buf[6] = {0}; 
  unsigned char check_sum = 0;
  unsigned char fre_L , fre_H;
  fre_L = frequence;
  fre_H = frequence>>8;
  Wire.beginTransmission(address); // Begin a transmission to the I2C Slave device with the given address. 
  Wire.write(0x5A); // see product mannual table 11:Obtain Data Frame
  Wire.write(0x06); // 
  Wire.write(0x03); // 
  Wire.write(fre_L); // 
  Wire.write(fre_H); // 
  Wire.write(0x5A+0x06+0x03+fre_L+fre_H); // 
  Wire.endTransmission();  // Send a START Sign 
  Wire.requestFrom(address, 6 , 1); // request 9 bytes from slave device address
  //Read IIC data and save to rx_buf[]
   while ( Wire.available()) 
  { 
    rx_buf[i] = Wire.read(); // received one byte 
    //Print the rx_buf data via serial
    Serial.print("0x");
    Serial.print(rx_buf[i],HEX);
    Serial.print(";");
    i++; 
   }
   //Judge and print result via serial
   for(i=0;i<5;i++)
    check_sum += rx_buf[i];
   if(rx_buf[0] == 0x5A && rx_buf[1] == 0x06 && rx_buf[2] == 0x03 && rx_buf[5] == check_sum)
   {
      Serial.print("    Lidar's frame rate has been set to ");
      Serial.print(rx_buf[3] + rx_buf[4]*256,DEC);
      Serial.print("Hz");
   }
   else
   {
      Serial.print("Set frame rate error!");
   }

  Serial.print("\r\n"); 

}
void ChanegLidarSlaveID(unsigned char address,byte SlaveID)
{
  char i = 0; 
  unsigned char rx_buf[5] = {0}; 
  unsigned char check_sum = 0;

  Wire.beginTransmission(address); // Begin a transmission to the I2C Slave device with the given address. 
  Wire.write(0x5A); // see product mannual table 11:Obtain Data Frame
  Wire.write(0x05); // 
  Wire.write(0x0B); // 
  Wire.write(SlaveID); //    
  Wire.write(0x5A+0x05+0x0B+SlaveID); // 
  Wire.endTransmission();  // Send a START Sign 
  Wire.requestFrom(address, 5 , 1); // request 5 bytes from slave device address
  //Read IIC data and save to rx_buf[]
   while ( Wire.available()) 
  { 
    rx_buf[i] = Wire.read(); // received one byte 
    //Print the rx_buf data via serial
    Serial.print("0x");
    Serial.print(rx_buf[i],HEX);
    Serial.print(";");
    i++; 
   }
   //Judge and print result via serial
   for(i=0;i<4;i++)
    check_sum += rx_buf[i];
   if(rx_buf[0] == 0x5A && rx_buf[1] == 0x05 && rx_buf[2] == 0x0B && rx_buf[4] == check_sum)
   {
      Serial.print("    Lidar's SlaveID has been set to ");
      Serial.print( rx_buf[3],HEX);
   }
   else
   {
      Serial.print("Set SlaveID error!");
   }

  Serial.print("\r\n"); 

}

void SaveLidarSetFromIIC(unsigned char address)
{
  char i = 0; 
  unsigned char rx_buf[5] = {0}; 
  Wire.beginTransmission(address); // Begin a transmission to the I2C Slave device with the given address. 
  Wire.write(0x5A); // see product mannual table 11:Obtain Data Frame
  Wire.write(0x04); // 
  Wire.write(0x11); // 
  Wire.write(0x6f); // 
  Wire.endTransmission();  // Send a START Sign 
  Wire.requestFrom(address, 5 , 1); // request 9 bytes from slave device address
  //Read IIC data and save to rx_buf[]
   while ( Wire.available()) 
  { 
    rx_buf[i] = Wire.read(); // received one byte 
    Serial.print("0x");
    Serial.print(rx_buf[i],HEX);
    Serial.print(";");
    i++; 
   }
   //Judge and print result via serial
   if(rx_buf[0] == 0x5A && rx_buf[1] == 0x05 && rx_buf[2] == 0x11 && rx_buf[3] == 0x00 && rx_buf[4] == 0x70)
   {
       Serial.print("    Lidar's set has been saved");
   }
   else
   {
      Serial.print("Save error!");
   }

  Serial.print("\r\n"); 
}

2 Likes

bonsoir

comment êtes vous passé du mode uart au mode I2C? je n'y arrive pas avec l'outil TFDS fournit par benewake

ps : je souhaite utiliser le tf02-pronavec un arduino uno

Merci

1 Like

Bonjour, tu as raison, avant d'utiliser l'I2C, il faut faire une manip à partir du TFDS.
Il faut d’abord programmer le TF02, pour cela et à partir du TFDS, il faut lui envoyer une première commande pour lui dire de passer en I2C et une deuxième pour sauvegarder le changement.
Tu trouve tout ça dans la doc d'utilisation du TF02 chez Benewake.
Vas sur le site de Benewake, en haut vas dans Ressource Center-Technical Support, choisis le capteur dans la liste, maintenant tu as toutes les docs disponible, dans TF02-Pro_User Manual il y a tout ce qu'il faut savoir pour pouvoir dialoguer avec le capteur.
Juste ne pas oublier le Save Setting sinon les modifs sont perdus à la prochaine coupure de courant.
Fait attention avec l'UNO, j'ai eu des problèmes de liaison en utilisant SofwareSerial, des fois des erreurs dans les données reçut, problème résolue avec le MEGA.
Amuse toi bien et si besoin repasse.

Top. Merci pour ton aide. Ça a marché.

Cordialement
Thierry

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