Effacer les filtres
Effacer les filtres

TFmini-S data aquisition on MATLAB SIMULINK using arduino UNO

14 vues (au cours des 30 derniers jours)
GURPREET
GURPREET le 9 Mai 2024
Commenté : GURPREET le 3 Juil 2024 à 14:20
can anyone help in measuring distance using TFmini-S attached to arduino UNO

Réponses (1)

Aishwarya
Aishwarya le 3 Juil 2024 à 11:27
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
  1 commentaire
GURPREET
GURPREET le 3 Juil 2024 à 14:20
thank you for the solution, I will try and will update you.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by