<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "Arduino and Mango Step by step working example"]]></title>
		<link>http://forum.infiniteautomation.com/forum/posts/list/13.page</link>
		<description><![CDATA[Latest messages posted in the topic "Arduino and Mango Step by step working example"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Arduino and Mango Step by step working example</title>
				<description><![CDATA[ 1. Buy or make a Arduino <br /> <br /> 2. Download the latest Arduino software I'm using 0020.  http://arduino.cc/en/Main/Software<br /> <br /> 3. If you are using Arduino Duemilanove or a similar board that runs off USB you’ll have to install the USB drivers. You can find them in the Arduino folder you just downloaded.<br /> <br /> 4. plug in a TMP36 temp sensor as shown here:  http://tinyurl.com/plbx38<br /> Plug it into Analog port 3 instead of 0 as shown in the link.  <br /> <br /> 5.  Grab the modbus library from http://www.tucsni.nl/jee/ModbusSlave.zip<br /> you should check his site http://www.tucsni.nl/jee/  he actually says to use the new version here: http://sites.google.com/site/jpmzometa/arduino-mbrt/arduino-modbus-slave<br /> but I havent tested it.<br /> <br /> 6.  Unzip modbusslave.zip to your_arduino_install\libraries\ModBusSlave<br /> <br /> 7.  open the arduino IDE<br /> <br /> 8.  Paste the following code:<br /> [code]#include &lt;ModbusSlave.h&gt;<br /> <br /> //TMP36 Pin Variables<br /> int temperaturePin = 3; //the analog pin the TMP36's Vout (sense) pin is connected to<br />                         //the resolution is 10 mV / degree centigrade <br />                         //(500 mV offset) to make negative temperatures an option<br /> int temptest = 1 ;                        <br /> //Arduino sketch example with 2 holding regs:<br /> void setup()<br /> {<br /> 	  /* Modbus setup example, the master must use the same COM parameters */<br /> 	  /* 115200 bps, 8N1, two-device network */<br /> //	  regs[MB_REG0]=153;<br /> //	  regs[MB_REG1]=456;<br /> <br /> 	  init_mb_slave(115200, 'n', 0);<br /> }<br /> <br /> <br /> void loop()<br /> {<br />     /* This is all for the Modbus slave */<br />     start_mb_slave(MB_SLAVE, regs, MB_REGS);<br /> <br />     /* your code goes here */<br />  float temperature = getVoltage(temperaturePin);  //getting the voltage reading from the temperature sensor<br />  temperature = (((temperature - .5) * 100)*1.8) + 32;          //converting from 10 mv per degree wit 500 mV offset<br />                                                   //to degrees ((volatge - 500mV) times 100)<br /> // Serial.println(temperature);    <br /> // Serial.println(regs[MB_REG0]);    //printing the result<br /> // delay(100);       <br /> temptest = (temperature);<br /> regs[MB_REG0]=temptest;<br /> <br /> <br />     /* handle write event */<br />     if (written.num_regs) {<br />    ///     ....<br /> 	  written.num_regs=0;<br />     }<br /> }  <br /> <br /> /*<br />  * getVoltage() - returns the voltage on the analog input defined by<br />  * pin<br />  */<br /> float getVoltage(int pin){<br /> return (analogRead(pin) * .004882814); //converting from a 0 to 1024 digital range<br />                                         // to 0 to 5 volts (each 1 reading equals ~ 5 millivolts<br /> }<br /> [/code]<br /> <br /> 9. upload the code to your Arduino.<br /> <br /> 10.  Install Mango<br /> <br /> 11.  Create a new data source.  <br /> [url=http://postimage.org/image/1kmj3h7pg/][img]http://s1.postimage.org/rTUni.jpg[/img][/url]<br /> <br /> 12.  Create a new datapoint<br /> [url=http://postimage.org/image/1syvr8io4/][img]http://s3.postimage.org/v_Lji.jpg[/img][/url]<br /> <br /> 13.  you should now be seeing the current temperature updating every 5 seconds on your datapoint.<br /> You can breathe hard on your tmp36 to see the temp go up in mango.<br /> <br /> have fun.<br /> hope this helps somebody as it took me about 2 days of scouring the net to make it finally work.]]></description>
				<guid isPermaLink="true">http://forum.infiniteautomation.com/forum/posts/preList/567/2721.page</guid>
				<link>http://forum.infiniteautomation.com/forum/posts/preList/567/2721.page</link>
				<pubDate><![CDATA[Fri, 1 Oct 2010 20:17:34]]> GMT</pubDate>
				<author><![CDATA[ JointTech]]></author>
			</item>
			<item>
				<title>Re:Arduino and Mango Step by step working example</title>
				<description><![CDATA[ Nice. Thanks.]]></description>
				<guid isPermaLink="true">http://forum.infiniteautomation.com/forum/posts/preList/567/2723.page</guid>
				<link>http://forum.infiniteautomation.com/forum/posts/preList/567/2723.page</link>
				<pubDate><![CDATA[Fri, 1 Oct 2010 23:24:40]]> GMT</pubDate>
				<author><![CDATA[ mlohbihler]]></author>
			</item>
			<item>
				<title>Re:Arduino and Mango Step by step working example</title>
				<description><![CDATA[ Hello.<br /> <br /> I'm trying to compile the sketch buy i get an error in "init_mb_slave(...)" not declared function.<br /> <br /> I think that the library i've got is newer because in new examples the configuration is done in this way:<br /> <br /> mbs.configure(SLAVE,BAUD,PARITY,TXENPIN);<br /> <br /> Can you comment this issue?<br /> thanks]]></description>
				<guid isPermaLink="true">http://forum.infiniteautomation.com/forum/posts/preList/567/2745.page</guid>
				<link>http://forum.infiniteautomation.com/forum/posts/preList/567/2745.page</link>
				<pubDate><![CDATA[Wed, 6 Oct 2010 03:55:04]]> GMT</pubDate>
				<author><![CDATA[ jose francisco]]></author>
			</item>
			<item>
				<title>Re:Arduino and Mango Step by step working example</title>
				<description><![CDATA[ I would use the library here: <a class="snap_shots" href="http://www.tucsni.nl/jee/ModbusSlave.zip" target="_blank" rel="nofollow">http://www.tucsni.nl/jee/ModbusSlave.zip</a><br /> other than that I have no idea.  probably question better for the arduino forums as well.]]></description>
				<guid isPermaLink="true">http://forum.infiniteautomation.com/forum/posts/preList/567/2746.page</guid>
				<link>http://forum.infiniteautomation.com/forum/posts/preList/567/2746.page</link>
				<pubDate><![CDATA[Wed, 6 Oct 2010 04:02:23]]> GMT</pubDate>
				<author><![CDATA[ JointTech]]></author>
			</item>
			<item>
				<title>Re:Arduino and Mango Step by step working example</title>
				<description><![CDATA[ Sketch for new library from http://sites.google.com/site/jpmzometa/arduino-mbrt/arduino-modbus-slave<br /> <br /> With this code you can:<br /> -See the status of pin 2 in mango (MB_REG0)<br /> -set the status of pin 13 with mango (MB_CTRL)<br /> <br /> use offset 0,1,... in mango to use MB_REG0, MB_CTRL, MB_TIME,...<br /> <br /> <br /> <br /> [code]<br /> <br /> #include &lt;ModbusSlave.h&gt;<br /> <br /> /* First step MBS: create an instance */<br /> ModbusSlave mbs;<br /> <br /> /* slave registers */<br /> enum {        <br />         MB_REG0,<br />         MB_CTRL,        /* Led control on, off or blink */<br />         MB_TIME,        /* blink time in milliseconds */<br />         MB_CNT,        /* count the number of blinks */<br />         MB_REGS	 	/* total number of registers on slave */<br /> };<br /> <br /> int asdf=1;<br /> int regs[MB_REGS];<br /> int ledPin = 13;<br /> <br /> <br /> void setup() <br /> {<br />         <br /> /* the Modbus slave configuration parameters */<br /> const unsigned char SLAVE = 1;<br /> const long BAUD = 9600;<br /> const char PARITY = 'n';<br /> const char TXENPIN = 1;<br /> <br />        /* Second step MBS: configure */<br />       mbs.configure(SLAVE,BAUD,PARITY,TXENPIN);<br /> <br />         pinMode(ledPin, OUTPUT);<br />         pinMode(2,INPUT);<br /> }<br /> <br /> void loop()<br /> {<br /> <br /> <br />        asdf=digitalRead(2);<br />       regs[MB_REG0]=asdf;<br /> <br /> <br />   /* Third and las step MBS: update in loop*/<br />        mbs.update(regs, MB_REGS);<br /> <br />    if(regs[MB_CTRL]==1)<br />      digitalWrite(ledPin,1);<br />      else<br />      digitalWrite(ledPin,0);<br /> <br /> }<br /> [/code]<br /> ]]></description>
				<guid isPermaLink="true">http://forum.infiniteautomation.com/forum/posts/preList/567/2756.page</guid>
				<link>http://forum.infiniteautomation.com/forum/posts/preList/567/2756.page</link>
				<pubDate><![CDATA[Thu, 7 Oct 2010 07:16:30]]> GMT</pubDate>
				<author><![CDATA[ jose francisco]]></author>
			</item>
			<item>
				<title>Re:Arduino and Mango Step by step working example</title>
				<description><![CDATA[ Nice I was struggling with setting values.  Ill have to give this a try.]]></description>
				<guid isPermaLink="true">http://forum.infiniteautomation.com/forum/posts/preList/567/2770.page</guid>
				<link>http://forum.infiniteautomation.com/forum/posts/preList/567/2770.page</link>
				<pubDate><![CDATA[Thu, 7 Oct 2010 15:37:13]]> GMT</pubDate>
				<author><![CDATA[ JointTech]]></author>
			</item>
			<item>
				<title>Re:Arduino and Mango Step by step working example</title>
				<description><![CDATA[ Hi, <br /> <br /> I have a one question. I use the modbus serial for comunication. It is script: <br /> <br /> #include &lt;ModbusSlave.h&gt; <br /> /* First step MBS: create an instance */ <br /> ModbusSlave mbs; <br /> /* slave registers */ <br /> enum { <br /> <br /> MB_CTRL, /* Led control on, off or blink */ <br /> MB_TIME, /* blink time in milliseconds */ <br /> MB_CNT, /* count the number of blinks */ <br /> MB_REGS /* total number of registers on slave */ <br /> <br /> }; <br /> <br /> <br /> int regs[MB_REGS]; <br /> int ledPin = 13; <br /> <br /> void setup() <br /> { <br /> <br /> /* the Modbus slave configuration parameters */ <br /> const unsigned char SLAVE = 1; <br /> const long BAUD = 9600; <br /> const char PARITY = 'n'; <br /> const char TXENPIN = 1; <br /> /* Second step MBS: configure */ <br /> mbs.configure(SLAVE,BAUD,PARITY,TXENPIN); <br /> pinMode(ledPin, OUTPUT); <br /> <br /> <br /> } <br /> <br /> void loop() <br /> <br /> { <br /> <br /> /* Third and las step MBS: update in loop*/ <br /> <br /> mbs.update(regs, MB_REGS); <br /> <br /> if(regs[MB_CTRL]==1) <br /> <br /> { <br /> <br /> digitalWrite(ledPin,1); <br /> <br /> } <br /> <br /> else{ <br /> <br /> digitalWrite(ledPin,0); <br /> <br /> } <br /> <br /> } <br /> <br /> <br /> ******************** <br /> But i want a blink effect in led and i modified the script: <br /> <br /> if(regs[MB_CTRL]==1) <br /> { <br /> digitalWrite(ledPin,1); <br /> delay(3000); <br /> digitalWrite(ledPin,0); <br /> delay(3000); <br /> } <br /> else{ <br /> digitalWrite(ledPin,0); <br /> } <br /> } <br /> <br /> Well, when i set the bit 1, the led blink but it don't enter in the else. <br /> <br /> Anyone had the same problem with supervisory and script? <br /> <br /> tank's <br /> <br /> <br /> *sorry, my english is very weak.]]></description>
				<guid isPermaLink="true">http://forum.infiniteautomation.com/forum/posts/preList/567/4835.page</guid>
				<link>http://forum.infiniteautomation.com/forum/posts/preList/567/4835.page</link>
				<pubDate><![CDATA[Fri, 6 Jul 2012 18:54:39]]> GMT</pubDate>
				<author><![CDATA[ relristein]]></author>
			</item>
	</channel>
</rss>