Clear Filters
Clear Filters

Why can't I read the values from LSM9DS1 on-board sensor on Arduino Nano 33BLE in Simulink?

5 views (last 30 days)
Hi there,
I've been trying since weeks now, to read acceleration values in Simulink from the on-board LSM9DS1 sensor of Arduino Nano 33BLE board. I have installed the arduino support packages for both simulink and matlab, and have setup the connection with the board. I tried two approaches and both were unsuccessful:
  1. Adding LSM9DS1 sensor block from simulink's library for the arduino support package and then connecting it with the scope for visualisation. On building and deploying the model, no errors were reported but the scope shows a flat line for all inputs.
  2. Adding a MATLAB function block (below) and connecting the outputs to scope, which gives an error: "Matlab code generation is not supported on arduino nano 33ble sense board."
function [x, y, z] = readAccel()
a = arduino();
lsmobj = lsm9ds1(a, "Bus", 1);
[x, y, z] = readAcceleration(lsmobj);
end
Any guidance/help will be much appreciated?
P.s. Sensor and board are working fine. Tested in Arduino IDE!

Answers (1)

Avni Agrawal
Avni Agrawal on 9 May 2024
I understand that you are trying to read the values from LSM9DS1 on-board sensor on Arduino Nano 33BLE in Simulink. However, first try to run this command in MATLAB command window:
a = arduino()
When using `arduino()` without specifying parameters, MATLAB tries to automatically connect to an Arduino board, which might not always work as expected, especially if you have multiple devices connected or specific board requirements.
If the above line fails, then try to specify port and correct board type as mentioned below:
a = arduino('Port address', 'Nano33BLE');
Replace `'Port address'` with your board's actual port and `'Nano33BLE'` with the correct board type. This ensures MATLAB connects to the right board.
I hope this helps.
  1 Comment
Rohitashva
Rohitashva on 13 May 2024
Thank you for your response.
I tried this approach too, and the project gets build and deployed to the board successfully. But, the Scope and the Data Inspector both shows a flat line. I also tried "Monitor and Tune" but it also shows the value zero for all axes.
On contrary, everthing seems to work fine in Arduino IDE.

Sign in to comment.

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!