We are back to central heating controllers I am afraid.
My electronic one has been working for 25 years based on a number of logic equations extracted from a truth table of inputs and outputs. The logic is implemented in relay switch diode logic. On the basis of it working without a fault for that time begs the question of why change, and indeed I will configure the hardware side such that I can change the plugs over to keep the system running while the updated system gets over it’s teething problems.
I have a wood burning stove, an oil boiler and intend fitting panels in the roof for the summer hot water.- the oil boiler has just been replaced, and it’s that plus the panels that justify a more adjustable system.
The new system I have pseudo-coded is quite short as I see no point in a display, nor am I sensing temperature with the Arduino. I have programmed in C around 20+ years ago so that is not a problem.
The area I require assistance on is that having thought of using a .h file for the truth table, I realised that any changes there would involve recompiling the program. So my thoughts are to write the short binary truth table onto an SD card, and to load that on boot up if the version data is different.
But then where am I going to read the file too, and how do I ‘seek’ through it?
At the moment the file is nominally 2 times 50 8 bit bytes. The system uses the group data input interrupt to detect a change – after debounce / dealing with RFI interference, the input byte is sought and the corresponding output byte for pumps, valves etc. implemented.
So four questions:-
-
The one above – where am I go load the file too to avoid the really slow SD card read?
-
How do I call it up to ‘seek’ through the file?
-
If I press the Nano ‘reset’ button will the program re-boot such that I can implement a read of the SD card ?
-
Having never messed around with bytes before, do I treat an 8 bit byte as one item or is it automatically half of a 16 bit byte.?
I’ve done a fair bit of reading here for my answers but not got the right search data obviously!!
Put a representation of your table in a text file on the SD card.
I would use something human readable to make it easy to fix up with a text editor on a big computer.
On the Arduino, open that file and read through it piece by piece, parsing it to determine the contents of the local table.
There are several libraries for dealing with SD cards on the Arduino, they let you open/read/write files just like you may have done before. What kind of programming did yo do that makes you confidant that it will not be a problem> I ask because it seems odd that you inquire about bytes… 
Your table is very small, so it can just be an array of bytes laid out however you like.
How were you doing it with the *.h file? Were not those values stored in an array somehow?
BTW bytes are 8 bits here. And they are "automatically" or artificially the component part out of which are made integers of 16 and 32 bits, for example, or floating point numbers or text strings or anything else being stored or manipulated.
You can get large swathes of this working before you ever upload to the Arduino. If you write the code in a sensible modular fashion, any of several on-line C/C++ interpreters will allow you to test the basic functions involved in taking text and processing it to make the table.
You could do the same for the logic of the program.
I highly recommend that approach. Finding errors in this kind of thing can be a challenge. Since the Arduino uses standard language, with some care the logic can be perfected without the constant need to upload. Just beware that the resources (speed and memory) of the Arduino are vastly limited. Write with some attention to keeping things small and processor friendly.
--> What have you written (coded, I mean) so far? Perhaps a glimpse of how this is intended to function all up would be helpful to us.
a7
robgraham:
So four questions:-
The one above – where am I go load the file too to avoid the really slow SD card read?
Just load it over the array of bytes you defined in the .h file. I would certainly read the data into RAM, but for not for speed reasons - Central heating decisions don't need microsecond timing.
How do I call it up to ‘seek’ through the file?
As already noted - there's an SD library so you can use the same old functions you would use to read a file on a PC.
If I press the Nano ‘reset’ button will the program re-boot such that I can implement a read of the SD card ?
Yes. Read it in the setup function.
Having never messed around with bytes before, do I treat an 8 bit byte as one item or is it automatically half of a 16 bit byte.?
A byte is eight bits on an Arduino (and every other computer I've ever used).
Personally, I wouldn't feel constrained to use the same truth table methodology - I'd just write the new controller from scratch, using it as a guide. It might well be clearer that way. YMMV.
Thanks guys - I'll follow that through.
The problem I see with just writing the 'table' into the code is that, yes I know how the current system did work, but I don't really know how the summer heating panels will fit in plus the new boiler has features I want to explore.
I feel I am best to go down the input/output truth table file route on an SD card such that I will be able to implement an upgrade to the sequencing of the CH system without having to connect up to the processor to install a freshly compiled program, with the hazards that represents.
I think I rather muddied the waters in that I referred to a. .h file. That was an earlier way of doing it and it was to avoid the re-compilation of each upgrade that I would like to go down the SD card route.
My problem with bytes was more one of age, the length of time since doing any programming and lack of familiarity with micro-processors.