Is it possible to send a Configuration File viz. conf.json
that can be sent to the Arduino Yun via Ethernet and a Python Program can parse the configuration and set for example Sampling Rate of a Sensor which is connected to the 32u4?
The problem for me is that Sampling Rate in the Arduino Sketch is actually a preprocessor directive and I understand that C++/Arduino Sketches need to be compiled once before the changes take place.
However, how can I change the preprocessor directive in the sketch using a configuration file?
e.g.
#define SAMPLE_RATE (100)
in a conf.json
file somewhere there might be:
{"sample_rate": 1000}
Once the .json
file is parsed using python is it possible to change
#define SAMPLE_RATE (100) // to #define SAMPLE_RATE (1000)
1 Answer 1
You can't. You'll have to change your macro into a variable and change that variable when suitable data is received through the serial port.
You may also have to trigger a reconfiguration of whatever software is doing the sampling, or reconfigure the hardware, depending on what it is you are sampling.
-
What if I had the Sketch on the Yun on an SD Card and use
sed
to check the parameters and compile the code again using command line?Shan-Desai– Shan-Desai2017年12月15日 14:16:10 +00:00Commented Dec 15, 2017 at 14:16 -
That would just be plain nasty. Using a variable instead of a #define should be simple enough, depending on what you are doing in your code with that value.Majenko– Majenko2017年12月15日 14:16:55 +00:00Commented Dec 15, 2017 at 14:16
-
I think you are right in this sense. I might as well use the Atheros microprocessor as a middleware to store the data and then do stuff on python and nodejs scripts than on the Microcontroller. Thanks for the insightShan-Desai– Shan-Desai2017年12月15日 14:20:03 +00:00Commented Dec 15, 2017 at 14:20