Arduino, Gyroscope and Processing
Arduino, Gyroscope and Processing
Arduino, Gyroscope and Processing
Table of Contents
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Step 2: Building . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Step 3: Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Step 4: Turn on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
http://www.instructables.com/id/ArduinoGyroscopeProcessing/
Intro: Arduino, Gyroscope and Processing
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).
Image Notes
1. angle indicator
File Downloads
arduino_gyro.pde (2 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'arduino_gyro.pde']
StandardFirmata.pde (7 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'StandardFirmata.pde']
http://www.instructables.com/id/ArduinoGyroscopeProcessing/
Step 1: What you need?
You will need:
- Breadboard
- Microcontroller, I used the Arduino board
- Wire
- Jumper Wires
- Gyroscope XV-8100
Image Notes
1. Vout pin
2. Vdd pin, connected to 3.3V
3. Ground pin
4. Epson gyro sensor XV-8100
Step 2: Building
The circuit consists of a gyroscope connected direct to port 0 from your arduino. Some capacitor added to reduce noise from analog value.
http://www.instructables.com/id/ArduinoGyroscopeProcessing/
Image Notes Image Notes
1. filtring capacitor 1. wire connected to arduino
Image Notes
1. from sensor
Step 3: Software
To communicate the arduino with the processing I used the standard firmata code, the same found inside the arduino's library. This library automatize the communicate
process between the arduino and firmata. So is not necessary any modification at the arduino code. We will gone just edit the processing code according with our desire.
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
void setup()
{
size(400,400);
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[1]);
arduino.pinMode(ledPin, Arduino.OUTPUT);
frameRate(60);
delay(500);
}
http://www.instructables.com/id/ArduinoGyroscopeProcessing/
float count= 0;
float valor =0;
float aux1=0,aux2=0;
int[] contador={
0,0,0};
float first_time, time;
float teta=0;
void draw() {
background(150);
fill(250,250,250);
arc(200,200,100,100,0,TWO_PI);
if(first_try==1){
//delay for arduino initialization
delay(2000);
first_try=0;
if (mousePressed == true) {
fill(255,0,0);
aux1=0;
aux2=0;
contador[0]=0;
contador[1]=0;
contador[2]=0;
teta=0;
arduino.digitalWrite(ledPin, Arduino.HIGH);
}
else {
fill(0,0,0);
arduino.digitalWrite(ledPin, Arduino.LOW);
}
//####################################################################//
// //
// Gyro //
// Scale Factor 2.5mV/ �/s = 0.512 counts/ �/s //
// Offset 316 counts = 1562mV = 1.562V //
// ADC 4.88 mV/count // 0.2048 count/mV //
// //
//####################################################################//
count =0;
for(int i=0;i<20;i++){
time=millis()-first_time;
first_time=millis();
teta=teta+valor*time/1000;
if(teta>-1 && teta<1) teta=0; //avoid drift error
PFont font;
font = loadFont("EngraversMT-48.vlw");
stf = str(teta);
textFont(font);
text(stf,150,270,200,200);
println("teta: "+teta+" count: "+count+" time: "+time+" valor: "+valor);
line(200,200,50*cos(radians(teta+270))+200,50*sin(radians(teta+270))+200);
http://www.instructables.com/id/ArduinoGyroscopeProcessing/
Step 4: Turn on
Now that we have all we gonna need, lets uploaded the standard firmata code at arduino. The code is found inside the library folder of your arduino.
The processing code I posted at the previous page. The code initialize the firmata library read the analog port and plot it at your desktop .
The processing code need a little tune and I'm working on it. As soon i fix I will edit the code here. Feel free to edit and improve the code for a better performance, and let
me know.
Turn on the arduino, compile the code and you gonna see a circle with a line at middle, wait a few seconds and click at the circle to reset the angle
When you turn the bread board, the line will turn to the same side.
http://www.instructables.com/id/ArduinoGyroscopeProcessing/
Related Instructables
Comments
41 comments Add Comment
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.
Is that possible? Do you know something about poor A/D conversion with arduino.
What kind of dynamic shows your realization?
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.
The angular value is slowly drifting apart when gyro is kept steady
(no force applied).
But I have just found out that in your code you have this constraint:
to avoid drifting.
I would like to change it to:
Thanks.
http://www.instructables.com/id/ArduinoGyroscopeProcessing/
otaviousp says: Nov 22, 2010. 7:33 AM REPLY
Have you change de offset value?
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.
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.
This produce, anyway, a drifting value for teta which keeps increasing or decreasing (depending on the value i choose for offset).
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.
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define FASTDAC 1
#if FASTDAC
#define DELAY 10 // delay in ms
#else
#define DELAY 50
#endif
so you can use less than 10 ms as delay time in between A/D calls.
I tested this with 5 ms delay and A/D conversion worked grate.
Thanks.
http://www.instructables.com/id/Accelerometer-Gyro-Tutorial/
//####################################################################//
// //
http://www.instructables.com/id/ArduinoGyroscopeProcessing/
// Gyro //
// Scale Factor 2.5mV/ �/s = 0.512 counts/ �/s //
// Offset 316 counts = 1562mV = 1.562V //
// ADC 4.88 mV/count // 0.2048 count/mV //
// //
//####################################################################//
count =0;
for(int i=0;i<20;i++){
time=millis()-first_time;
first_time=millis();
teta=teta+valor*time/1000;
cya
so, if you read from the adc channel a value like 2, this means 3.9 º/s
2 / 0.512 = 3.9
http://www.instructables.com/id/ArduinoGyroscopeProcessing/
otaviousp says: May 20, 2010. 6:13 AM REPLY
When you leave your gyro on a stationary position, probably you wont read a ZERO value.
So, if you extract the value you are reading from the offset you will have ZERO.
Thanks this realy helped a lot because there isnt much about gyros or 6DOF on arduino.cc
cya
Right now I have it set so if I type "T" into my serial monitor, it sends the command out digital pin 9, through my relay, and "presses" a button on my TV
controller, thus turning it on.
Can I do something so that pressing a button in my Processing sketch would be like typing "T"?
void draw() {
fill(fillVal);
rect(25, 25, 50, 50);
}
void keyReleased() {
Serial myPort;
myPort = new Serial(this, Serial.list()[0], 9600);
if (keyCode == 'T') {
println("T key pressed");
myPort.write("T");
}
I'm pretty new to Processing, so I'm not too sure of all it's capabilities.
http://www.instructables.com/id/ArduinoGyroscopeProcessing/
otaviousp says: Dec 15, 2009. 3:59 AM REPLY
NP, xD
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 A and A' will mesure the
anti couple
http://www.instructables.com/id/ArduinoGyroscopeProcessing/
TXTCLA55 says: May 6, 2009. 8:20 AM REPLY
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.
http://www.instructables.com/id/ArduinoGyroscopeProcessing/