<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=23&amp;t=3669&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2013-10-12T22:46:04+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=23&amp;t=3669&amp;mode</id>
<entry>
<author><name><![CDATA[eMCe2]]></name></author>
<updated>2013-10-12T22:46:04+01:00</updated>
<published>2013-10-12T22:46:04+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=52759#p52759</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=52759#p52759"/>
<title type="html"><![CDATA[Re: Lisek chytrusek w c# po I2C]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=52759#p52759"><![CDATA[
Wywaliłem całkiem tego Timera bo w sumie nie potrzebny faktycznie a mielony był co 10ms. Ale to i tak nic nie dało.<br />A ramkę mam całą bo widzę wartości X,Y,Z tylko że wygląda to tak że wywołanie rx_parse zajmuje tyle czasu że nawala się danych z RS na jakims stosie i to się powoli wykonuje. Tak to mi wygląda ale nie wiem czy to tak działa...<br />A ramka wygląda tak &quot;X,Y,Z\n&quot; i widzę ja w textboxie całą.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1363">eMCe2</a> — 12 paź 2013, o 22:46</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[savian86]]></name></author>
<updated>2013-10-12T21:50:52+01:00</updated>
<published>2013-10-12T21:50:52+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=52753#p52753</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=52753#p52753"/>
<title type="html"><![CDATA[Re: Lisek chytrusek w c# po I2C]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=52753#p52753"><![CDATA[
[syntax=csharp]private void timer1_Tick(object sender, EventArgs e)<br />        {          <br />            if (serialPort1.IsOpen)<br />            {<br />                toolStripStatusLabel3.Text = &quot;Open&quot;;<br />                toolStripStatusLabel1.Text = serialPort1.PortName;<br />                toolStripStatusLabel2.Text = serialPort1.BaudRate.ToString();<br />            }<br /><br />            else<br />            {<br />                toolStripStatusLabel3.Text = &quot;Closed&quot;;<br />                toolStripStatusLabel1.Text = &quot;Choose serial port&quot;;<br />                toolStripStatusLabel2.Text = &quot;Choose serial speed&quot;;<br />            }           <br />        }[/syntax]<br /><br />W jakim celu powtarzasz te czynności w zdarzeniu od timera? Z jakim interwałem jest on mielony?<br /><br />Dodatkowo gdy wywołujesz<br />[syntax=csharp]this.Invoke(new EventHandler(rx_parse));[/syntax]<br />to jesteś pewny, że masz odebraną kompletną ramkę?<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=393">savian86</a> — 12 paź 2013, o 21:50</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[eMCe2]]></name></author>
<updated>2013-10-12T20:11:06+01:00</updated>
<published>2013-10-12T20:11:06+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=52730#p52730</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=52730#p52730"/>
<title type="html"><![CDATA[Re: Lisek chytrusek w c# po I2C]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=52730#p52730"><![CDATA[
Trochę odświeżę kotleta ale właściwie swój program oparłem na tym tutaj w C#. Mam taki problem że moje dane wyswietlane są z kilkusekundowym opóźnieniem <img src="https://forum.atnel.pl/images/smilies/icon_neutral.gif" alt=":|" title="Średnio zadowolony" /> trochę więc dziwnie to wygląda...<br />Podpowie ktoś gdzie  szukać problemu?<br />Zapięty mam żyroskop MMA7455L po TWI,dane idą z ATB po RS232 COM6/19200/8/n/1.<br />Na LCD w ATB oczywiście wszystko zmienia się na bieżąco i w terminalu też dane lecą jak szalone.<br /><br />[syntax=csharp]using System;<br />using System.Collections.Generic;<br />using System.ComponentModel;<br />using System.Data;<br />using System.Drawing;<br />using System.Linq;<br />using System.Text;<br />using System.Windows.Forms;<br />using System.IO.Ports;<br /><br /><br /><br />namespace WindowsFormsApplication1<br />{<br />    <br />    public partial class Form1 : Form<br />    {<br />        <br />        public string data;<br />        <br />        public int X, Y, Z;<br />        public int maxX, maxY, maxZ;<br />        public int minX, minY, minZ;<br />        public int PROGRESS_MAX = 1024;<br />        <br /><br />        public Form1()<br />        {<br />            string&#91;&#93; porty;<br />           InitializeComponent();<br />           porty=System.IO.Ports.SerialPort.GetPortNames();<br />           for (int k = 0; k &lt; porty.Length; k++)<br />           {<br />               comboBox1.Items.Insert(k, porty&#91;k&#93;);<br />           }<br /><br /><br />           progressBar1.Minimum = 0;<br />           progressBar1.Maximum = PROGRESS_MAX;<br />           progressBar1.Style = System.Windows.Forms.ProgressBarStyle.Continuous;<br />           progressBar2.Minimum = 0;<br />           progressBar2.Maximum = PROGRESS_MAX;<br />           progressBar2.Style = System.Windows.Forms.ProgressBarStyle.Continuous;<br />           progressBar3.Minimum = 0;<br />           progressBar3.Maximum = PROGRESS_MAX;<br />           progressBar3.Style = System.Windows.Forms.ProgressBarStyle.Continuous;<br />           progressBar4.Minimum = 0;<br />           progressBar4.Maximum = PROGRESS_MAX;<br />           progressBar4.Style = System.Windows.Forms.ProgressBarStyle.Continuous;<br />           progressBar5.Minimum = 0;<br />           progressBar5.Maximum = PROGRESS_MAX;<br />           progressBar5.Style = System.Windows.Forms.ProgressBarStyle.Continuous;<br />           progressBar6.Minimum = 0;<br />           progressBar6.Maximum = PROGRESS_MAX;<br />           progressBar6.Style = System.Windows.Forms.ProgressBarStyle.Continuous;<br />          <br />          <br />            <br />            <br />        }<br /><br />     <br /><br />        private void button1_Click(object sender, EventArgs e)<br />        {<br />            if (serialPort1.IsOpen)<br />            {<br />                serialPort1.Close();<br />                button1.Text = &quot;Open&quot;;<br />                button1.ForeColor = System.Drawing.Color.Red;<br />               <br /><br /><br /><br /><br />            }<br />            else<br />            {<br />                serialPort1.PortName = &quot;COM6&quot;; // Convert.ToString(comboBox1.SelectedItem);<br />                serialPort1.BaudRate =19200;// Convert.ToInt32(comboBox2.SelectedItem);<br />                serialPort1.Parity = Parity.None;<br />                serialPort1.StopBits = StopBits.One;<br />                serialPort1.DataBits = 8;<br />                serialPort1.Handshake = Handshake.None;<br />                serialPort1.ReadBufferSize = 10;<br />                serialPort1.Open();<br />                button1.Text = &quot;Close&quot;;<br />                button1.ForeColor = System.Drawing.Color.Green;<br /><br />            }<br /><br />           <br />        }<br /><br />        private void timer1_Tick(object sender, EventArgs e)<br />        {<br />            <br />            if (serialPort1.IsOpen)<br />            {<br />                toolStripStatusLabel3.Text = &quot;Open&quot;;<br />                toolStripStatusLabel1.Text = serialPort1.PortName;<br />                toolStripStatusLabel2.Text = serialPort1.BaudRate.ToString();<br />            }<br />            else<br />            {<br />                toolStripStatusLabel3.Text = &quot;Closed&quot;;<br />                toolStripStatusLabel1.Text = &quot;Choose serial port&quot;;<br />                toolStripStatusLabel2.Text = &quot;Choose serial speed&quot;;<br />            }<br />             <br />        }<br /><br />        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)<br />        {<br />           <br />           data = serialPort1.ReadTo(&quot;\n&quot;);                     <br />           this.Invoke(new EventHandler(rx_parse));<br />           <br />        <br /><br />        }<br /><br />        private void rx_parse(object sender, EventArgs e)<br />        {<br />            textBox1.Text = data;<br />            string&#91;&#93; xyz = new string&#91;10&#93;;<br />            xyz=data.Split(',');<br />            <br />            label4.Text = xyz&#91;0&#93;.ToString();<br />            label5.Text = xyz&#91;1&#93;.ToString();<br />            label6.Text = xyz&#91;2&#93;.ToString();<br />            label10.Text = xyz&#91;0&#93;.ToString();<br />            label11.Text = xyz&#91;1&#93;.ToString();<br />            label12.Text = xyz&#91;2&#93;.ToString();<br />              <br />            X = Convert.ToInt16(xyz&#91;0&#93;);<br />            Y = Convert.ToInt16(xyz&#91;1&#93;);<br />            Z = Convert.ToInt16(xyz&#91;2&#93;);<br />            <br />            if (X &lt; minX) minX = X;<br />            if (Y &lt; minY) minY = Y;<br />            if (Z &lt; minZ) minZ = Z;<br />            label13.Text = minX.ToString();<br />            label14.Text = minY.ToString();<br />            label15.Text = minZ.ToString();<br /><br />            if (X &gt; maxX) maxX = X;<br />            if (Y &gt; maxY) maxY = Y;<br />            if (Z &gt; maxZ) maxZ = Z;<br />            label16.Text = maxX.ToString();<br />            label17.Text = maxY.ToString();<br />            label18.Text = maxZ.ToString();<br />             <br />            //X<br />            if (X &lt; 0)<br />            {<br />                progressBar1.Value = Math.Abs(X);<br />                progressBar2.Value = 0;<br />            }<br />            else<br />            {<br />                progressBar2.Value = X;<br />                progressBar1.Value = 0;<br />            }<br />            //Y<br />            if (Y &lt; 0)<br />            {<br />                progressBar3.Value = (Math.Abs(Y));<br />                progressBar4.Value = 0;<br />            }<br />            else<br />            {<br />                progressBar4.Value = Y;<br />                progressBar3.Value = 0;<br />            }<br />            //Z<br />            if (Z &lt; 0)<br />            {<br />                progressBar5.Value = (Math.Abs(Z));<br />                progressBar6.Value = 0;<br />            }<br />            else<br />            {<br />                progressBar6.Value = Z;<br />                progressBar5.Value = 0;<br />            }<br /><br />            <br /><br />        }<br />    }<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1363">eMCe2</a> — 12 paź 2013, o 20:11</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[wrzaskun]]></name></author>
<updated>2013-09-03T13:38:34+01:00</updated>
<published>2013-09-03T13:38:34+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=48010#p48010</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=48010#p48010"/>
<title type="html"><![CDATA[Re: Lisek chytrusek w c# po I2C]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=48010#p48010"><![CDATA[
Pionowo stawiając oś Z przyjmuje wartości w okolicach zera, a jak pukam pionowo to nic się nie zawiesza, żadna inna oś. W rezultacie Z pokazuje 127 tylko przy pukaniu poziomym.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=925">wrzaskun</a> — 3 wrz 2013, o 13:38</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[wrzaskun]]></name></author>
<updated>2013-09-03T12:07:59+01:00</updated>
<published>2013-09-03T12:07:59+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=48003#p48003</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=48003#p48003"/>
<title type="html"><![CDATA[Re: Lisek chytrusek w c# po I2C]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=48003#p48003"><![CDATA[
Hej, właśnie mam pytanko odnośnie liska,. na szybko go odpaliłem na kodzie z kamammi, w rezultacie oś Z mi się wiesza na 127 jak nim stuknę i odwiesza jak znowu pukam, natomiast jak nim mocniej macham to mam wartości w tysiącach na daną oś, nie wiem czy to tak działa ten czujnik czy mam felerny egzemplarz?<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=925">wrzaskun</a> — 3 wrz 2013, o 12:07</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[developer85]]></name></author>
<updated>2013-07-26T11:34:57+01:00</updated>
<published>2013-07-26T11:34:57+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=43414#p43414</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=43414#p43414"/>
<title type="html"><![CDATA[Re: Lisek chytrusek w c# po I2C]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=43414#p43414"><![CDATA[
heh taką stacje fajnie będzie zrobić,  już mam pomysłą na softa do PC:).<br />Ale mam oprócz tego narodził się pomysł  na robota przy użyciu serw - tylko muszę dokupić jeszcze z 6 szt.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=390">developer85</a> — 26 lip 2013, o 11:34</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[SunRiver]]></name></author>
<updated>2013-07-26T11:18:48+01:00</updated>
<published>2013-07-26T11:18:48+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=43409#p43409</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=43409#p43409"/>
<title type="html"><![CDATA[Re: Lisek chytrusek w c# po I2C]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=43409#p43409"><![CDATA[
hehe niema to jak zrobić małą prowokację , gratuluję developer zaciekłości w dążeniu do celu <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /><br />bo przecież o to właśnie chodzi żeby sie maxymalnie uczyć przy takich dziwnych pomysłach<br />dlatego teraz proponuje serowatowatą stacje meteo oparta o np SHT21 i BMP115 <br /><br /><img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=58">SunRiver</a> — 26 lip 2013, o 11:18</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[developer85]]></name></author>
<updated>2013-07-26T09:28:50+01:00</updated>
<published>2013-07-26T08:02:10+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=43404#p43404</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=43404#p43404"/>
<title type="html"><![CDATA[Lisek chytrusek w c# po I2C]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=3669&amp;p=43404#p43404"><![CDATA[
Jako że kiedyś Anty pytał o liska chytruska po SPI więc specjalnie dla niego przygotowałem małą aplikacje w c# oraz podaje libsa to chytruska po na I2C.<br /><br />Taki mały screen prostej jak drut apki to wizualizacji osi X,Y,Z:<br /> <a href="http://forum.atnel.pl/_obrazki/o/390/76964a0774fba326dce54b1d2d961d37.jpg"  class="postlink"><img src="http://forum.atnel.pl/_obrazki/o/thumb/390/76964a0774fba326dce54b1d2d961d37.jpg" alt="Obrazek" /></a><br /><br /><br />i wybaczcie za jakość filmów (aha jakoś znacznik YT coś mi nie działa) <span style="color: #00BF00">(poprawiłem i działa <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /> )</span><br /><br /><div style="width: 583px; height: 471px; margin: 0 auto; padding-left: 26px; padding-top: 48px; background: url('https://www.atnel.pl/download/atnel_tv.png') no-repeat;"> <strong>iframe</strong> </div><br /><br />ok kodzik w c#:<br />[syntax=csharp]using System;<br />using System.Collections.Generic;<br />using System.ComponentModel;<br />using System.Data;<br />using System.Drawing;<br />using System.Linq;<br />using System.Text;<br />using System.Windows.Forms;<br /><br />namespace lis35_bar<br />{<br />    public partial class Form1 : Form<br />    {<br />        public Form1()<br />        {<br />            InitializeComponent();<br />            serialPort1.Open();<br />            timer1.Start();<br />        }<br /><br />        public string rx_str = &quot; &quot;;<br />        public int licznik = 0;<br />        public int tab_size = 0;<br />        public int index = 0;<br /><br />        private void Form1_Load(object sender, EventArgs e)<br />        {<br /><br />        }<br /><br />        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)<br />        {<br />            licznik++;<br />            if (licznik == 1) <br />            {<br />                rx_str = serialPort1.ReadTo(&quot;\n&quot;);<br />                rx_str = &quot; &quot;;<br /><br /><br />            }<br />            else<br />            {<br />                rx_str = serialPort1.ReadTo(&quot;\n&quot;); // przekazanie odebranego łańcucha do zmiennej rx_str<br />                this.Invoke(new EventHandler(rx_parse)); // instalacja zdarzenia parsującego odebrany łańcuch<br />            }<br />        }<br />        private void rx_parse(object sender, EventArgs e)<br />        {<br /><br />             <br /><br />             string&#91;&#93; dane = new string&#91;5&#93;;<br />             dane = rx_str.Split(',');<br /><br />                <br /><br />             textBox1.Text = dane&#91;0&#93;;                     <br /><br />             if (Convert.ToInt16((textBox1.Text = dane&#91;0&#93;)) &lt; 0)<br />             {<br />                 //progressBar1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;<br />                 //progressBar1.RightToLeftLayout = true;<br />                 progressBar1.Value = Math.Abs(Convert.ToInt16(dane&#91;0&#93;));<br />             }<br />             else progressBar2.Value = Convert.ToInt16(dane&#91;0&#93;);<br />             <br />             textBox2.Text = dane&#91;1&#93;;<br />             if (Convert.ToInt16((textBox2.Text = dane&#91;1&#93;)) &lt; 0)<br />             {<br />                 //progressBar3.RightToLeft = System.Windows.Forms.RightToLeft.Yes;<br />                // progressBar3.RightToLeftLayout = true;<br />                 progressBar3.Value = Math.Abs(Convert.ToInt16(dane&#91;1&#93;));<br />             }<br />             else progressBar4.Value = Convert.ToInt16(dane&#91;1&#93;);<br /><br /><br />             textBox3.Text   = dane&#91;2&#93;;<br />             if (Convert.ToInt16((textBox3.Text = dane&#91;2&#93;)) &lt; 0)<br />             {<br />                 //progressBar5.RightToLeft = System.Windows.Forms.RightToLeft.Yes;<br />                // progressBar5.RightToLeftLayout = true;<br />                 progressBar5.Value = Math.Abs(Convert.ToInt16(dane&#91;2&#93;));<br />             }<br />             else progressBar6.Value = Convert.ToInt16(dane&#91;2&#93;);<br /><br />       }<br /><br />            private void timer1_Tick(object sender, EventArgs e)<br />            {<br />              serialPort1.WriteLine(&quot;AT+LIS=1\r&quot;);<br />            }<br /><br />   }<br />    <br />}[/syntax]<br /><br /><br />Full libs dla lis35de po SPI i I2C<br />lis.c[syntax=c]#include &quot;lis35.h&quot;<br />#include &lt;avr/io.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &quot;I2C_TWI/i2c_twi.h&quot;<br /><br /><br />signed char X, Y, Z;<br /><br />/************************* SPI Functions **********************************************/<br />void SPI_Init(void)<br />{<br /> <br />DDR_SPI |= (1&lt;&lt;DD_MOSI)|(1&lt;&lt;DD_SCK)|(1&lt;&lt;DD_SS);<br />DDR_SPI &amp;= ~(1 &lt;&lt; DD_MISO);<br />SPCR = (1&lt;&lt;SPE)|(1&lt;&lt;MSTR)|(1&lt;&lt;SPR1)|(1&lt;&lt;SPR0)|(1&lt;&lt;CPOL)|(1&lt;&lt;CPHA)/* | (1&lt;&lt;DORD)*/;<br />}<br /><br /><br />void SPI_Transmit(char cData)<br />{<br />SPDR = cData;<br />while(!(SPSR &amp; (1&lt;&lt;SPIF)));<br />}<br /><br /><br />char SPI_Receive(void)<br />{<br />SPDR = 0xFF;<br />while(!(SPSR &amp; (1&lt;&lt;SPIF)));<br />return SPDR;<br />}<br />/************************* SPI Functions - end *****************************************/<br /><br /><br /><br /><br /><br />void LIS35_RebootMemory()<br />{<br />PORTB&amp;=!(1&lt;&lt;DD_SS);<br />SPI_Transmit(LIS35_WRITE|LIS35_ADDR_NO_INC|LIS35_REG_CR2);<br />SPI_Transmit(LIS35_REG_CR2_BOOT);<br />PORTB|=(1&lt;&lt;DD_SS);<br />}<br /><br /><br />char InitializeLIS35()<br />{<br />char RegVal;<br /><br />//Inititalize SPI<br />SPI_Init();<br /><br />//Reset LIS35 configuration<br />    LIS35_RebootMemory(); <br /><br />//Power up<br />LIS35_WriteRegister(LIS35_REG_CR1, LIS35_REG_CR1_XEN | LIS35_REG_CR1_YEN | LIS35_REG_CR1_ZEN | LIS35_REG_CR1_ACTIVE);// | LIS35_REG_CR1_FULL_SCALE);<br />LIS35_ReadRegister(LIS35_REG_CR1, &amp;RegVal);<br /><br /><br /><br />//Configure click interrupt (enable all sigle clicks)<br />LIS35_WriteRegister(LIS35_CLICK_CFG, 0x1);<br />LIS35_WriteRegister(LIS35_CLICK_THSY_X, 0x77);<br />LIS35_WriteRegister(LIS35_CLICK_THSZ, 0x7);<br />LIS35_WriteRegister(LIS35_CLICK_TIME_LIMIT, 0xFF);<br /><br />//Enable interrupts<br />// LIS35 int 1 - click<br />// LIS32_CR3_IHL - interrupt is low pulse<br /> LIS35_WriteRegister(LIS35_CR3, LIS35_CR3_IHL | LIS35_CR3_CLICK_INT);<br /><br /><br /><br />//Check whether power up is set<br />if (RegVal==(LIS35_REG_CR1_XEN | LIS35_REG_CR1_YEN | LIS35_REG_CR1_ZEN | LIS35_REG_CR1_ACTIVE  /*| LIS35_REG_CR1_FULL_SCALE*/)) return LIS35_OK;<br /><br />return LIS35_ERROR;<br />}<br /><br /><br />void LIS35_ReadRegister(char addr,char * v)<br />{<br />PORTB&amp;=!(1&lt;&lt;DD_SS);<br />SPI_Transmit(LIS35_READ|LIS35_ADDR_NO_INC|addr);<br />*v=SPI_Receive();<br />PORTB|=(1&lt;&lt;DD_SS);<br />}<br /><br /><br />void LIS35_WriteRegister(char addr,char v)<br />{<br />PORTB&amp;=!(1&lt;&lt;DD_SS);<br />SPI_Transmit(LIS35_WRITE|LIS35_ADDR_NO_INC|addr);<br />SPI_Transmit(v);<br />PORTB|=(1&lt;&lt;DD_SS);<br />}<br /><br />void LIS35_GetPosition(signed char * x, signed char * y, signed char * z)<br />{<br />PORTB&amp;=!(1&lt;&lt;DD_SS);<br />SPI_Transmit(LIS35_READ|LIS35_ADDR_INC|LIS35_REG_OUTX);<br />*x=SPI_Receive();<br />SPI_Receive();<br />*y=SPI_Receive();<br />SPI_Receive();<br />*z=SPI_Receive();<br />PORTB|=(1&lt;&lt;DD_SS);<br />}<br /><br />//------I2C----------------------<br /><br /><br /><br />void initlis35i2c(void){<br /><br />TWI_start();<br />TWI_write(LIS35_WRITE_ADDR);//addr zapisu<br />TWI_write(0x20);<br />TWI_write(LIS35_WAKEUP);//wake up<br />TWI_stop();<br />}<br />signed char lisXaxis(void){<br />TWI_start();<br />TWI_write(LIS35_WRITE_ADDR);//rejest zapisu<br />TWI_write(LIS35_REG_OUTX);  //os X<br />TWI_start();<br />TWI_write(LIS35_REG_READ);//rejest odczytu<br />X = TWI_read(NACK); //NACK<br />TWI_stop();<br /><br />return X;<br />}<br />signed char lisYaxis(void){<br /><br />TWI_start();<br />TWI_write(LIS35_WRITE_ADDR);//rejest zapisu<br />TWI_write(LIS35_REG_OUTY);  //os X<br />TWI_start();<br />TWI_write(LIS35_REG_READ);//rejest odczytu<br />Y = TWI_read(NACK); //NACK<br />TWI_stop();<br /><br />return Y;<br /><br />}<br />signed char lisZaxis(void){<br /><br />TWI_start();<br />TWI_write(LIS35_WRITE_ADDR);//rejest zapisu<br />TWI_write(LIS35_REG_OUTZ);  //os X<br />TWI_start();<br />TWI_write(LIS35_REG_READ);//rejest odczytu<br />Z = TWI_read(NACK); //NACK<br />TWI_stop();<br /><br />return Z;<br />}[/syntax]<br /><br />lis.h<br />[syntax=c]#ifndef LIS35_H_<br />#define LIS35_H_<br /><br /><br />#define NACK 0<br />#define ACK 1<br /><br />#define LIS35_WRITE_ADDR 0x3A   //adres zapisu<br />#define LIS35_WAKEUP 0x47//pobudka<br />#define LIS35_REG_WRITE 0x3A//rejestr zapisu<br />#define LIS35_REG_READ 0x3B//<br /><br />#define LIS35_ERROR 1<br />#define LIS35_OK 0<br />#define LIS35_WRITE 0<br />#define LIS35_READ 0x80<br />#define LIS35_ADDR_NO_INC 0<br />#define LIS35_ADDR_INC 0x40<br /><br />#define LIS35_REG_OUTX 0x29<br />#define LIS35_REG_OUTY0x2B<br />#define LIS35_REG_OUTZ0x2D<br /><br />#define LIS35_REG_CR1 0x20<br />#define LIS35_REG_CR1_XEN 0x1<br />#define LIS35_REG_CR1_YEN 0x2<br />#define LIS35_REG_CR1_ZEN 0x4<br />#define LIS35_REG_CR1_DR_400HZ 0x80<br />#define LIS35_REG_CR1_ACTIVE 0x40<br />#define LIS35_REG_CR1_FULL_SCALE 0x20<br /><br />#define LIS35_REG_CR2 0x21<br />#define LIS35_REG_CR2_BOOT 0x40<br /><br />#define LIS35_CR3 0x22<br />#define LIS35_CR3_IHL 0x80<br />#define LIS35_CR3_CLICK_INT 0x7<br />#define LIS35_CR3_FF1_INT 0x1<br /><br /><br />#define LIS35_FF_WU_CFG_1 0x30<br />#define LIS35_FF_WU_SRC_1 0x31<br />#define LIS35_FF_WU_THS_1 0x32<br />#define LIS35_FF_WU_DURATION_1 0x33<br /><br /><br />#define LIS35_CLICK_CFG 0x38<br />#define LIS35_CLICK_THSY_X 0x3b<br />#define LIS35_CLICK_THSZ 0x3c<br />#define LIS35_CLICK_TIME_LIMIT 0x3D<br /><br /><br />#define LIS35_STATUS_REG 0x27<br /><br />#define DDR_SPI DDRB<br />#define DD_MOSIPINB5<br />#define DD_MISO PINB6<br />#define DD_SCKPINB7<br />#define DD_SSPINB4<br /><br />extern signed char X, Y, Z;<br /><br /><br />char InitializeLIS35();<br />void LIS35_ReadRegister(char addr,char * v);<br />void LIS35_WriteRegister(char addr,char v);<br />void LIS35_GetPosition(signed char * x, signed char * y, signed char * z);<br /><br />void initlis35i2c(void);<br /><br />signed char lisXaxis(void);<br />signed char lisYaxis(void);<br />signed char lisZaxis(void);<br /><br />#endif /* LIS35_H_ */[/syntax]<br /><br />To jak już mam w łapkach liska to posterujemy sobie servami:). Kodu nie będe dołączał bo jest tak banalny że każdy, na podstawie bibliotek zamieszczonych wcześniej będzie mógł wykonać coś takiego.<br />Generalnie sterowanie servami za pomocą akcelerometru będzie użyteczne przy poruszaniu się robota:) - więc zachęcam to testów we własnym zakresie!<br /><br /><br />tutaj sterowanie dwoma servami, przy przechyle liska w X-sie:<br /><br /><div style="width: 583px; height: 471px; margin: 0 auto; padding-left: 26px; padding-top: 48px; background: url('https://www.atnel.pl/download/atnel_tv.png') no-repeat;"> <strong>iframe</strong> </div><br /><br />a tutaj jedno servo w kierunku X-a a drugie w Y-ku<br /><br /><div style="width: 583px; height: 471px; margin: 0 auto; padding-left: 26px; padding-top: 48px; background: url('https://www.atnel.pl/download/atnel_tv.png') no-repeat;"> <strong>iframe</strong> </div><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=390">developer85</a> — 26 lip 2013, o 08:02</p><hr />
]]></content>
</entry>
</feed>