I still do not get it.
I tried reading this thread THIS but I can not for the life of me figure out how it is do be done.
I have a INA219 current sensor…
WinTR Scada - Link - Link2
I have ethernet shield and modbus library for Arduino - Modbus .
Everything is setup and I can read any register from the Arduino and control holding registers adjust set points. All int, bytes and bools.
What I want to do is read the current sensor through modbus. So I need to write the value to two 16bit registers. I tried using low byte en high byte from here but does not work.
So what I do is multiply by 100 and then send the int over modbus, in the master I do linear scaling. It works, but not if the current is a negative number.
From the Simply Modbus website - Here gives example like…
Register 40108 could also be combined with 40109 to form any of these 32-bit data types:
A 32-bit unsigned integer (a number between 0 and 4,294,967,295)
40108,40109 = AE41 5652 = 2,923,517,522
So I will be testing… Mb.MbData[0],Mb.MbData[1] = 30.11; as soon as I get home today.
#include <Wire.h>
#include <Adafruit_INA219.h>
#include <SPI.h>
#include <Ethernet.h>
#include "MgsModbus.h"
MgsModbus Mb;
int inByte = 0; // incoming serial byte
byte mac[] = {0x90, 0xA2, 0xDA, 0x0E, 0x94, 0xB5 };
IPAddress ip(192, 168, 0, 10);
IPAddress subnet(255, 255, 255, 0);
Adafruit_INA219 ina219;
int Current_int;
void setup(void)
{
Ethernet.begin(mac, ip, subnet);
uint32_t currentFrequency;
ina219.begin();
ina219.setCalibration_16V_400mA();
}
void loop(void)
{
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
loadvoltage = busvoltage + (shuntvoltage / 1000);
current_int = current_mA * 100; //This shifts the decimal point 2 places to the right
//9.40mA * 100 = 940 / In the master I just scale it.
Mb.MbData[0] = current_mA; //Here is the problem
Mb.MbData[1] = Current_int; //mA can reach 3200, so 3200*100 overflows this data type
Mb.MbsRun();
delay(2000);
}