Hi all.
Just after some info please? Ant know why I can't display neg figures on my lcd from Modbus?
Pos will display and also bits, I can send data from the Arduino to a plc no problems as well.
Also, if the plc spits out any number higher that 280 it will start reading funny numbers on the Arduino lcd.
Many thanks in advance, Steve.
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
#include <SPI.h>
#include <Ethernet.h>
#include <Modbus.h>
#include <ModbusIP.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD.
//Modbus Registers
const int16_t REG1 = 101; // T1
const int16_t REG2 = 102; // T2
const int REG3 = 103; // Output
int16_t holdingRegs1; // T1
int16_t holdingRegs2; // T2
unsigned int holdingRegs3; //Output
ModbusIP mb;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.setBacklight(HIGH);
lcd.setCursor (1,0);
lcd.print ("BOILER -");
lcd.setCursor (0,2);
lcd.print ("IN");
lcd.setCursor (11,2);
lcd.print ("OUT");
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEC };
byte ip[] = { 192, 168, 0, 130 };
mb.config(mac, ip);
mb.addHreg(REG1);
mb.addHreg(REG2);
mb.addCoil(REG3);
}
void loop() {
mb.task();
byte holdingRegs1 = mb.Hreg(REG1);
byte holdingRegs2 = mb.Hreg(REG2);
byte holdingRegs3 = mb.Coil(REG3);
int16_t T1 = holdingRegs1;
int16_t T2 = holdingRegs2;
lcd.setCursor(4,2);
lcd.print(T1 / 10.0, 1);
lcd.setCursor(16,2);
lcd.print(T2 / 10.0, 1);
Serial.println (T1);
if ((holdingRegs3) == 0)
{
lcd.setCursor(10,0);
lcd.print("(STOPPED)");
}
if ((holdingRegs3) == 1)
{
lcd.setCursor(10,0);
lcd.print("(RUNNING)");
}
}