johanbn2000
Dear All,

Since ESP8266 have I2C support, I wish to used it for some I2C Sensors (e.g BME280) or to add some IO expand on ESP8266.
Is OpenPLC support this use? Do I have to make some changes on ESP8266 code? How?
Please advise and elaborate in more detail.

Your earliest reply will be highly appreciated.
Thank you.
Quote 0 0
thiagoralves
OpenPLC does not support I2C on slave devices. If you wish to add that, you will have to modify the esp8266 firmware and make the I2C data available on the holding registers that are sent to OpenPLC 
Quote 0 0
johanbn2000
Dear Thiagoralves,

Thank you for your prompt reply.
Since I am quite new about this coding thing, can you please elaborate ini more detail how to modifying the esp8266 and how to make data available on holding registers?
Thank you. 
Quote 0 0
johanbn2000
Dear Thiago,

I try to add the 8266 code as follow to learn how the program work, but I can not read (on ScadaBR) the expected value ("100" on offset 101, "1000" on offset 102 and "10000" on offset 103). What I have missed? Please advise.

for (int i = 0; i < sizeof(pinMask_AIN); i++)
{
mb_input_regs[i] = (analogRead(pinMask_AIN[i]) * 64);
}
mb_input_regs[1]=100;
mb_input_regs[2]=1000;
mb_input_regs[3]=10000;

for (int i = 0; i < sizeof(pinMask_AOUT); i++)
{
analogWrite(pinMask_AOUT[i], mb_holding_regs[i] / 64);
}
}

Do I only have change the code on ESP8266 or also need to change code on Raspi?
Please advise or point out where to start by give me some references.

Thank you.
Quote 0 0
thiagoralves
On the Slave Devices page, if you select the “esp8266” option, it comes preconfigured with just one holding register. If your firmware now has more holding registers, you will have to select “generic modbus tcp device” and fill out with exactly the same numbers of the “esp8266” option, but then on size of holding registers you insert 2, or 3, or whatever size of your holding registers on your modified firmware
Quote 0 0
johanbn2000
Dear Thiago,

Thank you for your elaboration.
Now it works as expected.

Thanks
Quote 0 0
johanbn2000
Dear Thiago,

I have successfully reading the BME280 data on ESP8266 from ScadaBR, but the value is in integer format (eg 31C instead 0f 31.25C).
How to change it to 4 byte float? Is float format input supported by ESP8266 Wifi Modbus?
Please advise.

Thank you.
Quote 0 0
thiagoralves
Holding registers are, by definition of modbus protocol, 16 bit variables. You cannot fit a floating point variable on a 16 bit register. What you can do is use two registers to store your entire 32 bit floating point value (harder) or multiply the value by 10 or 100 before storing it on the holding register to capture some of the decimal digits (easier). Just keep in mind that if you do that, 16 bit unsigned integers overflow at 65535.
Quote 0 0