Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1]   Go Down
Author Topic: array size limit  (Read 371 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

  My UNO sketch uses an array of int to store the state of a data pin I want to poll.
How many samples can I store and does it depend on memory I have used elsewhere?
First I tried this:
int array[1000];
The program compiled but would not run.
I finally realized the code would work if I declared a smaller array.
int array[800];

So currently it works with an array size of 800 but if I use more memory by declaring more variables will that reduce my maximum array size even further?

-steve
Logged

Offline Offline
Edison Member
*
Karma: 51
Posts: 1734
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The UNO has 2kB of static ram which is where that array and all other global variables and the program stack go. An array of 800 ints is 1600 bytes which should leave you enough but as you add more global variables that will eventually push you over the limit again.
If you are using character strings, for example in Serial.print statements, those are also stored in static ram unless you force them to be stored in flash ram (along with the program code).

Pete
Logged

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3453
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So currently it works with an array size of 800 but if I use more memory by declaring more variables will that reduce my maximum array size even further?

Yes.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 555
Posts: 27683
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can go to a bigger chip - '1284P has 16K SRAM, biggest of any of the 8-bit AVRs.
I sell these bare boards that you can build up. Thinking of offering as kits, or maybe assembled boards.

http://www.crossroadsfencing.com/BobuinoRev17
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: