Arduino · guide
TFmini-i with Arduino I²C / UART: integration and configuration guide
Setup, connection, configuration and code guidance for TFmini-i with Arduino. The original files are available in Materials and downloads. Documented interface: I²C, UART.
Applicable setup
TFmini-i · Arduino · I²C, UART
Original Chinese technical instructions
多台 TFmini-I²C 在 Arduino 使用的参考方案
Version:v1.0
Update date:2019.04.28
Author:Mincy Zhao
(zhaomingxin@benewake)
目录
1 概述....................................................................................................................................................1
2 测试工具............................................................................................................................................1
3 连接测试............................................................................................................................................1
3.1 设置 TFmin-I²C 地址............................................................................................................. 1
3.2 连接.........................................................................................................................................1
3.3 Arduino 参考代码................................................................................................................... 2
4 测试效果............................................................................................................................................4
1概述 本方案使用 4 台 TFmini-I²C 雷达,通过一组 I²C 总线在 Arduino UNO 开发板进行接收数据。
I²C 通讯采用主从模式,Arduino 开发板作为主机,TFmini-I²C 作为从机。每一台 TFmini 配 置为独立的地址,主机查询对应地址的 TFmini 的数据并等待数据返回。
2测试工具 (1)TFmini-I²C,4 台;
(2)Arduino UNO 开发板,1 块;
(3)5VDC/2A 电源,1 个;
(4)杜邦线,若干。
3连接测试 3.1设置 TFmin-I²C 地址
设置方法可参考《产品说明书》。本方案将 4 台 TFmini 的从机地址分别设置为 0x10、0x11、 0x12 和 0x13。
3.2连接
注意:因为电脑 USB 接口输出电流有限,接多台 TFmini 同时使用需要外接 5V 供电。同时 雷达与 Arduino 开发板需要共地。
1
SCL
SDA
5VDC
3.3Arduino 参考代码
/*This is a reference code about Arduino UNO receive TFmini-I²C Data from I²C bus* Arduino is Master, TFmini-I²C is slave. Master send check
* Author:zhaomingxin@Benewake
* Update date:2019.4.28
*/
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(115200); // start serial for outputpinMode(LED_BUILTIN, OUTPUT);//LED
}
void loop() {Get_LidarDatafromIIC(0x10);
Get_LidarDatafromIIC(0x11);
Get_LidarDatafromIIC(0x12);
2
Get_LidarDatafromIIC(0x13);
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(byte address){
char i = 0;byte rx_buf[7] = {0};
Wire.beginTransmission(address); // Begin a transmission to the I2C Slave device with the given address.
Wire.write(1); // Reg's Address_H
Wire.write(2); // Reg's Address_L
Wire.write(7); // Data LengthWire.endTransmission(0); // Send a START Sign
Wire.requestFrom(address, 7); // request 7 bytes from slave device address
//print the result via serial
Serial.print("Address=0x");
Serial.print(address,HEX);
Serial.print(": ");
while ( Wire.available())
{
rx_buf[i] = Wire.read(); // received one byte
Serial.print("0x");
Serial.print(rx_buf[i],HEX);
Serial.print(";");3
i++;
if(i>=7)
{
i=0;
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]);
}
}
Serial.print("\r\n");
}4测试效果 Arduino 通过 I²C 总线查询雷达数据,再通过串口将数据打印出来。
4
5
Use and verification
The technical content follows the readable source material. Confirm the product hardware revision, flight-stack or software version, and field safety boundary against the original material and current platform documentation.
Materials and downloads
- 多台 TFmini-I²C 在 Arduino 使用的参考方案 · Chinese source (PDF)Complete inquiry to download
