<?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=6014" />

<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-08-09T08:18:36+01:00</updated>

<author><name><![CDATA[RoboSavvy Forum]]></name></author>
<id>http://forum.robosavvy.com/feed.php?f=17&amp;t=6014</id>
<entry>
<author><name><![CDATA[pujiyanto]]></name></author>
<updated>2010-08-09T08:18:36+01:00</updated>
<published>2010-08-09T08:18:36+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=27815#p27815</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=27815#p27815"/>
<title type="html"><![CDATA[SparkFun HMC6343 i2c Code]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=27815#p27815"><![CDATA[
I'm using AVR, ATMEGA 8535, but I can hardly get the data with I2C communication<br /><br /> I try to display the result in 16x2 LCD, but my result stuck at 264 even if the module is rotate.<br />here are my code<br /><br /><dl class="codebox"><dt>Code: </dt><dd><code>/*****************************************************<br />This program was produced by the<br />CodeWizardAVR V2.03.4 Standard<br />Automatic Program Generator<br />© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.<br />http://www.hpinfotech.com<br /><br />Project :<br />Version :<br />Date    : 7/12/2010<br />Author  :<br />Company :<br />Comments:<br /><br /><br />Chip type           : ATmega8535<br />Program type        : Application<br />Clock frequency     : 11.059200 MHz<br />Memory model        : Small<br />External RAM size   : 0<br />Data Stack size     : 128<br />*****************************************************/<br /><br />#include &lt;mega8535&gt;<br />#include &lt;stdlib&gt;<br />#include &lt;string&gt;<br />#include &lt;delay&gt;<br /><br /><br />unsigned int headinga, pitcha, rolla;<br />unsigned char heading&#91;4&#93;, pitch&#91;4&#93;, roll&#91;4&#93;;<br />unsigned int temp&#91;6&#93;;<br />int i;<br /><br />// I2C Bus functions<br />#asm<br />   .equ __i2c_port=0x15 ;PORTC<br />   .equ __sda_bit=1<br />   .equ __scl_bit=0<br />#endasm<br />#include &lt;i2c&gt;<br /><br />// Alphanumeric LCD Module functions<br />#asm<br />   .equ __lcd_port=0x1B ;PORTA<br />#endasm<br />#include &lt;lcd&gt;<br /><br />// Declare your global variables here<br /><br />void command &#40;unsigned char cmd&#41;<br />&#123;<br />i2c_start&#40;&#41;;<br />i2c_write&#40;0x32&#41;;<br />i2c_write&#40;cmd&#41;;<br />i2c_stop&#40;&#41;;<br />&#125;<br /><br />void read &#40;&#41;<br />&#123;<br /><br />  i2c_start&#40;&#41;;<br />  i2c_write&#40;0x33&#41;;<br />for&#40;i=0;i&lt;6;i++&#41;<br />&#123;<br />  temp&#91;i&#93; = i2c_read&#40;1&#41;;<br />&#125;<br />  i2c_stop&#40;&#41;;<br /><br /><br />&#125;<br /><br />void count&#40;&#41;<br />&#123;<br />headinga = &#40;temp&#91;0&#93;&lt;&lt;8 + temp &#91;1&#93;&#41;/10;<br />pitcha = &#40;temp&#91;2&#93;&lt;&lt;8 + temp &#91;3&#93;&#41;/10;<br />rolla = &#40;temp&#91;4&#93;&lt;&lt;8 + temp &#91;5&#93;&#41;/10;<br />   <br />      heading&#91;0&#93; = headinga % 1000 / 100 + 48;<br />      heading&#91;1&#93; = headinga % 100 / 10 + 48; <br />      heading&#91;2&#93; = headinga % 10 / 1 + 48;   <br />      heading&#91;3&#93; = NULL;<br />     <br />/* this part is used to convert binary to ascii. for example, if the heading result 271 degree, then<br />1. mod it with 1000 result in 271, then devide it with 100 result will be 2 &#40;rounded&#41; then add the result with  0 ascii &#40;48&#41; then it store at heading&#91;0&#93;;<br />2. mod it with 100 result in 71, then devide it with 10 result will be 7 &#40;rounded&#41; then add the result with  0 ascii &#40;48&#41; then it store at heading&#91;1&#93;;<br />3. mod it with 10 result in 1, then devide it with 1 result will be 1 &#40;rounded&#41; then add the result with  0 ascii &#40;48&#41; then it store at heading&#91;3&#93;;<br />*/<br />      pitch&#91;0&#93; = pitcha % 1000 / 100 + 48;<br />      pitch&#91;1&#93; = pitcha % 100 / 10 + 48; <br />      pitch&#91;2&#93; = pitcha % 10 / 1 + 48;   <br />      pitch&#91;3&#93; = NULL;<br />     <br />      roll&#91;0&#93; = rolla % 1000 / 100 + 48;<br />      roll&#91;1&#93; = rolla % 100 / 10 + 48; <br />      roll&#91;2&#93; = rolla % 10 / 1 + 48;   <br />      roll&#91;3&#93; = NULL;<br /> <br /> <br />&#125;<br /><br />void main&#40;void&#41;<br />&#123;<br />// Declare your local variables here<br /><br />// Input/Output Ports initialization<br />// Port A initialization<br />// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In<br />// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T<br />PORTA=0x00;<br />DDRA=0x00;<br /><br />// Port B initialization<br />// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In<br />// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T<br />PORTB=0x00;<br />DDRB=0x00;<br /><br />// Port C initialization<br />// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In<br />// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T<br />PORTC=0x00;<br />DDRC=0x00;<br /><br />// Port D initialization<br />// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In<br />// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T<br />PORTD=0x00;<br />DDRD=0x00;<br /><br />// I2C Bus initialization<br />i2c_init&#40;&#41;;<br /><br />// LCD module initialization<br />lcd_init&#40;16&#41;;<br />command&#40;0x82&#41;;<br />delay_ms&#40;500&#41;;<br /><br />while &#40;1&#41;<br />      &#123;       <br />       command&#40;0x50&#41;;<br />       delay_ms&#40;2&#41;;<br />       read&#40;&#41;;<br />       count&#40;&#41;;<br />       lcd_clear&#40;&#41;;<br />       lcd_puts&#40;heading&#41;;<br />       <br />&#125;<br /><br /></code></dd></dl><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=2276">pujiyanto</a> — Mon Aug 09, 2010 8:18 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[PaulL]]></name></author>
<updated>2010-04-05T03:51:38+01:00</updated>
<published>2010-04-05T03:51:38+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26237#p26237</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26237#p26237"/>
<title type="html"><![CDATA[SparkFun HMC6343 i2c Code]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26237#p26237"><![CDATA[
Yup, posting code can be problematic at times. Frustrating that posting such code causes truncation. Do the moderators have any suggestions???<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=741">PaulL</a> — Mon Apr 05, 2010 3:51 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[veltrop]]></name></author>
<updated>2010-04-05T03:45:13+01:00</updated>
<published>2010-04-05T03:45:13+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26236#p26236</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26236#p26236"/>
<title type="html"><![CDATA[SparkFun HMC6343 i2c Code]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26236#p26236"><![CDATA[
Just noticed that above the &quot;if (a == 'y') { &quot; statements the &quot;cin &gt;&gt; a&quot; got truncated becuase of the bugs with the greater-than and less-than characters.<br /><br />Proceed with caution <img src="http://forum.robosavvy.com/images/smilies/icon_wink.gif" alt=";)" title="Wink" /><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1573">veltrop</a> — Mon Apr 05, 2010 3:45 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[limor]]></name></author>
<updated>2010-04-03T01:20:29+01:00</updated>
<published>2010-04-03T01:20:29+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26212#p26212</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26212#p26212"/>
<title type="html"><![CDATA[SparkFun HMC6343 i2c Code]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26212#p26212"><![CDATA[
thanks!<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=2">limor</a> — Sat Apr 03, 2010 1:20 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[veltrop]]></name></author>
<updated>2010-03-29T09:30:10+01:00</updated>
<published>2010-03-29T09:30:10+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26118#p26118</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26118#p26118"/>
<title type="html"><![CDATA[SparkFun HMC6343 i2c Code]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6014&amp;p=26118#p26118"><![CDATA[
Here is some code for the SparkFun HMC6343 Compass/Tilt sensor.  It's not very different from other Roboard i2c code floating around, but thought I'd pass it along.<br /><br /><dl class="codebox"><dt>Code: </dt><dd><code>#include &lt;roboard&gt;<br />#include &lt;iostream&gt;<br />#include &lt;iomanip&gt;<br />using namespace std;<br /><br />int main&#40;int argz, char** argv&#41;<br />&#123;<br />    if &#40;!i2c_Initialize&#40;I2CIRQ_DISABLE&#41;&#41; &#123; <br />        cout &lt;&lt; &quot;Failed to Initialize i2c.&quot; &lt;&lt;endl;<br />    &#125; <br /><br />    i2c0_SetSpeed&#40;I2CMODE_STANDARD, 100000&#41;; <br />    <br />    /////////////////////////////////////////////////////////////////<br />    // Calibration<br />    cout &lt;&lt; &quot;Calibrate? &#40;y/n&#41;&quot;&lt;&lt;endl&gt;&gt; a;<br />        <br />    if &#40;a == 'y'&#41; &#123;<br />        usleep&#40; 500000 &#41;; // 500ms<br />        <br />        i2c0master_StartN&#40;0x32&gt;&gt;1, I2C_WRITE, 1&#41;; <br />        i2c0master_WriteN&#40;0x71&#41;;  // heading data<br />        usleep&#40; 1000 &#41;; // 1 ms<br /><br />        cout &lt;&lt; &quot;Press y and enter when finished calibrating to save calibration.&quot;&lt;&lt;endl&gt;&gt; a;<br />        <br />        if &#40;a == 'y'&#41; &#123;<br />            i2c0master_StartN&#40;0x32&gt;&gt;1, I2C_WRITE, 1&#41;; <br />            i2c0master_WriteN&#40;0x7E&#41;;  // heading data<br />            cout &lt;&lt;&quot;Calibration Saved&quot;&lt;&lt;endl&gt;&gt;1, I2C_WRITE, 1&#41;; <br />        i2c0master_WriteN&#40;0x50&#41;;  // heading data<br />        //i2c0master_WriteN&#40;0x55&#41;;  // tilt data<br />        //i2c0master_WriteN&#40;0x40&#41;;    // accel data<br />        //0x45 // mag data<br />        usleep&#40; 1000 &#41;; // 1 ms<br />    <br />        i2c0master_StartN&#40; 0x33&gt;&gt;1, I2C_WRITE, 1 &#41;; <br />        i2c0master_SetRestartN&#40; I2C_READ, 6 &#41;; <br />        i2c0master_WriteN&#40;6&#41;; <br />        char msb1 = i2c0master_ReadN&#40;&#41;; <br />        char lsb1 = i2c0master_ReadN&#40;&#41;; <br />        char msb2 = i2c0master_ReadN&#40;&#41;; <br />        char lsb2 = i2c0master_ReadN&#40;&#41;; <br />        char msb3 = i2c0master_ReadN&#40;&#41;; <br />        char lsb3 = i2c0master_ReadN&#40;&#41;; <br />        <br />        int head = 0;<br />        if &#40;msb1 &amp; 0x0080&#41; // 128 &#40;2's compliment negative&#41;<br />            head |= &#40;msb1&lt;&lt;8 &amp; 0xFFFFFF00&#41; | &#40;lsb1 &amp; 0xFFFF00FF&#41;;<br />        else<br />            head |= &#40;msb1&lt;&lt;8 &amp; 0x0000FF00&#41; | &#40;lsb1 &amp; 0x000000FF&#41;;<br />        <br />        int pitch = 0;<br />        if &#40;msb2 &amp; 0x0080&#41; // 128 &#40;2's compliment negative&#41;<br />            pitch |= &#40;msb2&lt;&lt;8 &amp; 0xFFFFFF00&#41; | &#40;lsb2 &amp; 0xFFFF00FF&#41;;<br />        else<br />            pitch |= &#40;msb2&lt;&lt;8 &amp; 0x0000FF00&#41; | &#40;lsb2 &amp; 0x000000FF&#41;;<br />        <br />        int roll = 0;<br />        if &#40;msb3 &amp; 0x0080&#41; // 128 &#40;2's compliment negative&#41;<br />            roll |= &#40;msb3&lt;&lt;8 &amp; 0xFFFFFF00&#41; | &#40;lsb3 &amp; 0xFFFF00FF&#41;;<br />        else<br />            roll |= &#40;msb3&lt;&lt;8 &amp; 0x0000FF00&#41; | &#40;lsb3 &amp; 0x000000FF&#41;;<br />        <br />        cout &lt;&lt; setw&#40;6&#41; &lt;&lt; &#40;float&#41;head/10.0f &lt;&lt; &quot; &quot; &lt;&lt; setw&#40;6&#41; &lt;&lt; &#40;float&#41;pitch/10.0f &lt;&lt; &quot; &quot; &lt;&lt; setw&#40;6&#41; &lt;&lt; &#40;float&#41;roll/10.0f &lt;&lt;endl;<br />                <br />        usleep&#40;200000&#41;; // 200ms<br />    &#125; while &#40;1&#41;;<br />    ////////////////////////////////////////////////////////////////<br /><br />    i2c_Close&#40;&#41;;<br /><br />    return 0;<br />&#125;</code></dd></dl><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1573">veltrop</a> — Mon Mar 29, 2010 9:30 am</p><hr />
]]></content>
</entry>
</feed>