Arduino+Daqfactory+Modbus=Plotting Graph From Arduino Data

Recommended Posts

hye..first of all i am at the lower level of understanding the DAQFacory together with Arduino. Actually this is a very basic question.sorry if its sound stupid.


so my component are Arduino Mega. What i want is to connect the Mega to DAQFactory using Rs232 and display the data of analog pin,also plotting the graph.


yes, i have read a post and the documentation related but still confusing. my bad. :unsure:  


FYI, i try the quick guide for device configuration but when i open the Channel under the LOCAL, there is NO data or graph display..did i miss something?maybe some configuration mistake.only the data at the 'monitor' display the reading.


for the Chn# , what is the exactly for Mega and how to determine that.

device type i choose ModBus RTU

I/O type i just select 'read holding UN-32bits' coz there is no UN-16bit..



thanks in advances. :P

Link to comment
Share on other sites

OK, first, Arduino != Modbus.  Arduino is a processor, or really a computer, just like I am a human.  Modbus is a protocol, like a spoken language, and I'm talking English.  Just because I'm a human does not mean I speak English.  Likewise, just because Arduino's are a computer, does not mean they speak Modbus.  In fact, I doubt an Arduino on its own speaks any language / protocol.  If it has a web server, it speaks http, and maybe ftp, but that's a piece of software (possibly the OS), not arduino.


Anyhow, if you want to connect DAQFactory to an Arduino you need to do a few things:

1) create a program on the Arduino to collect the data you want.

2) in that program, add some code to send out the data over the serial port (if it has one) in some format.  It can be as simple as the current value and a carriage return if you want.  You could code up a Modbus slave, but that's pretty complicated.  As I said, the Arduino doesn't really speak any protocols on its own.  You have to code it.


If you only have an Ethernet port, its a little harder.  Then you are going to have to code up an Ethernet server that DAQFactory can connect to.  It would probably be easier though to enable a web server on the arduino and put the current value in a file on the Arduino file system, then have DAQFactory do a web request for that file and parse the response.


I wish I could say it was easy, but there is a reason Arduino (and raspberry Pi) are cheap: they don't do a lot out of the box, at least not in the DAQ world.  Its usually easier to purchase a cheap PLC like the Click PLC's from automation direct which are < $100, have I/O built in with proper signal conditioning, and already know how to speak Modbus.  Arduinos and Pi's are great if you have a lot of time to code them up to do everything you want, and because you have to code them, you can pretty much do anything (processor power not withstanding), but they are, generally, much harder to use than a purpose built device like the Click PLCs, LabJack DAQ devices and the wide range of other DAQ / industrial automation devices out there.

Link to comment
Share on other sites

wow!! thnks for the very details reply..

yes, i put some code in arduino sketch to read A0 pin and Serial.println the reading. i installed the modbusmaster library in arduino library and uploaded to arduino.done. then i create the channel after configure the devices, device name,connection n etc.for the chn# i used 40001

D# i used 1

and the i/o type i used read holding S16(3)

then i can see the TX : \001\003\000\000\001\132\010 something

and the RX : 1023\013\010

i create the out channel as example. the problem is, nothing come out from the graph or i have to write some code in sequence part? i feel so dumb.  :unsure:

Link to comment
Share on other sites

Again, you don't want to use Modbus, and even though you have the modbusmaster library installed, you aren't using it.  The RX I see is just a text string with a carriage return / line feed at the end.  Also, Modbus Master is backwards, that would be if your Arduino wanted to go out and poll another Modbus device.  You would want a Modbus Slave.  But really, stop worrying about Modbus :).  And don't feel dumb.  No one is born knowing this stuff and I've been doing this a long time.  Now then:


If you delete whatever Modbus channel you created in DAQFactory, I'm assuming you'll see a string of RX:'s in the monitor similar to what you posted.  This would indicate that your code is reading the A0 pin and printing to the serial port correctly.  The new values should appear at whatever loop rate you have coded in the arduino.  Now you just need to parse it.  Its pretty straight forward:


1) create a new channel to hold the new values.  Device type Test, A/D, D# = 0, Chan # = 0, Timing = 0.  The last one is important, make sure Timing = 0.  For my script below, I'll call it simply "myChannel"

2) change the device you created in DAQFactory that you assigned as Modbus to NULL protocol.  I'm going to assume you named the device Ardy (mostly because I'm tired of typing Arduino...)

3) create a sequence to poll the device.  Something like this:

      private string datain = device.ardy.readuntil(10)
      private data = strToDouble(datain)

That should actually be about it.  Just run that sequence and the channel will fill with data.

Link to comment
Share on other sites

hye Guru, thnks for the reply appreciate a lot.  :) .So i try the steps 1-3 and the graph showing this




for the first time get the plotting graph.thnks..but the reading is quite weird.


and i try other way by setting  the D# 1,device type is Modbus,I/O type is Read Input S16(3) and the Chn# is 40001 also for the timing i put 1 secs, this come out from my comm monitor:

Rx (12:50:37.120): \001\003\002\003\255\248\244
Tx (12:50:38.001): \001\003\000\000\000\001\132\010

Rx (12:50:38.047): \001\003\002\003\255\248\244
Tx (12:50:38.048): \001\003\000\000\000\001\132\010

Rx (12:50:38.094): \001\003\002\003\255\248\244
Tx (12:50:39.002): \001\003\000\000\000\001\132\010

Rx (12:50:39.047): \001\003\002\003\255\248\244
Tx (12:50:39.048): \001\003\000\000\000\001\132\010

Rx (12:50:39.094): \001\003\002\003\255\248\244

below is the graph that i obtained,





according to the guideline from DAQFactory pdf file, state that if the RX line show anything other than \001\003 or \001\131 then its a garbage, so..means mine is the actual data from modbus protocols or what? what is exact output should be show up? i understand that the TX command used to read first holding register is it?


FYI, the A0 pin was connected to 5V pins and its value is 1023 when i test in arduino serial monitor.

Link to comment
Share on other sites

In the first graph you forgot to set the Timing to 0, or you did myChannel = someValue.  You are seeing the sine wave that the test device generates, not your own data. 


The second graph and the data transmission looks correct for Modbus.  It is not what you showed in a previous post, so you changed something on the arduino side to accept Modbus.


You should be on your way.  You can see the 1023 on your input channel, and it certainly looks like your Arduino is returning a valid Modbus packet for Holding Register 0.

Link to comment
Share on other sites

Doing myChannel = someValue sends someValue to the Test driver.  The test driver for A to D is designed to generate a sine wave.  When you send it someValue it simply triggers a read and returns the sine wave pattern.  That's why you saw that on your graph.  To add a value to a channel from script without calling the driver you should instead do:




this bypasses the driver and just shoves someValue into the channel.  In most cases MyChannel should have a Timing of 0 so the driver is never called.

Link to comment
Share on other sites

wow..i will try it later n keep update...thnks Guru.

Another things i wanna ask, is after i able to get the value in DAQFactory, i wanna  connect to realtime Webpage (DAQConn). so means i have to change the modbus type to modbus TCP? actually i have Ethernet shield that i want to use that attched with arduino and connect to my pc using usb. is there any specific way to be able to connect my arduino+ethernet shield with DAQConnect? i try put the byte mac,ip address and ping the ip device.done.but the DAQFactory come out with port locked error.


Thanks again  :)

Link to comment
Share on other sites

Do you want to send directly from your Arduino to DAQConnect, or are you going to have DAQFactory do that?  If you want DAQFactory to do it, all you have to do is setup DAQConnect in DAQFactory which is pretty easy.  You would not need to change the Arduino unit at all. 


If you want the arduino to send to DAQConnect then its a little more involved.  You'd need an ethernet port of course, but don't worry about Modbus.  DAQConnect doesn't talk Modbus, it uses web service calls.  You'll need to figure out how to open a socket to the DAQConnect server on port 80 (start simple and skip SSL) and send a web request.  Start by seeing if you can simply get the Arduino to download the html of the DAQConnect home page (or any web page really).  You don't need to do anything with it once you get it, just figure out how to request an html page from a web server somewhere.  Once you can do that, pushing data to DAQConnect is quite easy.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.