Hello.
Found really nice SCADA/HMI software, few limitations on free version but if, with your help my friends i figure out this Modbus system it really is worth for buying.
Here´s the link for the software: Winlog Lite: free SCADA software | SCADA free download.
Yesterday i tested it with two temp sensors attached to Arduino UNO and after many hours got it finally working. Sketch i used is here:
And original sketch was copied here: http://mango.serotoninsoftware.com/forum/posts/list/0/567.page#2721[/size][/size][/size]
#include <ModbusSlave.h>
//TMP36 Pin Variables
int temperaturePin = 2; //the analog pin the TMP36's Vout (sense) pin is connected to
int temperaturePin2 = 3; //the resolution is 10 mV / degree centigrade
//(500 mV offset) to make negative temperatures an option
int temptest = 1 ;
int temptest2 = 1 ;
//Arduino sketch example with 2 holding regs:
void setup()
{
/* Modbus setup example, the master must use the same COM parameters */
/* 115200 bps, 8N1, two-device network */
// regs[MB_REG0]=153;
// regs[MB_REG1]=456;
init_mb_slave(115200, 'n', 0);
}
void loop()
{
/* This is all for the Modbus slave */
start_mb_slave(MB_SLAVE, regs, MB_REGS);
/* your code goes here */
float temperature = getVoltage(temperaturePin); //getting the voltage reading from the temperature sensor
temperature = (((temperature * 5) * 100)); //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
float temperature2 = getVoltage(temperaturePin2);
temperature2 = (((temperature2 * 5) * 100));
// Serial.println(temperature);
// Serial.println(regs[MB_REG0]); //printing the result
// delay(100);
temptest = (temperature);
regs[MB_REG0]=temptest;
temptest2 = (temperature2);
regs[MB_REG1]=temptest2;
/* handle write event */
if (written.num_regs) {
/// ....
written.num_regs=0;
}
}
/*
* getVoltage() - returns the voltage on the analog input defined by
* pin
*/
float getVoltage(int pin){
return (analogRead(pin) * .004882814); //converting from a 0 to 1024 digital range
// to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}
Thing that i really don´t understand is those "regs[MB_REG0]=153; and regs[MB_REG1]=456;".. Are those REGS "memory locations" where i can save analog input readings, so MB_REG0 is temp sensor 1 and MB_REG1 is temp sensor 2 and so on? And what are those values 153 and 456?
Tried to add MB_REG2 but compiler said that MB_REG2 is not declared in this scope.
Winlog gate configuration i used addresses 3:0 for temp sensor 1 and 3:1 for temp sensor 2. Here is part of the Winlog manual for Modbus addressing and no matter how long i read and spell that text it doesn´t make any sense with those Arduino MB_REG addresses...
30011 : Holding register 0011 (16 bit).Obsolete
3:11 : Holding register 11 (16 bit).
3h:Bh : Holding register 11 (16 bit).
3h:10h:Bh : Holding register 11 (16 bit) with write function 10h instead of 6h.
40004 : Input register 0004 (16 bit).Obsolete
4:4 : Input register 4 (16 bit).
4h:4h : Input register 4 (16 bit).
7: Exception Status.
330011 : Holding register 0011 (32 bit float).Obsolete
33:11 : Holding register 11 (32 bit float).
21h:Bh : Holding register 11 (32 bit float).
440004 : Input register 0004 (32 bit float). Obsolete
44:4 : Input register 4 (32 bit float).
2Ch:4h : Input register 4 (32 bit float).
And yet again i spent allmost whole day at work to search information about Arduino Modbus configurations, addresses and everything but without any breakthrough which would cleared this thing in to my mind. So... If here is somebody Modbus <-> Arduino Expert, could you please give some links, hints, example sketches or anything what would clear this problem.