I have a very simple program to read the output from an Adafruit INA169 high-side current sensor and report the results to Serial1 (an HC-05 BT module):
If I uncomment the 'analogReadAveraging(4)' line, the program hangs. If I do nothing more than comment this line, the program runs fine, albeit with no averaging. In either case, the program compiles fine. What am I missing here?
TIA,
Frank
Code:
void setup()
{
Serial.begin(115200);
delay(2000); //10/06/21 - just use fixed delay instead
Serial1.begin(115200); //used HC-05 'AT' commands to set this speed
while (!Serial1) {}
pinMode(LED_BUILTIN, OUTPUT);
pinMode(ItotPin, INPUT); //I_total 1V/Amp
//analogReadAveraging(4);
MsecSinceLastLEDToggle = 0;
Serial1.printf("Msec\tADVal\tTotVolts\tTotAmps\n");
}
void loop()
{
if (Serial1.available())
{
CheckForUserInput();
}
if (MsecSinceLastLEDToggle >= 200)
{
MsecSinceLastLEDToggle -= 200;
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//11/01/21 read I_tot value & print out as current
int ItotVal = analogRead(ItotPin);
double ItotVolts = ItotVal * VoltsPerCount;
double ItotAmps = ItotVolts * AmpsPerVolt;
Serial1.printf("%lu\t%d\t%2.2f\t%2.2f\n", millis(), ItotVal, ItotVolts, ItotAmps);
}
}
If I uncomment the 'analogReadAveraging(4)' line, the program hangs. If I do nothing more than comment this line, the program runs fine, albeit with no averaging. In either case, the program compiles fine. What am I missing here?
TIA,
Frank