Grove - TF Mini LiDAR With Wio Terminal

by Seeed Studio in Outside > Sports

1537 Views, 4 Favorites, 0 Comments

Grove - TF Mini LiDAR With Wio Terminal

1.png

This product is based on ToF (Time of Flight) principle and integrated with unique optical and electrical designs, so as to achieve stable, precise, high sensitivity and high-speed distance detection.

ToF is the abbreviation of Time of Flight technology, and its operating principle is as follows: a modulated near-infrared light is sent from the sensor and reflected by an object; the distance to the object to be shot can be converted with the sensor by calculating the time difference or phase difference between the light sending and the light reflection, so as to produce the depth information.

In this instructable, we are going to introduce our Grove-TF Mini LiDAR displayed by not only Serial Port of Arduino IDE, but also Wio Terminal, one of the most popular newly-published products of our Seeed Studio!

Please visit our project on the blog for more interesting stories!

Play With Arduino

arduino.png
outcome.png

Materials required:

Steps:

  1. Connect Grove - TF Mini LiDAR to D2 port of Base Shield and connect Seeeduino to PC through a USB cable.
  2. Download the Demo Zip file and copy the whole Seeed_Arduino_TFlidar file and paste it into your Arduino IDE library file.
  3. Copy the demo code from Software below into Arduino IDE and upload.
#include "TFLidar.h"
#define USETFMINI// #define USETFLUNA
#define SERIAL Serial
#if defined(SEEED_XIAO_M0)
    #define uart  Serial1
#elif defined(SEEED_WIO_TERMINAL)
    #define uart  Serial1
#else
    SoftwareSerial uart(2, 3);
#endif

#ifdef USETFLUNA
TFLuna SeeedTFLuna;
TFLidar SeeedTFLidar(&SeeedTFLuna);
#endif

#ifdef USETFMINI
TFMini SeeedTFMini;
TFLidar SeeedTFLidar(&SeeedTFMini);
#endif 

void setup() {
  // put your setup code here, to run once:
  SERIAL.begin(9600);
  while(!Serial);
  SeeedTFLidar.begin(&uart,115200);
}
void loop() {
  while(!SeeedTFLidar.get_frame_data()){
    delay(1); 
  }
  // put your main code here, to run repeatedly:
  SERIAL.print("dist = ");
  SERIAL.print(SeeedTFLidar.get_distance()); //output measure distance value of LiDAR
  SERIAL.print('\t');
  SERIAL.print("strength = ");
  SERIAL.print(SeeedTFLidar.get_strength()); //output signal strength value
#ifdef USETFLUNA
  SERIAL.print("\t Chip Temprature = ");
  SERIAL.print(SeeedTFLidar.get_chip_temperature());
  SERIAL.print(" celcius degree"); //output chip temperature of Lidar
#endif
  SERIAL.println(" ");
  // delay(1000);
}

Success

We will see the distance display on the Serial Port above. The blue curve is the Distance and the red is Strength. You could delete Line 42 to Line 43 of the demo code if only the Distance is required:

SERIAL.print("strength = ");
SERIAL.print(SeeedTFLidar.get_strength()); //output signal strength value<br>

Play With Wio Terminal

wio_terminal_BVBA55fsdH.jpg
pin.png
image-101-1030x787.png
1.png

The previous demos are usually illustrating by Serial ports on Arduino IDE, however, in this PART II, it's going to display on Wio Terminal and prepare to be shocked!

Materials required:

Steps:

  1. Plug Grove-TF-Mini-LiDAR to Wio Terminal via Jumpers and also connect Wio Terminal to PC through a USB cable.
  2. Download the Demo Zip File and copy the whole Seeed_Arduino_Linechart file and paste it into your Arduino IDE library file.
  3. Copy the demo code from Software below into your Arduino IDE.
#include"seeed_line_chart.h" //include the library
#include "TFLidar.h"
#define LINE_DIS 0X00
#define STRING_DIS 0X01
TFMini SeeedTFMini;
TFLidar SeeedTFLidar(&SeeedTFMini);
#define uart  Serial1

TFT_eSPI tft;
 
#define max_size 10 //maximum size of data
doubles data; //Initilising a doubles type to store data
TFT_eSprite spr = TFT_eSprite(&tft);  // Sprite 
 
void setup() {
    Serial.begin(115200);
    pinMode(WIO_KEY_C, INPUT_PULLUP);
    tft.begin();
    tft.setRotation(3);
    spr.createSprite(TFT_HEIGHT,TFT_WIDTH);
    SeeedTFLidar.begin(&uart,115200);
}
uint8_t mode = LINE_DIS;
void loop() {
    
    if (digitalRead(WIO_KEY_C) == LOW) {
        mode ++;
        if(mode > STRING_DIS ) mode = LINE_DIS;
        while(!digitalRead(WIO_KEY_C));
    }
    display(get_Lidar_data(),mode);
    delay(50);
}

uint16_t get_Lidar_data()
{
    while(!SeeedTFLidar.get_frame_data()){
        delay(1); 
    }
    return SeeedTFLidar.get_distance();
}

void display(uint16_t lidar_data,uint8_t mode){

    spr.fillSprite(TFT_WHITE);
    //Settings for the line graph title
    auto header =  text(0, 0)
                .value("Lidar Terminal")
                .align(center)
                .valign(vcenter)
                .width(tft.width())
                .color(green)
                .thickness(3);
    header.height(header.font_height() * 2);
    header.draw(); //Header height is the twice the height of the font
    if (LINE_DIS == mode){
        if (data.size() == max_size) {
            data.pop();//this is used to remove the first read variable
        }
        data.push(lidar_data); //read variables and store in data
    //Settings for the line graph
        auto content = line_chart(10, header.height()); //(x,y) where the line graph begins
            content
                    .height(tft.height() - header.height() * 1.5) //actual height of the line chart
                    .width(tft.width() - content.x() * 2) //actual width of the line chart
                    .based_on(0.0) //Starting point of y-axis, must be a float
                    .show_circle(false) //drawing a cirle at each point, default is on.
                    .value(data) //passing through the data to line graph
                    .color(TFT_RED) //Setting the color for the line
                    .draw();
    }
    else if (STRING_DIS == mode){
        for(int8_t line_index = 0;line_index < 5 ; line_index++)
        {
            spr.drawLine(0, 50 + line_index, tft.width(), 50 + line_index, TFT_GREEN);
        }        
        auto header =  text(0, 0)
                    .thickness(1);
        spr.setFreeFont(&FreeSansBoldOblique24pt7b); 
        spr.setTextColor(TFT_BLUE);
        spr.drawFloat(lidar_data / 100.00,2,80,110);
        spr.drawString(" M",80 + 90,110,1);

    }
    spr.pushSprite(0, 0);

}

Success

An image will display on the screen of Wio terminal as above if everything goes well.