s-function builder Simulink for Arduino

조회 수: 11 (최근 30일)
EB
EB 2020년 6월 4일
댓글: SRance 2020년 9월 30일
I am trying to build an s-function builder for the LSM6DS3 IMU with the following Arduino code:
#include <Arduino_LSM6DS3.h>
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (true); // halt program
}
Serial.println("IMU initialized!");
}
void loop() {
float aX, aY, aZ;
float gX, gY, gZ;
const char * spacer = ", ";
if (
IMU.accelerationAvailable()
&& IMU.gyroscopeAvailable()
) {
IMU.readAcceleration(aX, aY, aZ);
IMU.readGyroscope(gX, gY, gZ);
Serial.print(aX); Serial.print(spacer);
Serial.print(aY); Serial.print(spacer);
Serial.print(aZ); Serial.print(spacer);
Serial.print(gX); Serial.print(spacer);
Serial.print(gY); Serial.print(spacer);
Serial.println(gZ);
delay(1000);
}
}
Data Properties, I deleted the input ports since I will not have any, and added an output port with a random name with uint32 (only because it was suggested in the reference example link below).
I put this in the Libraries Includes:
#include <math.h>
# ifndef MATLAB_MEX_FILE
# include <Arduino.h>
#include <Arduino_LSM6DS3.h>
# endif
Outputs:
if(xD == 1)
# ifndef MATLAB_MEX_FILE
ana[0] = analogRead(A0);
# endif
Update:
if (xD[0] != 1)
xD[0] = 1;
When I compile it, I get the following error code:
C:\Users\ASDFGHJKL\Documents\MATLAB\Examples\R2020a\IoT_wrapper.c: In function 'IoT_Outputs_wrapper':
C:\Users\ASDFGHJKL\Documents\MATLAB\Examples\R2020a\IoT_wrapper.c:47:4: error: 'xD' undeclared (first use in this function)
if(xD == 1)
^~
C:\Users\ASDFGHJKL\Documents\MATLAB\Examples\R2020a\IoT_wrapper.c:47:4: note: each undeclared identifier is reported only once for each function it appears in
C:\Users\ASDFGHJKL\Documents\MATLAB\Examples\R2020a\IoT_wrapper.c:52:1: error: expected expression before '}' token
}
^
What should I modify to get this to display all six values?
Reference:
  댓글 수: 1
SRance
SRance 2020년 9월 30일
Your outputs needs to specify the element, i.e: if(xD[0] == 1)
You also need to bracket your functions with the { } on the outputs and update.
For reference, even if you have a constant you will need to reference it like a C array.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by