ATmega1280. Put 20 arrays with 800 elements each one by Serial. Should I change?

Hi.

I’m using Pyserial and Arduino ATmega1280.

I have to send 20 arrays with 800 elements each one to Arduino.

I need those 20 arrays to be all “mounted” inside arduino before arduino starts what it should do.

By the first try (single array), when I monitor the values received, Arduino starts printing random values after 20 or 30 elements, instead of my “array” values.

Is that something about the number of elements (my int array has 900 as a size)?

If I try smaller arrays (10 elements) sent through serial… everything works fine.

I tried different delay values and got the same.

Serial from Python and inside Arduino are set to 9600 (I tried different values without any effect).

Should I change the Arduino board?

Should I ignore serial monitor response and assume the values are ok?

Here’s my arduino code:

#define EOP ‘>’
#include<string.h>

char character;
String content = “”;

// sizeOfPositions is the position itself and will be used as the size of the final array.
int sizeOfPositions = 0;

// Stores the elements of the array
int position[999];

void setup(){
Serial.begin(9600);
}

void loop(){

while(Serial.available()) {
character = Serial.read();

// comma separate elements
if ( character == ‘,’ ) {
position[sizeOfPositions] = content.toInt();

// only to show what we got
Serial.println( position[sizeOfPositions] );

delay(4);

// reset content
content = “”;

sizeOfPositions++;
}

// EOP means a ‘>’ char and tell to stop serial reading
else if ( character != ‘,’ && character != EOP ) {
// I’ve found easier to deal with String
content.concat(character);
}

if ( character == EOP ) {
// ‘N’ is only a way to see in the monitor the end of reading
Serial.println( ‘N’ );

content = “”;
break;
}

}
}

Here’s an example of my Python code:

import serial
s = serial.Serial( ‘/dev/ttyUSB0’, 9600, timeout=1 )
values = list( range( 1, 800 ) )
values = list( map( str, values ) )
values = ‘,’.join(values)
values = values + ‘>’
s.write( values.encode() )

s
Alex

20 arrays of integers, 800 elements each?

2 bytes for an integer, times 20 arrays times 800 elements = 32,000 bytes.

The m1280 only has 8196 bytes of SRAM.

Therefore, you need to either not have those arrays in RAM (are they static, ie, can you put them in flash?), or use a different processor (something that's not an AVR, ie, some ARM processor like teensy, arduino zero, etc), or add external RAM to your m1280 - there's info on this around on the internet; the mega2560/1280 has the ability to use external ram - but making use of it requires a bit more effort than normal memory (above mentioned info on internet will explain in more detail)

As for the specific problem you're having, I didn't look hard enough at the code to venture a guess why - I just felt like I should point out that you've got a problem lurking down the road.

After 16 posts you'd think you would have read Nick Gammon's posts on how to post code to this Forum using code tags. Give that a try.

Also, how much SRAM do you think the Arduino has? Let's see...20 arrays of 800 elements is 16,000 and since they are ints, multiply that by 2 for 32,000 bytes on a machine with 8K of SRAM. Or, are you going to put that in progmem?

Add a SPI SRAM to hold the data.
Or an FRAM, non-volatile like EEPROM, but with SRAM read/write access speeds:
http://www.digikey.com/product-search/en/integrated-circuits-ics/memory/2556980?k=fram+memory&k=&pkeyword=fram+memory&pv276=15&FV=2380061%2Cfff40027%2Cfff80434%2C268001d&mnonly=0&newproducts=0&ColumnSort=0&page=1&stock=1&quantity=0&ptm=0&fid=0&pageSize=25
'1280 Max Speed for SPI is 1/2 the system clock speed, so 8 MHz.,

Try removing the 'delay(4)' since there is no throttling on the serial port. If the buffer fills up, characters are thrown away. It might also help to wait until all the reading is done before displaying the data (the Serial.print() may be slowing the reads too much).

Ok.

I've got the situation in the future and I have to think about the limitations.

But If anyone try the code, even using small amount of elements (150 for example, instead of 800) in a single array, still there's wrong values being printed.

I'll change the code and see if I can do something better.

My major concerning is if my board+linux+pc is working fine or if it's a programming limitation.

Telling about the project at all, I have to control 12 motors in different speed, types (servo, stepper etc) and modes of movement repetitions.

I don't know if Arduino is the best option for that.

I'll double check my ideas and try something better.

[]s Alex