/////////////////////////////////////////////////// CALIBRATION
| 249 | // CALIBRATION |
| 250 | // |
| 251 | bool INA219::setMaxCurrentShunt(float maxCurrent, float shunt) |
| 252 | { |
| 253 | #define printdebug true |
| 254 | uint16_t calib = 0; |
| 255 | |
| 256 | if (maxCurrent < 0.001) return false; |
| 257 | if (shunt < 0.001) return false; |
| 258 | |
| 259 | // _current_LSB = maxCurrent / 32768; |
| 260 | _current_LSB = maxCurrent * 3.0517578125e-5; |
| 261 | _maxCurrent = maxCurrent; |
| 262 | _shunt = shunt; |
| 263 | calib = round(0.04096 / (_current_LSB * shunt)); |
| 264 | _writeRegister(INA219_CALIBRATION, calib); |
| 265 | |
| 266 | |
| 267 | #ifdef printdebug |
| 268 | Serial.println(); |
| 269 | Serial.print("current_LSB:\t"); |
| 270 | Serial.print(_current_LSB, 8); |
| 271 | Serial.println(" uA / bit"); |
| 272 | |
| 273 | Serial.print("Calibration:\t"); |
| 274 | Serial.println(calib); |
| 275 | Serial.print("Max current:\t"); |
| 276 | Serial.print(_maxCurrent, 3); |
| 277 | Serial.println(" A"); |
| 278 | Serial.print("Shunt:\t"); |
| 279 | Serial.print(_shunt, 8); |
| 280 | Serial.println(" ohm Ω"); |
| 281 | #endif |
| 282 | |
| 283 | return true; |
| 284 | } |
| 285 | |
| 286 | |
| 287 |