How to read 500 readings from analog input block in 1 second in simulink?

Hello all,
I am new to Arduino & Simulink, I want to read 500 analog readings from pin0 in Arduino in 1 second to make a vector of [1 x 500]
and then manipulate with this vector.
The problem is the analog input block in simulink reads only one reading and so generates a vector of size [1 x 1].
if any one can help I would be so grateful :slight_smile: .

It is easier and better and faster to buy and Arduino board and give it a try.
There are many troubles with simulation programs. I have read a lot about simulation troubles on this forum, but I seldom read that it was fixed.

I have already an arduino-uno board , and I am using simulink as it can convert the blocks in simulink into c conde and burn it into the arduino, without actually writing any code.

I am using simulink as it can convert the blocks in simulink into c conde and burn it into the arduino, without actually writing any code.

Except when the simulation program won't do what you want....

It sounds like you are going to have to write some code yourself. I assume that what you are calling a vector is an array. It seems odd that Simulink only allows a one element one dimensional array as that is about as much use a a chocolate teapot and might just as well be a normal variable.

What sort of data do you want to store ? If they are ints them a 500 element array will use half of the memory available on a Uno, which is not a good start. What sort of manipulation do you want to do on the Arduino and how will the results be output ?

I want to store 1 dimension array of ints [1 x 500] , these 500 readings represents an arm movement in 1 second , then I pass them to a neural network to classify which movement is performed and finally I move a servo motor which moves an artificial limb.

these 500 readings represents an arm movement in 1 second

The is about 2 milliseconds to get the request, take a reading and send it to the PC. I do NOT think that that is a realistic expectation.

At whatever rate is possible, it is up to the PC end to loop, asking the Arduino to perform a reading and processing the returned data.

It is NOT an Arduino problem. You should be asking at the Ford dealer.

An Arduino can make 8000 analog samples per second, so 500 is no problem.
The real problem is in the protocol simulink uses / expects.

Can you post the Simulink code (not a visual diagram).

An Arduino can make 8000 analog samples per second, so 500 is no problem.

Taking a reading and ignoring the results, and getting an instruction to take a reading, taking a reading, and sending the results back are two different things. Doing the former 8000 times a second might be reasonable. Doing the latter 8000 times a second is not going to happen.

a analog read is 6 bytes (incl \n\r ) in worst case, sending 6 bytes @115200 baud takes about 0.6 millisecond
making a sample costs about 0.1 millisecond.
so in total it takes 0.7 millisecond, say 1 millisecond. 1000 samples per second and send them is therefore no Arduino problem,

for 500 samples one needs to wait 2 millis between sampels so the main loop looks something like:

uint32_t lastTime;
void setup()
{
  Serial.begin(115200);
  lastTime = millis();
}

void loop()
{
  while ((millis() - lastTime)  < 2);  // wait for 2 ms passed
  lastTime = millis();
  int x = analogRead(A0);  // make a read
  Serial.println(x);  // send it
}

One can even make 4 analogReads and average them (and still make those 500 samples)

If more performance is needed, one could use code like explored here - Experiment - split up analog read in 3 steps - Libraries - Arduino Forum -

The number of samples per second also depends on what the sending app sends to tell the Arduino to take one or more samples, and how long it takes the Arduino to receive and understand that request. None of that information is known. So, it still isn't clear that 500 samples per second is possible.