Hi,
My question relates to whether I am using the right type of external memory to overcome the 2kb SRAM limitation of a Pro Mini Arduino.
I have a working program which calculates the distance from a GPS device to the centres of greens on a golf course. The same for the tee positions.
To do this I defined arrays as indicated at the bottom of the sample code attached to store the green and tee positions in PROGMEM so as to leave sufficient SRAM for the program to run. All good.
Using PROGMEM there is only sufficient Flash memory to hold the green and tee longitude and latitude locations for two 36 hole golf courses.
I would like to add many more courses and thought that a way to approach it would be to increase the SRAM by adding a 23LC1024 SRAM chip and moving the location coordinates into float arrays. I have attached an example of working code using the chip with sample coordinates data. However, the array itself is using SRAM in the Pro Mini before I write or read from the chip. 14% program spaced used. 68% of dynamic memory used.
Am I going about this the wrong way... if so should I be using an SD card or something else to store the green and tee coordinates?
I havent included the working code for the GPS device as my question relates to the approach I need to adopt. Hope you can point me in the right direction. Thanks.
/* Example program for use with SRAMsimple.h
Arduino Uno Memory Expansion Sample Program
Author: J. B. Gallaher 07/09/2016
Library created and expanded by: D. Dubins 12-Nov-18
Sample program to use a Serial SRAM chip to expand memory for an Arduino Uno
giving access to an additional 128kB of random access memory. The 23LC1024 uses
the Serial Peripheral Interface (SPI) to transfer data and commands between the
UNO and the memory chip.
Used the following components:
(1) Arduino Uno
(2) Microchip 23LC1024 SPI SRAM chip soldered on an Arduino Protoshield
Wiring:
23LC1024 - Uno:
---------------
Pin1 (JSC) -- Pin 10 (CS) (with 10K pullup to +5V)
Pin2 (SO) -- Pin 12 (MISO)
Pin3 (NU) -- 10K -- +5V
Pin4 (GND) -- GND
Pin5 (SI) -- Pin 11 (MOSI)
Pin6 (SCK) -- Pin 13 (SCK)
Pin7 (HOLD) -- 10K -- +5V
Pin8 (V+) -- +5V
*/
#include <SRAMsimple.h>
#define CSPIN 10 // Default Chip Select Line for Uno (change as needed)
SRAMsimple sram; // initialize an instance of this class
/******************* Create some dummy data to read and space to write ******************/
float course1[144]={53.039684, 53.040735, 53.042010, 53.043283, 53.042638, 53.042123, 53.041194, 53.042149, 53.040581, 53.039136, 53.039510, 53.038168, 53.036910, 53.037994, 53.038401, 53.038762, 53.040113, 53.040829,
53.038859, 53.041617, 53.039538, 53.041357, 53.039134, 53.036690, 53.035390, 53.038362, 53.038284, 53.037287, 53.033159, 53.031944, 53.033840, 53.032987, 53.033292, 53.037766, 53.035190, 53.034329,
-1.112773, -1.113041 , -1.111765, -1.109521, -1.107617, -1.105827, -1.106187, -1.109229, -1.110978 ,-1.113907, -1.115656, -1.117544, -1.118477, -1.120237 , -1.122386, -1.119661, -1.117290, -1.113927,
-1.111218, -1.108807 , -1.104452, -1.109921, -1.103770, -1.106340, -1.107702, -1.101375, -1.105623, -1.109488 ,-1.111114, -1.109271 ,-1.103507, -1.113029 , -1.118557, -1.120239, -1.116245, -1.112965,
53.040672, 53.041553, 53.042700, 53.042504, 53.041670, 53.040984, 53.041813, 53.041663, 53.039494, 53.039933, 53.038707, 53.036828, 53.038009, 53.037866, 53.038559, 53.039394, 53.040492, 53.039702,
53.041007, 53.040095, 53.041160, 53.038965, 53.036787, 53.035696, 53.037962, 53.038615, 53.038529, 53.033940, 53.032291, 53.033423, 53.033471, 53.033202, 53.037311, 53.035035, 53.034245, 53.037850,
-1.111855, -1.111844 , -1.109603, -1.108493, -1.106184, -1.104746, -1.107943, -1.111127, -1.111701 ,-1.115381, -1.117052, -1.117028, -1.119418, -1.121357 , -1.119989, -1.117529, -1.114624, -1.113892,
-1.110199, -1.105100 , -1.108813, -1.105050, -1.105849, -1.107745, -1.102287, -1.103322, -1.110582, -1.111838, -1.109510, -1.103518, -1.110553, -1.117063 , -1.120566, -1.117050, -1.114829, -1.111439,
/* 6,18,25,26,29,24,24,26,24,25,26,28,26,20,24,24,24,32,28,20,25,27,30,32,27,21,27,22,27,21,29,20,19,27*/};
//float course2[]={....};
float read_data_course1[144]; // array to hold data read from memory
void setup()
{
uint32_t address = 0; // create a 32 bit variable to hold the address (uint32_t=long)
byte value; // create variable to hold the data value read
byte data; // create variable to hold the data value sent
Serial.begin(9600); // set communication speed for the serial monitor
SPI.begin(); // start communicating with the memory chip
/************ Write a Float Array *******************/
Serial.println("nWriting float array: ");
sram.WriteFloatArray(0, course1, 144); // Write array f to memory starting at address 0
/************ Read Float Array **********/
Serial.println("Reading float array: ");
sram.ReadFloatArray(0, read_data_course1, 144); // Read from memory into empty array read_data_f
for(int i=0; i<144; i++){ // Output read data to serial monitor
Serial.println(read_data_course1[i],7);
}
}
void loop()
{
}
/*
const PROGMEM float tee[][2][36]={
//latititude for each tee course0 RAMSDALE PAR 3 & MAIN
{{53.039684, 53.040735, 53.042010, 53.043283, 53.042638, 53.042123, 53.041194, 53.042149, 53.040581, 53.039136, 53.039510, 53.038168, 53.036910, 53.037994, 53.038401, 53.038762, 53.040113, 53.040829,
53.038859, 53.041617, 53.039538, 53.041357, 53.039134, 53.036690, 53.035390, 53.038362, 53.038284, 53.037287, 53.033159, 53.031944, 53.033840, 53.032987, 53.033292, 53.037766, 53.035190, 53.034329},
// longitude for each tee course0
{-1.112773, -1.113041 , -1.111765, -1.109521, -1.107617, -1.105827, -1.106187, -1.109229, -1.110978 ,-1.113907, -1.115656, -1.117544, -1.118477, -1.120237 , -1.122386, -1.119661, -1.117290, -1.113927,
-1.111218, -1.108807 , -1.104452, -1.109921, -1.103770, -1.106340, -1.107702, -1.101375, -1.105623, -1.109488 ,-1.111114, -1.109271 ,-1.103507, -1.113029 , -1.118557, -1.120239, -1.116245, -1.112965},
},
//latititude for each tee course1 COTGRAVE SIGNATURE & CHAMPIONSHIP
{{52.926893, 52.927419, 52.923112, 52.923708, 52.927406, 52.923926, 52.925145, 52.929541, 52.929206, 52.931885, 52.932508, 52.929935, 52.928434, 52.931981, 52.928973, 52.930898, 52.928579, 52.928438,
52.927061, 52.928722, 52.930366, 52.929003, 52.925830, 52.924842, 52.923677, 52.923548, 52.926520, 52.925408, 52.923039, 52.925331, 52.927002, 52.926409, 52.926041, 52.923609, 52.925860, 52.928375},
// longitude for each tee course1
{-1.061620, -1.056573 , -1.055452, -1.052043, -1.053902, -1.054336, -1.054799, -1.054504, -1.060684, -1.057377, -1.059471, -1.066385, -1.062466, -1.058602 , -1.060568, -1.057459, -1.054637, -1.055769,
-1.063495, -1.069493 , -1.067178, -1.070643, -1.068884, -1.068852, -1.062787, -1.057743, -1.062316, -1.060170, -1.055718, -1.060155, -1.057558, -1.063100 , -1.065324, -1.063210, -1.066276, -1.068248}
},
};
//cot third tee: 52.923112, -1.055452. Close to Home: 52.892500, -0.960600
*/