Pages: [1]   Go Down
Author Topic: Dgitial Pin status affect sensor value  (Read 774 times)
0 Members and 1 Guest are viewing this topic.
Rome, IT
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I'm a Java programmer but I'm new on Arduino. By now I'm working on simple project just to get knowledge about its world. My current project is rotate a 3d box on my monitor using a gyro sensor.
The sketch for Arduino I wrote is really simple (see attached file) and basically perform the zero calibration of the gyro in setup() method and the measurement on loop() method.
On first test I found that the zero found on setup() method and the values the sensor give in loop() method when gyro is steady are not the same: my code detect angular speed but gyro was not moving.
After hours of attempts I got it: in order to show when my sketch is calibrating and when is reading I use a led. The led is switched on when calibration start and switched off just before setup() method end.
Removing this lines my sketch works fine! This behavior for me make no sense and I was starting think that my board was not working fine. But a friend of mine with more experience on microcontrollers told me this is normal for this type of device.
A the end the question is: is possible to avoid this type of problem? What the best practice in order to avoid this type of problem?
I want to by a 3-axis gyro and accelerometer by Sparkfun (MPU6050) that use I2C communication on digital pin: using this device the AC convertion is done by the chip itself so I should not have this problem... right?


I'm using Arduino Ethernet R3 board and 2-axis gyro from Tinker kit.

Thanks
Ale

* GyroScope.ino (2.2 KB - downloaded 4 times.)
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The MEMS sensors drift.
http://en.wikipedia.org/wiki/Microelectromechanical_systems
The gyro on its own is therefor not enough.
If you use an extra accelerometer, you can stabelize the gyro + accel combination. But you still don't know the direction. So you also need a magnetometer.
If you also want to know the height, you need a barometer. The gyro + accel + compass + barometer is called 10DOF.

You probably want something like the teapot demo:

https://www.youtube.com/watch?v=Rb_T0wrLYUg

For that, you need an accel + gyro. The MPU-6050 is a good sensor for that and are only 5 or 6 dollars on Ebay.
Use the software created by Jeff Rowberg, http://www.i2cdevlib.com/
« Last Edit: March 11, 2013, 09:45:18 am by Erdin » Logged

Rome, IT
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Erdin,

first of all thanks for your reply.

I know the drift problem of this type of sensor and for this reason I go in the direction to buy MPU6050 (that I want use with Kalman filter).

The problem I expose is different: from calibration phase I get, for example (sorry, I don't remember the real value and I have the board with myself), a main value after 50 samples of 532. When the loop() method runs I make some read from sensor (in steady state, of course) and I found mean value of 530.
This if I use the led system in order to notify calibration phase is running.
Removing those lines of code (digitalWrite(PIN_LED, HIGH) etc) I get mean value lower that are comparable with the ones I get on my loop() method.
I know that sensor drift but I cannot understand why light on/off a led on setup alter the values and, final, the drift.

Thanks
Ale
« Last Edit: March 11, 2013, 11:47:26 am by afrancescon » Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, I understand your question now.

The most common things I like to know in this situation: what sensor (with link, copy the url); which arduino board; how is it powered; how is the ground connected; full sketch; code tags.

You gave the full sketch, that's good.
Did you know about the code tags ? You can paste your sketch in the text between the code tags. Above the text input field are buttons. The '#'-button is for the code tags.

About the power supply. If you use USB power, the 5V could drop a little if the led is on. That would immediate have influence on the analogRead() of the sensor. The default setting for the Arduino is an analog reference equal to the 5V. The input range will be full range of 0V to 5V.  If the 5V changes, so does the value read by analogRead().
You could try a external power supply to check this.

The digital MPU-6050 doesn't have this problem ofcourse. But you need a library to get the thing working for you.
Logged

Rome, IT
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Erdin,

as you suggest the problem was in USB power! Using external power supply it works fine. Probably the consumption of LED was enough to change the reference voltage!

My problem is fixed. Just for future information I report here some info:
- Board: Arduino Ethernet Rev3
- Gyro Tinker Kit (http://store.arduino.cc/it/index.php?main_page=product_info&cPath=16_19&products_id=180)
- powered by USB (problem fixed using an external power supply)
Wiring:
- I didn't use Tinker Shield: I connect the Gyro directly to Arduino using a bread board. GND and 5V to respective port on on the board. The X and Y signal to A0 and A1
- a led is connected to digital pin 2 and GND using 200 ohm resistor

Thanks a lot
Ale
Logged

Pages: [1]   Go Up
Jump to: