Библиотека для доступа к модулю ina219

здавствуйте.

возникла необходимость откалибровать сабж под конкретные сопротивления шунтов. секс с адафруит утомил и результата нет.

покурив тему со старого форума увидел код

 #include <Wire.h>
#include "ina219.h"

INA219 monitor;

void setup() {
  Serial.begin(9600);
  monitor.begin(64); // i2c address 64=0x40
  monitor.configure(0, 1, 3, 3, 7);
 
  /*  конфигурируем режим датчика тока INA219
   *  range, gain, bus_adc, shunt_adc, mode
   *  range = 1 (0-32V bus voltage range)
   *  gain = 3 (1/8 gain - 320mV range)
   *  bus adc = 3 (12-bit, single sample, 532uS conversion time)
   *  mode = 7 (continuous conversion)
   */

  monitor.calibrate(0.100, 0.075, 16, 3); 
 //R_шунта, напряж_шунта, макc_напряж, макс_ток
  }

  
void loop() {

 for (int i=1; i<16; i++){
 delay(300);
 Serial.print(monitor.busVoltage()); Serial.println(" - v");
 Serial.print(monitor.shuntCurrent() * 1000,0);Serial.print(" - ");
}
Serial.println();
}

от димах. меня вполне бы устроила эта библиотека но линк на нее битый. в гитхабе я ее не нашел, может даст кто нормальный линк на эту либу?

не она случайно?

Допишите кто-нибудь что три апострофа надо ставить на отдельной строке!

C:\Users\root\Documents\Arduino\sketch_jan18b\sketch_jan18b.ino: In function ‘void setup()’:
sketch_jan18b:9:21: error: invalid conversion from ‘int’ to ‘INA219::t_range’ [-fpermissive]
9 | monitor.configure(0, 1, 3, 3, 7);
| ^
| |
| int
In file included from C:\Users\root\Documents\Arduino\sketch_jan18b\sketch_jan18b.ino:2:
C:\Users\root\Documents\Arduino\libraries\ina219\src/INA219.h:143:29: note: initializing argument 1 of ‘void INA219::configure(INA219::t_range, INA219::t_gain, INA219::t_adc, INA219::t_adc, INA219::t_mode)’
143 | void configure( t_range range = RANGE_32V, ///< Range for bus voltage.
| ^~~~~~~~~~~
sketch_jan18b:9:24: error: invalid conversion from ‘int’ to ‘INA219::t_gain’ [-fpermissive]
9 | monitor.configure(0, 1, 3, 3, 7);
| ^
| |
| int
In file included from C:\Users\root\Documents\Arduino\sketch_jan18b\sketch_jan18b.ino:2:
C:\Users\root\Documents\Arduino\libraries\ina219\src/INA219.h:144:22: note: initializing argument 2 of ‘void INA219::configure(INA219::t_range, INA219::t_gain, INA219::t_adc, INA219::t_adc, INA219::t_mode)’
144 | t_gain gain = GAIN_8_320MV,///< Set Gain for shunt voltage.
| ~^~~~~~~~~~~~~~~~~
sketch_jan18b:9:27: error: invalid conversion from ‘int’ to ‘INA219::t_adc’ [-fpermissive]
9 | monitor.configure(0, 1, 3, 3, 7);
| ^
| |
| int
In file included from C:\Users\root\Documents\Arduino\sketch_jan18b\sketch_jan18b.ino:2:
C:\Users\root\Documents\Arduino\libraries\ina219\src/INA219.h:145:21: note: initializing argument 3 of ‘void INA219::configure(INA219::t_range, INA219::t_gain, INA219::t_adc, INA219::t_adc, INA219::t_mode)’
145 | t_adc bus_adc = ADC_12BIT, ///< Configure bus voltage conversion.
| ^~~~~~~~~~~~~~~
sketch_jan18b:9:30: error: invalid conversion from ‘int’ to ‘INA219::t_adc’ [-fpermissive]
9 | monitor.configure(0, 1, 3, 3, 7);
| ^
| |
| int
In file included from C:\Users\root\Documents\Arduino\sketch_jan18b\sketch_jan18b.ino:2:
C:\Users\root\Documents\Arduino\libraries\ina219\src/INA219.h:146:21: note: initializing argument 4 of ‘void INA219::configure(INA219::t_range, INA219::t_gain, INA219::t_adc, INA219::t_adc, INA219::t_mode)’
146 | t_adc shunt_adc = ADC_12BIT, ///< Configure shun voltage conversion.
| ^~~~~~~~~~~~~~~
sketch_jan18b:9:33: error: invalid conversion from ‘int’ to ‘INA219::t_mode’ [-fpermissive]
9 | monitor.configure(0, 1, 3, 3, 7);
| ^
| |
| int
In file included from C:\Users\root\Documents\Arduino\sketch_jan18b\sketch_jan18b.ino:2:
C:\Users\root\Documents\Arduino\libraries\ina219\src/INA219.h:147:22: note: initializing argument 5 of ‘void INA219::configure(INA219::t_range, INA219::t_gain, INA219::t_adc, INA219::t_adc, INA219::t_mode)’
147 | t_mode mode = CONT_SH_BUS ///< Sets operation mode.
| ~^~~~~~~~~~~~~~~~
exit status 1
invalid conversion from ‘int’ to ‘INA219::t_range’ [-fpermissive]

либо код слишком старый либо либа не та.

ina219.h

/******************************************************************************
* TI INA219 hi-side i2c current/power monitor Library
*
* http://www.ti.com/product/ina219
*
* 6 May 2012 by John De Cristofaro
*
*
* Tested at standard i2c 100kbps signaling rate.
*
* This library does not handle triggered conversion modes. It uses the INA219
* in continuous conversion mode. All reads are from continous conversions.
*
* A note about the gain (PGA) setting:
*	The gain of the ADC pre-amplifier is programmable in the INA219, and can
*	be set between 1/8x (default) and unity. This allows a shunt voltage 
*	range of +/-320mV to +/-40mV respectively. Something to keep in mind,
*	however, is that this change in gain DOES NOT affect the resolution
*	of the ADC, which is fixed at 1uV. What it does do is increase noise
*	immunity by exploiting the integrative nature of the delta-sigma ADC.
*	For the best possible reading, you should set the gain to the range
*	of voltages that you expect to see in your particular circuit. See
*	page 15 in the datasheet for more info about the PGA.
*
* Known bugs:
*     * may return unreliable values if not connected to a bus or at
*	bus currents below 10uA.
*
* Arduino 1.0 compatible as of 6/6/2012
*
* Dependencies:
*    * Arduino Wire library
*
* MIT license
******************************************************************************/

#ifndef ina219_h
#define ina219_h


#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#include <Wire.h>

#define INA219_DEBUG 1

// INA219 memory registers
#define CONFIG_R		0x00	// configuration register
#define V_SHUNT_R		0x01	// differential shunt voltage
#define V_BUS_R			0x02	// bus voltage (wrt to system/chip GND)
#define P_BUS_R			0x03	// system power draw (= V_BUS * I_SHUNT)
#define I_SHUNT_R		0x04	// shunt current
#define CAL_R			0x05	// calibration register

#define INA_RESET		0xFFFF	// send to CONFIG_R to reset unit

#define CONFIG_DEFAULT		0x399F

// config. register bit labels
#define RST	15
#define BRNG	13
#define PG1	12
#define PG0	11
#define BADC4	10
#define BADC3	9
#define BADC2	8
#define BADC1	7
#define SADC4	6
#define SADC3	5
#define SADC2	4
#define SADC1	3
#define MODE3	2
#define MODE2	1
#define MODE1	0

// default values
#define D_I2C_ADDRESS	0x40 // (64) - адрес по умочанию, перемычки на датчике разомкнуты
#define D_RANGE			1
#define D_GAIN			3
#define D_SHUNT_ADC		3
#define D_BUS_ADC		3
#define D_MODE			7
#define D_SHUNT			0.25
#define D_V_BUS_MAX		6
#define D_V_SHUNT_MAX		0.3
#define D_I_MAX_EXPECTED	1


class INA219
{
  public:
	INA219();
	
	// by default uses addr = 0x40 (both a-pins tied low)
	void begin(uint8_t addr = D_I2C_ADDRESS);

	void calibrate(float r_shunt = D_SHUNT, float v_shunt_max = D_V_SHUNT_MAX, float v_bus_max = D_V_BUS_MAX, float i_max_expected = D_I_MAX_EXPECTED);

	void configure(uint8_t range = D_RANGE, uint8_t gain = D_GAIN, uint8_t bus_adc = D_BUS_ADC, uint8_t shunt_adc = D_SHUNT_ADC, uint8_t mode = D_MODE);

	void reset();

	int16_t shuntVoltageRaw();
	int16_t busVoltageRaw();
	float shuntVoltage();
	float busVoltage();
	float shuntCurrent();
	float busPower();


  private:
	uint8_t i2c_address;
	float r_shunt, current_lsb, power_lsb;
	uint16_t config, cal, gain;

	int16_t read16(uint8_t addr);
	void write16(uint8_t addr, uint16_t data);

};

#endif

ina219.cpp

/******************************************************************************
* TI INA219 hi-side i2c current/power monitor Library
*
* http://www.ti.com/product/ina219
*
* 6 May 2012 by John De Cristofaro
*
*
* Tested at standard i2c 100kbps signaling rate.
*
* This library does not handle triggered conversion modes. It uses the INA219
* in continuous conversion mode. All reads are from continous conversions.
*
* A note about the gain (PGA) setting:
*	The gain of the ADC pre-amplifier is programmable in the INA219, and can
*	be set between 1/8x (default) and unity. This allows a shunt voltage 
*	range of +/-320mV to +/-40mV respectively. Something to keep in mind,
*	however, is that this change in gain DOES NOT affect the resolution
*	of the ADC, which is fixed at 1uV. What it does do is increase noise
*	immunity by exploiting the integrative nature of the delta-sigma ADC.
*	For the best possible reading, you should set the gain to the range
*	of voltages that you expect to see in your particular circuit. See
*	page 15 in the datasheet for more info about the PGA.
*
* Known bugs:
*     * may return unreliable values if not connected to a bus or at
*	bus currents below 10uA.
*
* Arduino 1.0 compatible as of 6/6/2012
*
* Dependencies:
*    * Arduino Wire library
*
* MIT license
******************************************************************************/

#ifndef ina219_h
#define ina219_h


#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#include <Wire.h>

#define INA219_DEBUG 1

// INA219 memory registers
#define CONFIG_R		0x00	// configuration register
#define V_SHUNT_R		0x01	// differential shunt voltage
#define V_BUS_R			0x02	// bus voltage (wrt to system/chip GND)
#define P_BUS_R			0x03	// system power draw (= V_BUS * I_SHUNT)
#define I_SHUNT_R		0x04	// shunt current
#define CAL_R			0x05	// calibration register

#define INA_RESET		0xFFFF	// send to CONFIG_R to reset unit

#define CONFIG_DEFAULT		0x399F

// config. register bit labels
#define RST	15
#define BRNG	13
#define PG1	12
#define PG0	11
#define BADC4	10
#define BADC3	9
#define BADC2	8
#define BADC1	7
#define SADC4	6
#define SADC3	5
#define SADC2	4
#define SADC1	3
#define MODE3	2
#define MODE2	1
#define MODE1	0

// default values
#define D_I2C_ADDRESS	0x40 // (64) - адрес по умочанию, перемычки на датчике разомкнуты
#define D_RANGE			1
#define D_GAIN			3
#define D_SHUNT_ADC		3
#define D_BUS_ADC		3
#define D_MODE			7
#define D_SHUNT			0.25
#define D_V_BUS_MAX		6
#define D_V_SHUNT_MAX		0.3
#define D_I_MAX_EXPECTED	1


class INA219
{
  public:
	INA219();
	
	// by default uses addr = 0x40 (both a-pins tied low)
	void begin(uint8_t addr = D_I2C_ADDRESS);

	void calibrate(float r_shunt = D_SHUNT, float v_shunt_max = D_V_SHUNT_MAX, float v_bus_max = D_V_BUS_MAX, float i_max_expected = D_I_MAX_EXPECTED);

	void configure(uint8_t range = D_RANGE, uint8_t gain = D_GAIN, uint8_t bus_adc = D_BUS_ADC, uint8_t shunt_adc = D_SHUNT_ADC, uint8_t mode = D_MODE);

	void reset();

	int16_t shuntVoltageRaw();
	int16_t busVoltageRaw();
	float shuntVoltage();
	float busVoltage();
	float shuntCurrent();
	float busPower();


  private:
	uint8_t i2c_address;
	float r_shunt, current_lsb, power_lsb;
	uint16_t config, cal, gain;

	int16_t read16(uint8_t addr);
	void write16(uint8_t addr, uint16_t data);

};

#endif

компилируется

Скетч использует 8710 байт (30%) памяти устройства. Всего доступно 28672 байт.
Глобальные переменные используют 534 байт (20%) динамической памяти, оставляя 2026 байт для локальных переменных. Максимум: 2560 байт.

И именно ОБРАТНЫХ апострофа, а не абы каких ))

получается у меня библиотека криво встала? удалил. закрыл иде. скачал из вашего гитхаба еще раз. установил. запустил иде. открыл и попыталься скомпилировать еще раз - ошибки те же самые.

закинь два файла библиотеки в папку со скетчем, да и скетч поправь, у тебя там косяки

ваша библиотека работает с любыми мк? скомпил пример, в порту одни кракозяблы…

а мк какой?
вот ссылка на генератор, там на яндекс диске все библиотеки рабочие

esp8266 плата nodemcu

Я один чтоли его сообщение с выводом ошибок прочел?))
Оно ж прям там КРИЧИТ (ладно, намекает)…

да что там читать усе же работает когда сам пользуешь. а то что в либе изменились форматы в вызове кого волнует чужое горе:
было - monitor.configure(0, 1, 3, 3, 7);
стало - monitor.configure(INA219::RANGE_16V, INA219::GAIN_2_80MV, INA219::ADC_64SAMP, INA219::ADC_64SAMP, INA219::CONT_SH_BUS)

в общем откомпилил. но при использовании вашей библиотеки у меня в мониторе порта одни кракозяблы.

заливаю в плату другой скетч с адафрутовской библиотекой - все в порту нормально показывает.

скорость порта настроил?

понятно, у еспехи скорость меньше 115200 глюки вызывает.

спасибо.

так. костыль с указанием текущего адреса платы так и остался надо править и в файле библиотеки тоже?

и чем ее не устроило явное указание адреса ина - monitor(I2C_ADDR_40) ??

я щас уже не помню, вроде можно не править, давно не заглядывал что там и как

несколько датчиков с этой библиотекой, одновременно работает?