I have worked for most of the day on this problem and have narrowed it down to the following simple program to replicate it: Test.ino
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
}
// the loop function runs over and over again until power down or reset
void loop() {
char _message[16] = { '\0' };
char *message = _message;
int pins[1] = { 1 };
//testOne(pins, 35, 5); // WORKS!!
testTwo(pins, 35, 5, message); // Desn't Work...
}
void testOne(int sensorPins[], int userDefault, int offset) {
char _int_char[2];
sprintf(_int_char, "%d", 36);
Serial.println(_int_char);
}
void testTwo(int sensorPins[], int userDefault, int offset, char *message) {
char _int_char[2];
sprintf(_int_char, "%d", 37);
Serial.println(_int_char);
}
All the above code does is call the testOne and testTwo functions.
The testOne function gives the expected outcome of the value of 36 being written to the serial window for each iteration of the loop.
The testTwo function writes the following to the serial window: "VMDPV_1|1_VMVMDPV_1|1_VM".....
This only happens when I add the char *message parameter to the function. Obviously this is a very simplified demo with hard coded values etc... in my actual code I make use of the parameters and there is a lot more going on...
It is actually the call to sprintf that causes the issues. In my actual code I use this as a part of building up the message. When I comment out the sprintf line in my actual code it works. But of course I need that line to get the value of one of the parameters into the message.
Can anyone out there tell me why sprintf doesn't work in a function that has a char *message param?
I am using an Arduino UNO and have written the code in Visual Studio using Visual Micro 1511.23.1, which does it's bulid based on the installed arduino IDE setup which is 1.6.5.
I have been able to replicate this in the arduino IDE as well, except I get different characters than "VMDPV_1..."... I got a, 3 a letter O with a upside down comma on top and a square.
I am developing all this on a Win 10 64bit PC.
Thanks for your time,
Scott