TFmini-S data aquisition on MATLAB SIMULINK using arduino UNO

조회 수: 1 (최근 30일)
GURPREET
GURPREET 2024년 5월 9일
댓글: GURPREET 2024년 7월 3일
can anyone help in measuring distance using TFmini-S attached to arduino UNO

답변 (1개)

Aishwarya
Aishwarya 2024년 7월 3일
Hi Gurpreet,
According to datasheet of TFmini-S (https://cdn.sparkfun.com/assets/8/a/f/a/c/16977-TFMini-S_-_Micro_LiDAR_Module-Product_Manual.pdf), it follows Serial protocol (UART). The blocks from "Simulink Support Package for Arduino Hardware" can be used for this purpose.
To perform data aquisition in Simulink from TFmini-S sensor connected to Arduino:
  • We can use “Serial Receive” block to receive data from Arduino where TFmini-S sensor is connected.
  • After receiving the data from the block, we can use “MATLAB Function” Block to parse the received data.
  • Below is an example implementation of the function after referring to the data format provided in the datasheet. The function extracts distance, strength, and performs checksum verification. The inputs of the function block "data" and "status" are recieved from "Serial Recieve" block.
function [distance, strength] = parseTFminiSData(data, status)
% Check if the status is 0, indicating that the length of the received data is less than datalength
if status == 0
% If data length is insufficient, set distance to an error value
distance = -1;
strength = -1;
temperature = -1;
return;
end
% Check if the data frame starts with the correct headers
if data(1) == 0x59 && data(2) == 0x59
% Extract distance
distance = double(data(3) + bitshift(data(4), 8));
% Extract strength
strength = double(data(5) + bitshift(data(6), 8));
% Verify checksum
checksum = mod(sum(data(1:8)), 256);
if checksum ~= data(9)
% If checksum does not match, set distance to an error value
distance = -1;
end
else
% If headers do not match, set distance to an error value
distance = -1;
end
end
Kindly note that I could not test the function implementation due to unavailabilty of hardware. But I hope this give a basic idea about the implementation.
For more information on “Serial Receive” block, you can refer to the following documentation: https://www.mathworks.com/help/simulink/supportpkg/arduino_ref/serialreceive.html

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by