Developing a MATLAB/Simulink project with ARDUINO Mega2560

Hello everyone! I am a Mechatronics engineering student and I'm new in the forum so I hope the section will be the correct one for this topic. Anyway, just to briefly introduce myself, my knowledge about Arduino platform is very poor but I would learn quickly, because it seems a very good solution for lots of ideas.

The project: I'm working on Artificial Neural Networks (ANN) applied to SOC estimation in battery packs and, after having developed and tested the project by means of MATLAB/Simulink softwares with good results, it is requested to me to perform the simulations (already completed in Simulink) with the help of an ARDUINO Mega 2560.

I have already installed the packages (both for MATLAB and for Simulink) to directly interface MATLAB and Simulink with my ARDUINO board.

In very few words: I have to send from MATLAB workspace to ARDUINO two dataset timeseries (which are the input of my neural network, generated by myself separately), then I have to process these timeseries with a Simulink-generated block (that simulates the Neural Network, created by the function 'gensim'), and finally I have to save as a plot (or similarly a vector of datapoint) the output of my Neural Network, that is obviously the estimated data for the SOC (State of Charge).
All the parameters have to be sampled at 0.1s and the simulation has to last about 1000s, but I can arbitrarly choose it.

Is it possible to process this kind of project serially? Any hint to develop it?

I have thought to program ARDUINO board in some way to implement the Neural Network Simulink block and then, when I send the timeseries to Arduino, it returns me the estimated output. Or is there any more convenient solution, like a "model-based" programming directly by means of Simulink?

Sorry if they are silly questions but I'm really new to Arduino and with the whole Informatic-world :cold_sweat: .
Thanks everyone for your help. :slight_smile:

The Arduino is generally used for sensing the environment and controlling simple devices.

Which of those tasks would it be doing in your project?

in similar projects I would use the Arduino (or PIC24, dsPIC, PIC32) to sample real world data and transmit it (over serial communcations, WiFi, Ethernet, etc) to a Nerual Network ruuning on a PC which then displays the results

jremington:
The Arduino is generally used for sensing the environment and controlling simple devices.

Which of those tasks would it be doing in your project?

Thanks for your answers; anyway, the task in my project is just processing data that I send to ARDUINO by MATLAB/Simulink and then reading the processed data in MATLAB/Simulink.
The process I want to implement in ARDUINO is already developed in Simulink (and it uses NN).
I want to transmit and receive all the data over serial communication.

have a look at
http://forum.arduino.cc/index.php?topic=396450.0

how much data are you planning to send/receive per second?

horace:
how much data are you planning to send/receive per second?

I have to send and receive 10 samples per second, so I think it is largely feasible, isn't it?

horace:
in similar projects I would use the Arduino (or PIC24, dsPIC, PIC32) to sample real world data and transmit it (over serial communcations, WiFi, Ethernet, etc) to a Nerual Network ruuning on a PC which then displays the results

Anyway, Horace, this is exactly the task required to me, but in my situation data are all previously collected in MATLAB/Simulink thorugh a timeseries coming from some sensors on the model plant developed in Simulink.

10 samples/second via serial line at 115200baud should be OK
once you get to 100s of samples per second you start to look at USB, ethernet or WiFi

horace:
10 samples/second via serial line at 115200baud should be OK
once you get to 100s of samples per second you start to look at USB, ethernet or WiFi

Thank you, do you know if it is possible to program Arduino directly through Simulink just running my Simulink project in external mode, or something like this?

Sorry, guys, I have another question for you. I succeed in running in external mode my Simulink plant in Arduino MEGA, but I can just process 3 arrays of 100 data each from workspace until the memory saturates and there is no way to compile the code.
How can I send all the data (3 timeseries arrays of 10000 elements each) from workspace to Arduino?
Thanks

an Arduino mega with a ATmega2560 has 8Kbytes of SRAM so you should be able to define three arrays of 100 elements of a basic data type such as int or float. What is the array data type?. what is the error message from the compiler?
do you need to load 3 timeseries arrays of 10000 elements each at a time or could you send blcks of data for processing
perhaps you should move to a Rassberry Pi

horace:
an Arduino mega with a ATmega2560 has 8Kbytes of SRAM so you should be able to define three arrays of 100 elements of a basic data type such as int or float. What is the array data type?. what is the error message from the compiler?
do you need to load 3 timeseries arrays of 10000 elements each at a time or could you send blcks of data for processing
perhaps you should move to a Rassberry Pi

Yeah, I succeed in compiling the code and run the project with 3 arrays of 100 elements. The arrays are MATLAB timeseries.

(do you need to load 3 timeseries arrays of 10000 elements each at a time or could you send blcks of data for processing?)
I can send blocks of data, also one element for each array (3 elements at a time) for processing and the data that I have to receive from Arduino is just 1 element at a time. How could I do this operation?
Thank you.

have a look at serial basics
http://forum.arduino.cc/index.php?topic=396450.0

Hey guys,
I've made some steps in the project development. I'll post here the arduino code I'm using for it.
I just want to send data x[0],x[1],x[2] and y and I want to read y2 that is generated by the code in the loop.
Any hint to do this?

(see attachment)

NNarduino.ino (12.2 KB)