leomariga / simulink-arduino-serial Goto Github PK
View Code? Open in Web Editor NEWHow to connect Arduino and Simulink
How to connect Arduino and Simulink
Dear Leonardo Mariga;
could you please help me solve this problem?
I want to send variables from Simulink to Arduino (for example 7 variables) each variable has a value varying from [0 to 255]
Then, send these variables from Arduino to Simulink.
https://drive.google.com/drive/folders/1G1Gq4NzOqOURmDxV1TbSAQAeoBhJWKgF?usp=sharing
Thank you for your support.
when I try to use this code with an arduino which has servo motor connected to it, I got servo motor turning randomly when I try to start or close the simulation!!
I have tried your code to control a stepper motor through matlab, but I have a problem where the motor keeps running away all the time turns out the getFloat() keeps returning a inf number when not connected to anything. Im not sure where my problem lies here are the code that I used to recreate the problem.
`// Create a union to easily convert float to byte
typedef union{
float number;
uint8_t bytes[4];
} FLOATUNION_t;
// Create the variables you want to receive
FLOATUNION_t myValue1;
FLOATUNION_t myValue2;
FLOATUNION_t myValue3;
FLOATUNION_t myValue4;
FLOATUNION_t myValue5;
FLOATUNION_t myValue6;
// Create the variables to send
FLOATUNION_t send1;
FLOATUNION_t send2;
FLOATUNION_t send3;
void setup() {
// initialize serial, use the same boudrate in the Simulink Config block
Serial1.begin(115200);
}
void loop(){
// Get the floats from serial
myValue1.number = getFloat(); // Give your float a value
myValue2.number = getFloat(); // Give your float a value
myValue3.number = getFloat(); // Give your float a value
myValue4.number = getFloat(); // Give your float a value
myValue5.number = getFloat(); // Give your float a value
myValue6.number = getFloat(); // Give your float a value
// Do whatever you want here
Serial1.println(myValue1.number);
Serial1.println("GAE");
//Serial1.println(myValue1);
// Send some variables back
send1.number = myValue1.number+myValue2.number;
send2.number = myValue3.number+myValue4.number;
send3.number = myValue5.number+myValue6.number;
// Print header: Important to avoid sync errors!
Serial1.write('A');
// Print float data
for (int i=0; i<4; i++){
Serial1.write(send1.bytes[i]);
}
for (int i=0; i<4; i++){
Serial1.write(send2.bytes[i]);
}
for (int i=0; i<4; i++){
Serial1.write(send3.bytes[i]);
}
// Print terminator
Serial1.print('\n');
// Use the same delay in the Serial Receive block
delay(50);
}
float getFloat(){
int cont = 0;
FLOATUNION_t f;
while (cont < 4 ){
f.bytes[cont] = Serial1.read() ;
cont = cont +1;
}
return f.number;
}`
Hi there,
Work done in this repository is commendable and useful for real-world applications
I am exploring the feasibility of incorporating the data acquisition method proposed in this repository through Simulink Desktop Real-Time. The current approach needs to be revised for higher data rates, such as 1000 Samples/Second.
Please see the thread below:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.