48
48
*
49
49
* Version | Date | Developer | Comments
50
50
* ------- | ---------- | ----------- | --------
51
+ * 1.0.8 | 2020-12-01 | SV-Zanshin | Issue #72, allow dynamic memory allocation instead of EEPROM
51
52
* 1.0.7 | 2020-06-30 | SV-Zanshin | Issue #58, changed formatting to use clang-format
52
53
* 1.0.6 | 2020-06-29 | SV-Zanshin | Issue #57, changed case of functions "Alert..."
53
54
* 1.0.5 | 2020-05-03 | SV-Zanshin | Moved setting of maxAmps and shunt to constants
78
79
/* *************************************************************************************************
79
80
** Declare program constants, global variables and instantiate INA class **
80
81
**************************************************************************************************/
81
- const uint32_t SERIAL_SPEED = 115200 ; // /< Use fast serial speed
82
- const uint32_t SHUNT_MICRO_OHM = 100000 ; // /< Shunt resistance in Micro-Ohm, e.g. 100000 is 0.1 Ohm
83
- const uint16_t MAXIMUM_AMPS = 1 ; // /< Max expected amps, values are 1 - clamped to max 1022
84
- uint8_t devicesFound = 0 ; // /< Number of INAs found
85
- INA_Class INA; // /< INA class instantiation
82
+ const uint32_t SERIAL_SPEED{115200 }; // /< Use fast serial speed
83
+ const uint32_t SHUNT_MICRO_OHM{100000 }; // /< Shunt resistance in Micro-Ohm, e.g. 100000 is 0.1 Ohm
84
+ const uint16_t MAXIMUM_AMPS{1 }; // /< Max expected amps, clamped from 1A to a max of 1022A
85
+ uint8_t devicesFound{0 }; // /< Number of INAs found
86
+ INA_Class INA; // /< INA class instantiation to use EEPROM
87
+ // INA_Class INA(0); ///< INA class instantiation to use EEPROM
88
+ // INA_Class INA(5); ///< INA class instantiation to use dynamic memory rather
89
+ // than EEPROM. Allocate storage for up to (n) devices
86
90
87
91
void setup () {
88
92
/* !
@@ -98,22 +102,22 @@ void setup() {
98
102
#ifdef __AVR_ATmega32U4__ // If a 32U4 processor, then wait 2 seconds to initialize
99
103
delay (2000 );
100
104
#endif
101
- Serial.print (" \n\n Display INA Readings V1.0.7 \n " );
105
+ Serial.print (" \n\n Display INA Readings V1.0.8 \n " );
102
106
Serial.print (" - Searching & Initializing INA devices\n " );
103
107
/* ***********************************************************************************************
104
108
** The INA.begin call initializes the device(s) found with an expected ±1 Amps maximum current **
105
109
** and for a 0.1Ohm resistor, and since no specific device is given as the 3rd parameter all **
106
110
** devices are initially set to these values. **
107
111
************************************************************************************************/
108
- devicesFound = INA.begin (
109
- MAXIMUM_AMPS, SHUNT_MICRO_OHM); // Set to the expected Amp maximum and shunt resistance
110
- while (INA. begin (MAXIMUM_AMPS, SHUNT_MICRO_OHM) == 0 ) {
111
- Serial. println ( " No INA device found, retrying in 10 seconds... " );
112
- delay ( 10000 ); // Wait 10 seconds before retrying
113
- } // while no devices detected
114
- Serial.print (" - Detected " );
112
+ devicesFound = INA.begin (MAXIMUM_AMPS, SHUNT_MICRO_OHM); // Expected max Amp & shunt resistance
113
+ while (devicesFound == 0 ) {
114
+ Serial. println ( F ( " No INA device found, retrying in 10 seconds... " ));
115
+ delay ( 10000 ); // Wait 10 seconds before retrying
116
+ devicesFound = INA. begin (MAXIMUM_AMPS, SHUNT_MICRO_OHM ); // Expected max Amp & shunt resistance
117
+ } // while no devices detected
118
+ Serial.print (F ( " - Detected " ) );
115
119
Serial.print (devicesFound);
116
- Serial.println (" INA devices on the I2C bus" );
120
+ Serial.println (F ( " INA devices on the I2C bus" ) );
117
121
INA.setBusConversion (8500 ); // Maximum conversion time 8.244ms
118
122
INA.setShuntConversion (8500 ); // Maximum conversion time 8.244ms
119
123
INA.setAveraging (128 ); // Average each reading n-times
@@ -134,8 +138,8 @@ void loop() {
134
138
static char sprintfBuffer[100 ]; // Buffer to format output
135
139
static char busChar[8 ], shuntChar[10 ], busMAChar[10 ], busMWChar[10 ]; // Output buffers
136
140
137
- Serial.print (" Nr Adr Type Bus Shunt Bus Bus\n " );
138
- Serial.print (" == === ====== ======== =========== =========== ===========\n " );
141
+ Serial.print (F ( " Nr Adr Type Bus Shunt Bus Bus\n " ) );
142
+ Serial.print (F ( " == === ====== ======== =========== =========== ===========\n " ) );
139
143
for (uint8_t i = 0 ; i < devicesFound; i++) // Loop through all devices
140
144
{
141
145
dtostrf (INA.getBusMilliVolts (i) / 1000.0 , 7 , 4 , busChar); // Convert floating point to char
@@ -148,7 +152,7 @@ void loop() {
148
152
} // for-next each INA device loop
149
153
Serial.println ();
150
154
delay (10000 ); // Wait 10 seconds before next reading
151
- Serial.print (" Loop iteration " );
155
+ Serial.print (F ( " Loop iteration " ) );
152
156
Serial.print (++loopCounter);
153
- Serial.print (" \n\n " );
157
+ Serial.print (F ( " \n\n " ) );
154
158
} // method loop()
0 commit comments