Hi guys, this is my first attempt to post a project here.

This is an instructable on how to read a gyro sensor and plot the data using processing software at your desktop. I am using gyroscope model XV81-000 and an arduino. The device is a rough prototype of what will eventually become a self balance robot, this is the first part of the hole thing (read accelerometer and control a motor to self balance).

Step 1: What You Need?

You will need:

- Breadboard
- Microcontroller, I used the Arduino board
- Wire
- Jumper Wires
- Gyroscope XV-8100
very good guide how to use gyro and accelerometer sensors. I add this tutorial on my article where a long list with sensors and tutorials about <a href="http://www.intorobotics.com/accelerometer-gyroscope-and-imu-sensors-tutorials/" rel="nofollow">how to interface and programming accelerometer, gyro and IMU sensors&nbsp;</a>
Blz Ot&aacute;vio<br>o Codigo do arduino_gyro.pde<br>&eacute; o codigo do processing e n&atilde;o do arduino<br>Vc poderia corigir.<br>Agrade&ccedil;o pelo tutorial.
Realmente esta errado, vou corrigir assim que possivel.
Ol&aacute; Ot&aacute;vio, me chamo ontreus e tamb&eacute;m me encontro em S&atilde;o Paulo.<br>Na busca por informa&ccedil;&otilde;es sobre Girosc&oacute;pio, cheguei no seu tutorial.<br>Bem, possuo os seguintes componentes:<br>- Giroscopio0 XV-3500CB PROTOTYPE PCB<br>- Arduino Duemilanove<br>- Servo Motor<br>Estou tentando fazer o mesmo desse link que segue:<br>http://www.youtube.com/watch?v=xkVRZC0e8Vk<br>Depois de testes verifiquei que este meu sensor possui um sinal muito baixo na porta anal&oacute;gica<br>Denominada de ANA0 e verifiquei que voc&ecirc; usou dois capacitores para amplificar o sinal.<br>Meu sensor possui j&aacute; uma sa&iacute;da de sinal digital compat&iacute;vel com l2c pois assim o sinal fica melhor<br>Pergunto que capacitores voc&ecirc; usou em seu projeto e conectado aonde?<br>
Para este seu sensor voce nao precisa dos capacitores.<br><br>O melhor seria usar o I2C para nao ter problemas de interferencia.
i need algorithm of above code for my LABVIEW programming... so plz post it here...
Dear otaviousp, sorry if I bother you, but I'm trying to reproduce your realization using an Arduino Mega BT (Blue Tooth) 368 and what I get as output visualization is a very unstable angle indicator also with gyro device laying on the table without movements.<br> <br>To verify A2D (arduino Analog to Digital) converter I connected analog input 0 to ground. With this configuration the A/D converter is giving me strange values ranging (randomly) from a minimum of 0 to a maximum of 64. <br>Is that possible? Do you know something about poor A/D conversion with arduino.<br>What kind of dynamic shows your realization?<br><br>Thanks for any comment.
What Gyro are you using?<br><br>Are you using the same code without modifications?
Currently I'm using a LPR510AL on a micro board which provides an output voltage which represents the angular acceleration.<br><br>I fixed the A/D conversion problem on arduiono using a resistive partition on AREF pin on arduino board. AREF is now connected to GND with a 10microF, and with a 10K resistor to Vcc (5V). This give me a reference voltage for A/D of 3.77 V.<br><br>Yes, I'm using your sample code.<br>But I'm still having problem with angular value computation.<br><br>The angular value is slowly drifting apart when gyro is kept steady <br>(no force applied).<br><br>But I have just found out that in your code you have this constraint:<br><br>if(teta&gt;-1 &amp;&amp; teta&lt;1) teta=0; //avoid drift error<br> teta = teta + ( valor * time ) / 1000;<br><br>to avoid drifting.<br>I would like to change it to:<br><br>deltaTeta = ( valor * time ) / 1000; // Angle infinitesimal increment<br><br> if(deltaTeta&gt;-1 &amp;&amp; deltaTeta&lt;1) {<br> deltaTeta=0; //avoid drift error<br> }<br><br> teta = teta + deltaTeta; <br><br>Probably this would avoid spurious variation is steady state.<br>But I haven't yet tried this solution.<br>I would let you know as soon I get tested with new code.<br><br>Thanks.<br><br>
Have you change de offset value?<br><br>Make a simple code to return the value read from your analog port with your gyro steady. The value show often is yout offset. Just replace this value on the code.<br><br>This can help improve the steady problem.
Yes correct.<br>This is what I'm doing. I'm reading teta, the A/D output (from 0 to 1023) which is the gyro output voltage read with the arduino A/D converter.<br><br>The gyro output from the A/D has a range from 328 to 330 [count] when gyro is in a steady state ( I do not know if this variability is normal in a gyro or not). So I did use value 329 as offset inside the equation used to compute teta.<br><br>This produce, anyway, a drifting value for teta which keeps increasing or decreasing (depending on the value i choose for offset).<br>Also tuning the offset value using 0.1 resolution (let's suppose 329.4 instead of 329.0) can improve performance in the sense that I reduce the speed with which teta is increasing (decreasing) when gyro is in steady state but i?m not able to stop it.<br><br>I do not want to bother you too much with this problem.<br>Probably I would try with a different gyro with a I2C interface with integrated A/D conversion.<br><br>Thanks for you help.<br>Paolo.<br><br><br>
OK I got the solution to my problem.<br>The problem was related to the fact that I was querying the arduino's A/D converter to fast, a was not giving enough delay in between two consecutive readAnalog() calls.<br><br>Introducing a delay of at least 50 ms definitively solved my problem.<br>By the way I did find a solution to increase speed in A/D conversion on arduino.<br>Here are few lines of &quot;code&quot;:<br><br>#ifndef cbi<br> #define cbi(sfr, bit) (_SFR_BYTE(sfr) &amp;= ~_BV(bit))<br>#endif<br>#ifndef sbi<br> #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))<br>#endif<br><br>#define FASTDAC 1<br><br>#if FASTDAC<br> #define DELAY 10 // delay in ms<br>#else<br> #define DELAY 50<br>#endif<br><br>so you can use less than 10 ms as delay time in between A/D calls.<br>I tested this with 5 ms delay and A/D conversion worked grate.<br><br>Thanks.
Hello, I'm interested in finding out more about these solid state gyros. My question is:- If you had the device on the worktop and it read say 20 degrees. If you pick it up and drive around the block then put it back on the table in exactely the same place would it still show 20 degrees? what kind of accuracy can you get with these? Lastely where can I get chep ones in the UK to play with? Thanks, and sorry for so many questions...
Here is a nice tutorial about this gyros and accelerometers.<br> <br> <a href="https://www.instructables.com/id/Accelerometer-Gyro-Tutorial/" rel="nofollow">https://www.instructables.com/id/Accelerometer-Gyro-Tutorial/</a><br>
ok so this is the code i would need just to get the angle<br /> <br /> <br /> <br /> <strong>float sens= 0.512;<br /> float offset= 316 ;<br /> float count= 0;<br /> float valor =0;<br /> float first_time, time;<br /> float teta=0;<br /> <br /> <br /> //####################################################################//<br /> // //<br /> // Gyro //<br /> // Scale Factor 2.5mV/ �/s = 0.512 counts/ �/s //<br /> // Offset 316 counts = 1562mV = 1.562V //<br /> // ADC 4.88 mV/count // 0.2048 count/mV //<br /> // //<br /> //####################################################################//<br /> <br /> count =0;<br /> for(int i=0;i&lt;20;i++){<br /> <br /> count = count + arduino.analogRead(0);<br /> <br /> }<br /> <br /> count = count /20;<br /> <br /> valor = (count - offset ) / sens;<br /> <br /> time=millis()-first_time;<br /> <br /> first_time=millis();<br /> <br /> teta=teta+valor*time/1000;<br /> <br /> if(teta&gt;-1 &amp;&amp; teta&lt;1) teta=0; //avoid drift error<br /> </strong><br />
Thats right.<br /> <br /> cya<br />
...ok just one other thing if I use a gyro with a accelerometer I would need this:<br /> <br /> Angle=HPF*(teta) + LPF*(arctg( Ay / sqrt( Ax^2 + Az^2 ))<br /> <br /> (from your other instructable)<br />
Yes, but if you gonna use a 6DOF sensor, i think it is better to use the angle from only one direction. That way you have the rotation in on direction off the acellerometer plus the rotation from your gyro. 3 times this configuration.<br /> <br /> Sorry my bad english and worst explanation.<br />
how did you got the&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float sens= 0.512; ?
The Scale factor is 2.5mV / &ordm;/s.<br /> From the ADC 5V / 1024 = 4.8mV / count(raw value)<br /> <br /> ( 2.5mV / (&ordm;/s)&nbsp; ) / (4.8mV / count) = 0.512 count(raw value) / (&ordm;/s)<br /> <br /> so, if you read from the adc channel a value like 2, this means 3.9 &ordm;/s<br /> <br /> 2 / 0.512 = 3.9<br />
so for this sensor (http://www.sparkfun.com/datasheets/Sensors/IMU/lpr530al.pdf)it would be (with 4x amplified)<br /> <br /> 3.3mV / (&ordm;/s)&nbsp; ) / (4.8mV / count) = 0.512 count(raw value) / (&ordm;/s)<br /> <br /> and if you would wire up 3.3v to Aref pin it would be<br /> <br /> From the ADC 3.3V / 1024 = ...<br />
From the ADC 3.3V / 1024 = 3.222mV / count (raw value)<br /> <br /> 3.33mV / (&ordm;/s) / (3.222mV / count)&nbsp; = 1.0333 count (raw value) / (&ordm;/s)<br />
ok thanks ...just one question why is the offet=<br /> 316<br />
When you leave your gyro on a stationary position, probably you wont read a ZERO value.<br /> <br /> You will have something like 1.23V. Or 381 counts.<br /> <br /> This is your offset.<br /> <br /> So, if you extract the value you are reading from the offset you will have ZERO.<br /> <br /> <br />
ok thanks a lot this really helped me <br />
ok thanks<br /> <br />
I know what you mean ... so Ill get a tetax,and tetay, and anglex, angley.<br /> <br /> Thanks this realy helped a lot because there isnt much about gyros or 6DOF on arduino.cc<br /> <br /> <br /> <br />
ok thanks for that fast reply<br /> im gonna use this for a quadrocoper with a razor 6dof from Sparkfun<br />
<p><strong>Can you provide the manufacturer of the breakout board or the retailer from who you got it? I have only been able to find the Gyro in SMD w/o breakout board. Thanks</strong></p>
the sensor is manufactured by epson toycom.<br /> i bought that board on ebay, but I didn't found the seller anymore.<br /> <br /> cya<br />
&nbsp;Is there anyway I can use Processing to send a command to my Arduino?<br /> <br /> Right now I have it set so if I type &quot;T&quot; into my serial monitor, it sends the command out digital pin 9, through my relay, and &quot;presses&quot; a button on my TV controller, thus turning it on.<br /> <br /> Can I do something so that pressing a button in my Processing sketch would be like typing &quot;T&quot;?<br />
Somithing like this should work:<br /> <br /> color fillVal = color(126);<br /> import processing.serial.*;<br /> <br /> void draw() {<br /> &nbsp; fill(fillVal);<br /> &nbsp; rect(25, 25, 50, 50);<br /> }<br /> <br /> void keyReleased() {<br /> &nbsp; Serial myPort;<br /> &nbsp;&nbsp;&nbsp; myPort = new Serial(this, Serial.list()[0], 9600);<br /> &nbsp;&nbsp;&nbsp; if (keyCode == 'T') {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; println(&quot;T key pressed&quot;);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myPort.write(&quot;T&quot;);<br /> &nbsp;&nbsp;&nbsp; }<br /> &nbsp; <br /> }<br />
&nbsp;Ah, I see!<br /> Thank you very much.<br /> <br /> I'm pretty new to Processing, so I'm not too sure of all it's capabilities.<br />
NP, xD<br />
andrew&nbsp; this type of gyroscope use the stability of a blade in vibration.<br /> 1)take a cork and insert in the center a long steel stick<br /> 2)put your stick in vibration vertical and hold the cork under your palm<br /> 3)turn the cork the axe of the stick stay vertical and you feel a force under your palm<br /> <br /> in this type of chips they use a double (A,A')=x=(B,B') lyre the extremity (A and A')is put in vibration by a solenoid the other extremity (B and B') will vibrate then generate a current in a receptive solenoid the difference between the current generate by B and B' with a constant vibration&nbsp; A and A' will mesure the anti couple <br />
Please explain, why you add 270 here: line(200,200,50*cos(radians(teta+270))+200,50*sin(radians(teta+270))+200);
This is just an offset for the angle, when add 270º to the teta angle, the line who indicates the angle stay on vertical.
Thank you! I'm still confused ;) <br/>Would you please explain it mathematically? For I see here:<br/>if(teta&gt;-1 &amp;&amp; teta&lt;1) teta=0; //avoid drift error<br/>That the absolute value of teta is less than 1, then teta could not be in degree...right? next I don't see any conversion to degree, and then it is added to 270 and used as a degree. The program works with my IMU and it means that it is correct. I anyway can't understand the math behind this angle offset! do you see where my problem in understanding is? ;)<br/>
probably your IMU measure the angle rate in &ordm;/s like mine. so you have the angle already in degrees. <br/>if(teta&gt;-1 &amp;&amp; teta&lt;1) teta=0; //avoid drift error &lt;- when you integrate the signal from the IMU if the IMU doesn't stay still, an error will be summed to the angle, so, this line try to prevent this.<br/>the line() function on processing works in rad, so we have to make a conversion, that's why I use the function radians(270+teta); i really don't remember why i choose this value of 270, but i know it's work fine for me, xD<br/>if you need some other explanation, feel free to ask.<br/>
Thank you for the answer. Well then I will go for trial and error, to find out what that 270 does there! Your software is anyway nice! It didn't need any alteration when I uploaded to my Arduino, and worked fine with my IMU. I am doing the same thing, i.e. balancing a robot, toward DIY Segway. What I have now, is good tools for Kalman filtering the balancing process. I am seeking complementary filter code and information. It would be nice if we could share info ;)
Nice, I almost finished my DIY Segway, but it doesn't stay on the vertical, xD.<br/>Soon I will post some information about it. <a rel="nofollow" href="http://web.mit.edu/first/segway/">http://web.mit.edu/first/segway/</a> Here you can found some information about sensor merging and filtering. My hole project is based on this. I'm using an accelerometer from a nunchuk to have the acceleration and the angle, that way I have two angles, and avoid the drift error from gyro. I have some documentation but it is on portuguese. <br/>Plz send a PM with your email and I cans send it, and more informations for you.<br/>Good luck <br/>
I received your email, thanks, but when I answered you, the mail was returned saying "access denied". :((
its not a gyro, its an accelerometer. a gyro has a spinning disc to keep it stable
this is a gyroscope, this is the datasheet from this <a rel="nofollow" href="http://www.epsontoyocom.co.jp/english/product/Sensor/set01/xv8100cb/index.html">http://www.epsontoyocom.co.jp/english/product/Sensor/set01/xv8100cb/index.html</a><br/>
nice, i will try it latter, ty
cool! what you need to do is get it to send this data to a lcd screen so you can see it with out a computer.

About This Instructable




More by otaviousp:CNC G-Code Interpreter using Processing How to connect Arduino and RFID Angle measurement using gyro, accelerometer and Arduino 
Add instructable to: