Proper format for storing values (with image)

I need some advice how to best receiving and storing data in maybe a multidimensional struct.
I'm trying to explain what I would like to do.

There are a max. of 63 sensors. They can be paired with a max. of 63control boxes.
Now I have a remote and would like to check which sensors are connected to control box 1, control box 2 etc
So in the maximum there will be 63x63 Bytes that the remote needs to store temporarily

Which structure would you advise to use? The used mcu is a samd21g (arduino zero)

What processor are you using…?
(edit, just saw the SAMD)

63x63 bytes is just under 4000 bytes… if you’re storing 16 or 32 bit values, you’re in even deeper per array.

Depending on what you’re storing, you might run out of memory, or already have.

An SD card, or bigger memory model might be necessary.

What are you doing with the data once collected? If you are just displaying it, you don't need to save it at all.
The simpliest: as you fetch values from box 1, you print the directly as they come in. Repeat for all boxes.
less simple: You get an entire "packet" from box 1 so you have at most 63 values. Print and move to next box
least simple: You store all "packets" from all boxes - requires lots of space

Can't each control box report which sensors it's attached to? Then to assemble the complete table, you just poll all the boxes... If you use dynamic lists, you can have variable length storage for each box, then you don't always have to allocate 63x63 data items. This is especially attractive if the number of sensors each box can access is less than 63.

Do you need to know which sensor(s) is (are) attached to which controller? Or, which controller is associated with each sensor? If the latter, a simple array of 63 bytes will do just fine (assuming each sensor can only be attached to one and only one controller).

Hi, thanks for your replies and sorry for reaching back to you late.
I'm trying to answer your follow-up questions

So far I'd only like to display it with my remote. Later I'd like to add a monitoring device (connected via wireless as well) that collects all the information on a sd card.
I think I first will go with your "less simple" suggestion. In few cases I will reach the maximum amount of control boxes. Average is around 10 I guess.

That's the goal so far, yes.

I need to know which sensors are attached to each controller. The sensors can be attached to several controller at the same time.


I think you could use a simple 1 dimensional array of 63 elements (bytes). Each element (i.e index) in the array represents 1 sensor. The contents of the array element hold the controller number.

That way you can scan the array for each occurrence of a particular controller and the index into the array tells you the sensor number. You would need to add 1 to the index value as your array would have elements 0 to 62.

This assumes that a sensor can only be connected to 1 controller, but 1 controller can be connected to 1 or more sensors.

As far as the controller reporting back, you would need to decide the maximum number of sensors each controller could connect to. If it's 63, then you could configure your comms protocol to handle a 63 byte packet plus whatever packet overhead you need (packet id, length etc).

EDIT: having re-read the posts, it looks like you have a many to many relationship between controllers and sensors

Do you need to hold all the data or just the data from one controller at a time?

If you are using a SAMD21, then variable storage may not be such an issue compared to a 328p...

Or use a container data structure with dynamic-allocation.

In case of the remote I think now that I can hold the data from one controller at a time and fetch the other controller on demand. For the later case with my monitoring device where I need to store all data, I could use a EEPROM or directly write to a sd card.

You're right but I'm unsure as I don't know what libraries I use are doing with my storage/ram. I experienced some wild behavior with a 328P in the past where I run out of ram from time to time and everything crashed. I'd like to avoid it and make sure I have a reliable format/protocol for data handling in that case

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.