<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
<link rel="self" type="application/atom+xml" href="http://forum.robosavvy.com/feed.php?f=17&amp;t=3695" />

<title>RoboSavvy Forum</title>
<subtitle>Robosavvy Forum: The largest online community of Humanoid Robot Builders</subtitle>
<link href="http://forum.robosavvy.com/index.php" />
<updated>2010-01-01T07:25:18+01:00</updated>

<author><name><![CDATA[RoboSavvy Forum]]></name></author>
<id>http://forum.robosavvy.com/feed.php?f=17&amp;t=3695</id>
<entry>
<author><name><![CDATA[Chaosmann]]></name></author>
<updated>2010-01-01T07:25:18+01:00</updated>
<published>2010-01-01T07:25:18+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=24393#p24393</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=24393#p24393"/>
<title type="html"><![CDATA[Re: I2C sample code for Devantech SRF08/SRF10 UltraSonic Ran]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=24393#p24393"><![CDATA[
Hi, have got a brand new SRF08 yesterday so I wanted to test it with the code above.<br />But after hours I found out that the first i2c0master_StartN call in the loop have to write to 0xE1 instead on 0xE0.<br /><br />I've just written an example for Linux which reads the value from the light sensor:<br /><br /><dl class="codebox"><dt>Code: </dt><dd><code>#include &lt;iostream&gt;<br />#include &lt;stdio&gt;                               // for in-/output<br />#include &lt;unistd&gt;                             // for usleep<br />#include &quot;include/roboard.h&quot;<br /><br />#define SRF08Address 0xE0<br /><br />using namespace std;<br /><br />void GotoXY&#40; int x, int y &#41; &#123;<br />    printf&#40;&quot;%c&#91;%d;%df&quot;,0x1B,y,x&#41;;<br />&#125;<br /><br />void SRFStart&#40; int add &#41; &#123;<br />    i2c0master_StartN&#40; add&gt;&gt;1, I2C_WRITE, 2 &#41;;<br />    i2c0master_WriteN&#40; 0 &#41;;<br />    i2c0master_WriteN&#40; 0x51 &#41;;<br />&#125;<br /><br />unsigned SRFReadLight&#40; int add &#41; &#123;<br />    //START with address 0xe0&gt;&gt;1 to write 1 bytes<br />    i2c0master_StartN&#40; &#40;add+1&#41;&gt;&gt;1, I2C_WRITE, 1 &#41;;<br />    //set RESTART to read 2 bytes after I2C writing<br />    i2c0master_SetRestartN&#40; I2C_READ, 1 &#41;;<br />    i2c0master_WriteN&#40; 1 &#41;;<br />    return i2c0master_ReadN&#40;&#41;;<br />&#125;<br /><br />int main&#40; void &#41; &#123;<br />    unsigned b1, b2;<br /><br />    printf&#40; &quot;\f&quot; &#41;; // clear the screen<br /><br />    if &#40;i2c_Initialize&#40;I2CIRQ_DISABLE&#41; == false&#41; &#123;<br />        printf&#40;&quot;fail to initialize I2C &#40;%s&#41;!&quot;, roboio_GetErrMsg&#40;&#41;&#41;;<br />        return -1;<br />    &#125;<br /><br />    printf&#40; &quot;set I2C speed to 400Kbps&quot; &#41;;<br />    i2c0_SetSpeed&#40; I2CMODE_AUTO, 400000 &#41;;<br />    do &#123;<br />        SRFStart&#40; SRF08Address &#41;;<br />        usleep&#40; 200000 &#41;;<br />        GotoXY&#40; 1,2 &#41;; cout &lt;&lt; SRFReadLight&#40; SRF08Address &#41; &lt;&lt; &quot;  &quot; &lt;&lt; endl;;<br />    &#125; while &#40; true &#41;;<br /><br />    i2c_Close&#40;&#41;;<br />    return 0;<br />&#125;<br /></code></dd></dl><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1823">Chaosmann</a> — Fri Jan 01, 2010 7:25 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[roboard]]></name></author>
<updated>2009-12-09T11:00:05+01:00</updated>
<published>2009-12-09T11:00:05+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23646#p23646</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23646#p23646"/>
<title type="html"><![CDATA[I2C sample code for Devantech SRF08/SRF10 UltraSonic Ranger]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23646#p23646"><![CDATA[
According to the provisions of the SRF10,you can change address by only one method:<br />Send commands in the correct sequence to the command register at location 0, which means 4 separate write transactions on the I2C bus.<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1542">roboard</a> — Wed Dec 09, 2009 11:00 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Tsai Sung Yang]]></name></author>
<updated>2009-12-08T17:22:09+01:00</updated>
<published>2009-12-08T17:22:09+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23618#p23618</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23618#p23618"/>
<title type="html"><![CDATA[I2C sample code for Devantech SRF08/SRF10 UltraSonic Ranger]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23618#p23618"><![CDATA[
It works!! Thank you!  <img src="http://forum.robosavvy.com/images/smilies/icon_biggrin.gif" alt=":D" title="Very Happy" /> <br />So the function can only write 2 byte at a time?<br /><br /><blockquote><div><cite>roboard wrote:</cite><br />You can try to send each command to register at location 0 like following code:<br /><dl class="codebox"><dt>Code: </dt><dd><code>  i2c0master_StartN&#40;0xE0&gt;&gt;1, I2C_WRITE, 2&#41;;<br />  i2c0master_WriteN&#40;0&#41;;<br />  i2c0master_WriteN&#40;0xA0&#41;;// 1st in sequence to change I2C address <br />  i2c0master_StartN&#40;0xE0&gt;&gt;1, I2C_WRITE, 2&#41;;<br />  i2c0master_WriteN&#40;0&#41;;<br />  i2c0master_WriteN&#40;0xAA&#41;;// 2st in sequence to change I2C address </code></dd></dl><br />last to 0xE2<br /><br />Reference:SRF10 Ultra sonic range finder<br /><!-- m --><a class="postlink" href="http://www.robot-electronics.co.uk/htm/srf10tech.htm">http://www.robot-electronics.co.uk/htm/srf10tech.htm</a><!-- m --><br /></div></blockquote><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1767">Tsai Sung Yang</a> — Tue Dec 08, 2009 5:22 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[roboard]]></name></author>
<updated>2009-12-08T11:57:13+01:00</updated>
<published>2009-12-08T11:57:13+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23613#p23613</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23613#p23613"/>
<title type="html"><![CDATA[I2C sample code for Devantech SRF08/SRF10 UltraSonic Ranger]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23613#p23613"><![CDATA[
You can try to send each command to register at location 0 like following code:<br /><dl class="codebox"><dt>Code: </dt><dd><code>  i2c0master_StartN&#40;0xE0&gt;&gt;1, I2C_WRITE, 2&#41;;<br />  i2c0master_WriteN&#40;0&#41;;<br />  i2c0master_WriteN&#40;0xA0&#41;;// 1st in sequence to change I2C address <br />  i2c0master_StartN&#40;0xE0&gt;&gt;1, I2C_WRITE, 2&#41;;<br />  i2c0master_WriteN&#40;0&#41;;<br />  i2c0master_WriteN&#40;0xAA&#41;;// 2st in sequence to change I2C address </code></dd></dl><br />last to 0xE2<br /><br />Reference:SRF10 Ultra sonic range finder<br /><!-- m --><a class="postlink" href="http://www.robot-electronics.co.uk/htm/srf10tech.htm">http://www.robot-electronics.co.uk/htm/srf10tech.htm</a><!-- m --><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1542">roboard</a> — Tue Dec 08, 2009 11:57 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Tsai Sung Yang]]></name></author>
<updated>2009-12-08T17:23:13+01:00</updated>
<published>2009-12-07T11:16:53+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23598#p23598</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23598#p23598"/>
<title type="html"><![CDATA[I2C sample code for Devantech SRF08/SRF10 UltraSonic Ranger]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=23598#p23598"><![CDATA[
Hi, I was trying to set up two SRF10, so I need to change one's address which default is 0xE0.<br /><br />I tried above code and added this:<br /><br /><dl class="codebox"><dt>Code: </dt><dd><code>i2c0master_StartN&#40;0xe0&gt;&gt;1, I2C_WRITE, 5&#41;;<br />i2c0master_WriteN&#40;0&#41;;     // Command<br />i2c0master_WriteN&#40;0xA0&#41;;  // 1st in sequence to change I2C address<br />i2c0master_WriteN&#40;0xAA&#41;;  // 2st in sequence to change I2C address<br />i2c0master_WriteN&#40;0xA5&#41;;  // 3st in sequence to change I2C address<br />i2c0master_WriteN&#40;0xE2&#41;;  // New address<br /></code></dd></dl>   <br /><br />but seems doesn't work, its address is still 0xE0  <img src="http://forum.robosavvy.com/images/smilies/icon_confused.gif" alt=":?" title="Confused" /><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1767">Tsai Sung Yang</a> — Mon Dec 07, 2009 11:16 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[roboard]]></name></author>
<updated>2009-07-10T06:23:12+01:00</updated>
<published>2009-07-10T06:23:12+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=20666#p20666</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=20666#p20666"/>
<title type="html"><![CDATA[Re: I2C sample code for Devantech SRF08/SRF10 UltraSonic Ran]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=20666#p20666"><![CDATA[
An additional remark: The old RoBoIO library v1.5b has a bug in I2C lib. To run the above sample correctly, you need to download the fix version of RoBoIO library v1.5b from the RoBoard website.<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1542">roboard</a> — Fri Jul 10, 2009 6:23 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[roboard]]></name></author>
<updated>2009-08-17T13:05:27+01:00</updated>
<published>2009-07-10T06:14:42+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=20665#p20665</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=20665#p20665"/>
<title type="html"><![CDATA[I2C sample code for Devantech SRF08/SRF10 UltraSonic Ranger]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=3695&amp;p=20665#p20665"><![CDATA[
Some people asked us how to interfacing with SRF08/SRF10 UltraSonic Ranger by RoBoard. This is easy using RoBoIO library; the following is a brief sample code.<br /><br /><dl class="codebox"><dt>Code: </dt><dd><code>#include &lt;stdio.h&gt;<br />#include &lt;conio.h&gt;<br /><br />#include &lt;roboard.h&gt;<br /><br />//you need to change this function for Linux and DOS<br />void wait_ms&#40;unsigned long ms&#41; &#123;<br />    unsigned long nowtime = GetTickCount&#40;&#41;;<br />    while &#40;&#40;GetTickCount&#40;&#41; - nowtime&#41; &lt;= ms&#41;;<br />&#125;<br /><br />int main&#40;void&#41; &#123;<br />    unsigned b1, b2;<br /><br />    if &#40;i2c_Initialize&#40;I2CIRQ_DISABLE&#41; == false&#41;<br />    &#123;<br />        printf&#40;&quot;fail to initialize I2C &#40;%s&#41;!\n&quot;, roboio_GetErrMsg&#40;&#41;&#41;;<br />        return -1;<br />    &#125;<br /><br />    printf&#40;&quot;set I2C speed to 400Kbps\n\n&quot;&#41;;<br />    i2c0_SetSpeed&#40;I2CMODE_STANDARD, 400000L&#41;;<br /><br />    do<br />    &#123;<br />        printf&#40;&quot;send SRF ranging command\n&quot;&#41;;<br /><br />        //START with address 0xe0&gt;&gt;1 to write 2 bytes<br />        i2c0master_StartN&#40;0xe0&gt;&gt;1, I2C_WRITE, 2&#41;;<br /><br />        //Note: the SRF device address 0xe0 actually contains the I2C r/w bit,<br />        //      so we divide it by 2 to get the correct I2C slave address;<br />        //      see the I2C lib section of RoBoard SW intro. slide for more details.<br /><br />        i2c0master_WriteN&#40;0&#41;;       //set SRF command register<br />        i2c0master_WriteN&#40;81&#41;;      //set ranging Mode - result in cm<br /><br />        wait_ms&#40;100&#41;; //wait 100ms<br /><br />        printf&#40;&quot;read SRF ranging data......\n&quot;&#41;;<br /><br />        //START with address 0xe0&gt;&gt;1 to write 1 bytes<br />        i2c0master_StartN&#40;0xe0&gt;&gt;1, I2C_WRITE, 1&#41;;<br /><br />        //set RESTART to read 2 bytes after I2C writing<br />        i2c0master_SetRestartN&#40;I2C_READ, 2&#41;;<br /><br />        i2c0master_WriteN&#40;2&#41;;       //set 1st SRF range register<br />        b1 = i2c0master_ReadN&#40;&#41;;    //read echo high byte<br />        b2 = i2c0master_ReadN&#40;&#41;;    //read echo low byte<br /><br />        printf&#40;&quot;result = %u\n\n&quot;, b1*256 + b2&#41;;<br /><br />    &#125; while &#40;getch&#40;&#41; != 27&#41;; //press ESC to quit<br /><br />    i2c_Close&#40;&#41;;<br />    return 0;<br />&#125;<br /></code></dd></dl><br /><br />The above sample code is for WinXP and WinCE; if you want to compile it at Linux or DOS, just change the wait_ms() function.<br /><br />Note: in our test, SRF08/SRF10 can connect to RoBoard's I2C0_SCL, I2C0_SDA pins without pull-up resistors and run on 400Kbps. But for other I2C sensors, pull-up resistors may be necessary for fast I2C transmission (&gt;100Kbps).<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1542">roboard</a> — Fri Jul 10, 2009 6:14 am</p><hr />
]]></content>
</entry>
</feed>