Blame | Last modification | View Log | Download
/*Modbus-Arduino Example - TempSensor (Modbus IP)Copyright by André Sarmento Barbosahttp://github.com/andresarmento/modbus-arduino*/#include <SPI.h>#include <Ethernet.h>#include <Modbus.h>#include <ModbusIP.h>//Modbus Registers Offsets (0-9999)const int SENSOR_IREG = 100;//Used Pinsconst int sensorPin = A0;//ModbusIP objectModbusIP mb;long ts;void setup() {// The media access control (ethernet hardware) address for the shieldbyte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };// The IP address for the shieldbyte ip[] = { 192, 168, 1, 120 };//Config Modbus IPmb.config(mac, ip);// Add SENSOR_IREG register - Use addIreg() for analog Inputsmb.addIreg(SENSOR_IREG);ts = millis();}void loop() {//Call once inside loop() - all magic heremb.task();//Read each two secondsif (millis() > ts + 2000) {ts = millis();//Setting raw value (0-1024)mb.Ireg(SENSOR_IREG, analogRead(sensorPin));}}