- 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.
TFmini-S data aquisition on MATLAB SIMULINK using arduino UNO
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
can anyone help in measuring distance using TFmini-S attached to arduino UNO
0 comentarios
Respuestas (1)
Aishwarya
el 3 de Jul. de 2024
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:
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
Ver también
Categorías
Más información sobre Modeling en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!