Usar um sensor i2c (TSL2561) com o arduino e enviar via modbus para o ScadaBR

Alguém sabe como fazer a comunicação de um sensor i2c (TSL2561), do arduino para o ScadaBR? Agradeço desde já pela ajuda.

first of all download SparkFun TSL2561
download ticker library
download modbus library from https://github.com/andresarmento/modbus-arduino
and here is an example:

/* Reading I2C TSL561 and transmitting to ScadaBR ModbusSerial
By issam zait (@issambmsknx) forum.scadabr.com.br
http://forum.scadabr.com.br/t/usar-um-sensor-i2c-tsl2561-com-o-arduino-e-enviar-via-modbus-para-o-scadabr/3930/2

*/
        #include "Ticker.h"
        #include <Modbus.h>
        #include <ModbusSerial.h>
        #include <SparkFunTSL2561.h>
        #include <Wire.h>
        SFE_TSL2561 light;

        ModbusSerial mb;// ModbusSerial object

         float CT,CT1,CT2;
         boolean gain;     // Gain setting, 0 = X1, 1 = X16;
         unsigned int ms;  // Integration ("shutter") time in milliseconds 
         
         void light();
        Ticker timer1(light, 2500);

        void setup() {
            
            mb.config(&Serial, 9600, SERIAL_8N1);// Config Modbus Serial (port, speed, byte format)  
            mb.setSlaveId(1); // Set the Slave ID (1-247) 

            
           mb.addIreg(0); mb.addIreg(1);mb.addIreg(2);mb.addIreg(3);
           light.begin();
            gain = 0;
            unsigned char time = 2;
            light.setTiming(gain,time,ms);   
    timer1.start(); 
        }

        void loop() {
           
            mb.task();//Call once inside loop() - all magic here
            mb.Ireg(0,lux);
            mb.Ireg(1,visible);
            mb.Ireg(2,infrared);
          }
         
          void light() {   
           //TSL2561      
              unsigned int visible, infrared;     
              if (light.getData(visible,infrared)){
                
            double lux;    // Resulting lux value
            boolean good;  // True if neither sensor is saturated
            good = light.getLux(gain,ms,visible,infrared,lux);

          }
     timer1.update();
    }

go to scadabr and make serial modbus data source with 9600 and (serial port number)
make data points 0,1,2 for lux and other parameters.
good luck

1 curtida

sorry i forgot to insert timer1.start(); befor the loop function
and timer1.update(); after the loop function row.
sorry again

Muito Obrigado pela resposta e atenção, agradeço de coração, TY!