multi-dimentionnal array with several types

Hi everyone

I'm trying to make a LCD-touchscreen interfaced sensor module. The idea is to have up to 9 sensors, interfaced different ways, get the readings, some calculations on them like calibrations, and give one or several outputs in pwm.

I would like to create arrays to store the data, per sensor. There will be up to 48 different data for each.
these data can me names, units, pin numbers, 16bit readings etc... so quite many different types.

i thought about defining structures as i found on another post :

http://forum.arduino.cc/index.php?topic=43587.0

but i think i got the coding wrong and the structure declaration;

struct sensorarraydef {

char sensorName;
char sensorUnit;
short sensorVaue;
short sensorRaw;
char inputType;
char i2cAddress;
byte analogInput;
byte digitalInput;
short timeVar;
short calibX1;
short calibY1;
short calibX2;
short calibY2;
int correctA;
int correctB;
byte correctSensorNumb;
short lowTrigger1;
short highTrigger1;
byte triggerPin1;
int triggerVal1;
short lowTrigger2;
short highTrigger2;
byte triggerPin2;
int triggerVal2;
}record_type;

The next part of the code is pretty long so i just put the begining of it

record_type sensorArray[432];
sensorArray[1].sensorName = sensor1;
sensorArray[1].sensorUnit = mm;
sensorArray[1].sensorValue = 17200;
sensorArray[1].sensorRaw = 61359;
sensorArray[1].inputType = analog;
sensorArray[1].i2cAddress = 0x00;
sensorArray[1].analogInput = A1;
sensorArray[1].digitalInput = 40;
sensorArray[1].timeVar= 23595;
sensorArray[1].calibX1 = 10321;
sensorArray[1].calibY1 = 2630;
sensorArray[1].calibX2 = 58963;
sensorArray[1].calibY2 = 7590;
sensorArray[1].correctA = 0;
sensorArray[1].correctB = 0;
sensorArray[1].correctSensorNumb = 4;
sensorArray[1].lowTrigger1 = 5200;
sensorArray[1].highTrigger1 = 15200;
sensorArray[1].triggerPin1 = 37;
sensorArray[1].triggerVal1 = 255;
sensorArray[1].lowTrigger2 = 5200;
sensorArray[1].highTrigger2 = 15200;
sensorArray[1].triggerPin2 = 37;
sensorArray[1].triggerVal2 = 255;

I'm planning on replacing the [] by the sensor number every time i need to read or write a data at a specific spot
Would anyone have experience in designing such arrays and help me put everything together?

Thank you so much

Damien

Your numeric values are fine, but your strings are not. You need things like

 char* sensorName;

and then

sensorArray[1].sensorName = "sensor1";

You are building an awfully large array which will consume a lot of memory. I hope you have chosen a board that can handle it.

By my count your structure takes 39 bytes. The 432 instances in the array will take a total of 16,884 bytes. The Arduino UNO,for example, only has 2,048 bytes of RAM. What model Arduino were you going to use?

johnwasser:
By my count your structure takes 39 bytes. The 432 instances in the array will take a total of 16,884 bytes. The Arduino UNO,for example, only has 2,048 bytes of RAM. What model Arduino were you going to use?

And that is the current structure which is using 'char' in the place of 'char *' so it is only going to grow....

You might want to check out the Adafruit Common Sensor Library to see how they do it.

With objects you can do things like sensorArray*.readSensor() and it reads that sensor, no matter what type of sensor it is. An object is like a struct except it also has functions that work on the data.*

johnwasser:
By my count your structure takes 39 bytes. The 432 instances in the array will take a total of 16,884 bytes. The Arduino UNO,for example, only has 2,048 bytes of RAM. What model Arduino were you going to use?

That was my first thought when I saw the Title.

I wonder if this is the sort of project in which the Arduino should just collect data and send it to a PC or a RaspberryPI. It will be much easier to manipulate all the data using a higher level language such as Python.

...R

It might be possible to get this data into Uno's memory, but the data structure needs to be redesigned. Most of the data for each reading is associated with the sensor, not the reading, so it will be the same for each reading and waste a lot of memory. For example, the sensor name, pin number, i2c address and calibration values will be the same for every reading from that sensor.

So I think you need two arrays with different structs. One to hold the fixed data on each sensor and another to hold only the minimum fields that are different for each reading from the sensor, plus a sensor number which is the index into the first array.

It may be possible to hold the first array in PROGMEM so that it uses no ram memory.