Low Cost Gyroscope – Accelerometer Combo Project In building a balancing robot you need a Gyroscope unit and an Accelerometer unit in order to get it to balance. But I also wanted it to be reasonably low in cost and easily interfaced to a MCU. Some of the other solutions are prohibitively expensive, even if they may work well. Also the solution I had in mind had to be small and use up little space and use up little power too. So when Analog Devices (http://www.analogdevices.com) recently came out with their ADXRS150 and ADXRS300 piezo-gyroscope integrated circuit, I now had a solution that had low cost and low power with high performance too. Steve Insert a picture here (gyro pcb populated 2.png) I also took advantage of the small size and combined an Analog Devices Accelerometer integrated circuit on the same PCB to maximize performance. Plus there are no moving parts per se to complicate the issue. All the good stuff is contained inside the chips. Using the two Analog Devices ADXRS150 and ADXL202 we can build a combo PCB for under $100.00 in parts. In this case at the Analog Devices http://www.analogdevices.com web site, they are selling the gyro for about $39.90 in singles and the Accelerometer for about $29.90 in singles. I know that the Express PCB service charges about $62 for three mini-boards, so one board costs about $20, then we have about $20 for all the other parts, since the PCB uses up only a small portion of the whole PCB blank, you can put in a few other needed layouts for other things on the same PCB and cut them out later as you need them. I usually use a scroll saw to cut out the small PCBs. In some cases you could obtain samples of these chips, or as they start to fill in the vendor pipeline, you’ll be able to get them at better prices through the vendors and distributors. Steve insert picture (Gyro PCB layout image.bmp) Can you please do whatever it was you did to invert the colors like on the servo tester project. I couldn’t get it to work right myself. Other interesting gyro solutions are: You can, off and on, get nice Murata Piezo Gyros for $40 each from http://www.proxyone.com/cgi-bin/nphsrch.cgi/000000A/687474702f7777772e616e64726f6964776f726c642e636f6d2f70726f6434372e68746d But these tend to go to the manufacturers first, so sometimes it is difficult to get one. Gyration sells a micro gyro academic kit for about $450; it has three gyros in the kit. http://www.gyration.com/MG100-starter.htm of course it costs a whole lot more if it is non-academic. Microstrain sells a number of different gyro modules starting at $295 up to around $1495. http://www.microstrain.com/index.cfm The old classic approach is to obtain RC hobby model aircraft gyros and use them. These gyros run in cost from about $69.00 on up to several hundred dollars, depending on the model or type. A source to check out is http://www.towerhobbies.com or even better a RC specialty store like Helicopter World at http://65.215.192.230/Merchant2/merchant.mv Then the most basic method is to use a potentiometer with a pole or pendulum attached to it. You feed the wiper output from the potentiometer to an ADC and then you can determine your position or tilt angle. This is the standard classic approach to balancing robots that balance a pole on top of them. But you could invert it as well. Usually you would still have to have some kind of a reference to the floor or tabletop for the robot to know where the floor is. But you could trail a potentiometer with a small arm touching the floor behind the robot for this purpose as well. Although a RC hobby gyroscope is cost effective, it is a bit difficult to interface to a MCU. The gyro is designed for RC model airplane servos that work with a 1 to 2ms-width pulse train. Thus 1.5ms is neutral, 1ms full one way and 2ms full the other way. Using a MCU you have to transmit the 1.5ms neutral signal to the gyro, then receive the pulses from the gyro and translate them into something more meaningful for you to use. The next problem is you basically have to have the MCU stop for up to 2ms to read a pulse width, before you can do something with it. Depending on the MCU you might have to have the MCU send the the 1.5ms pulse as well, eating up even more time. That 2ms may be very critical to other things going on. But if we use the gyro chip, we can use a ADC (analog digital converter) to convert the analog voltage level to a numerical value much faster, plus you could, in some cases, start the ADC to get a value, and come back later for the result. We can now reduce the time to get a numerical value down to microseconds instead of milliseconds. Thus we get better accuracy, and faster performance. If you use a high performance DSP processor, you may be able to get this down to less than a microsecond to read a voltage level. The more expensive gyroscope systems, unfortunately, tend to be prohibitively expensive. So although they are really neat solutions, I didn’t pursue them any further. Without going into all the engineering gobblygook, the basic way the ADXRS150 or 300 Gyroscope IC’s work, is they output a 2.5 volt level at rest. If the gyro is tilted one way or the other, then it will output up to a +/voltage change from reference. This is an analog level that you need to feed into an analog digital converter (ADC) for a MCU to use. The ADXRS150 has about a 12.5mv per degree of sensitivity, for up to about 150 degrees per second of tilting. This can be adjusted some more as needed too. The voltage change is proportional to the speed or rate of the tilt angle. The faster the robot tilts the larger the change in voltage. The ADXRS300, as a higher performance device, gives about 300 degrees per second of tilting. If you want more information about the chips, please go to the www.analogdevices.com website and download the spec sheets and documentation on the chips. Also get the documentation on the accelerometer evaluation board as well. I expect Analog Devices to have an evaluation board for the gyroscope IC pretty soon as well. Gyro circuit at rest: Steve Insert picture (gyrorest.png) Gyro circuit tilted forward rapidly: Steve Insert picture (gyroFwd.png) Gyro circuit tilted in reverse rapidly: Steve Insert picture (gyroRev.png) The ADXL202 Accelerometer is a really neat device in itself. It basically outputs a pulse string, and changes the duty cycle as the unit is tilted. Plus the change stays at the tilted angle until you change it to a different angle. Thus it makes for a really handy reference point type of device, such as where is “up” versus where is “down”. Using a gyroscope by itself seems reasonable, but the gyro develops a slow creeping tilt error that continues to increase. An example of this is when you tilt the gyro you’ll see a change in the output voltage, but it quickly returns to it’s resting level, if the tilt doesn’t change. Thus if your robot was to tilt forward a few degrees and stay at that angle, the gyro will report that the robot is standing straight up after a second. So eventually the errors add up and the robot falls over. Using an accelerometer helps to solve this problem. The accelerometer outputs a steady duty cycle when the robot is standing straight up, and if the robot tilts one way or the other the duty cycle changes, and stays changed, until you have the robot’s computer correct for the tilt. Now on the surface it looks like you could use only the accelerometer, but the gyro reacts much faster to tilt changes than the accelerometer can. So the gyro gives you the fast response and the accelerometer helps to correct for the creeping gyro errors that will occur and tells you when your level or not, or where up and down is. I basically followed the designs as put forth by Analog Devices, but I did add more filtering into the power line for the gyroscope chip. Without the additional filtering you run the risk of noise causing too many spurious readings, which would cause more problems. I also kept the two circuits somewhat separate in order to ensure that the noise generated by the Accelerometer doesn’t interfere with the Gyroscope or vice versa. Plus the additional filtering is needs as the MCU or electric motors will generate additional power line noise as well. Except for mounting the gyroscope IC, building the PCB is fairly straightforward and simple. But do be extremely careful with the surface mount capacitors as they are not marked and they typically all look alike. I would suggest taking the capacitors from their package one at a time and soldering them down one at a time to ensure you don’t mix any up. Also note that the two IC chips are complex and sensitive to static electricity so you need to be careful with them. I use a small X-Acto knife to help hold the little parts down as I am soldering them. Sometimes a bit of air gets trapped under the part and it’ll pop off from the heat as you solder it. When the part goes poof and pops off the PCB you can’t find it on the desk or floor, so you have to go get another one. Mounting the gyroscope IC is a big problem as it is a BGA (Ball Grid Array package) that is about ¼” square in size. The 32 little pins are .020” in diameter and are about .015” apart. In looking at the chip, it had me spooked for quite a while. There may be other ways of doing it, but the three that I know of are: One), you can use a IR oven designed for soldering these parts onto PCB’s; Two), you can use a hot air SMD rework station to heat up the parts and solder them; Three), you could heat up your oven to 300 degrees and then stick the PCB with the gyro on it into the oven and cook it for about 5 minutes or so (I have not ever tried this method though). In the oven methods, I’ve seen them use some kind of a PCB pre-heater to heat the PCB up to near 300 degrees, but just short of where the solder starts to melt. Note that a unique characteristic of the soldering is as the solder melts it sort of self aligns the chip onto the pads, based on the surface tension of the solder in it’s liquid state. I suggest you build the Gyroscope circuit first and test it, then build the Accelerometer circuit and test it. There is an option to use a common single 78L05 voltage regulator on the PCB, but I decided that might be risky, as it may introduce too much RFI noise back into the Gyroscope circuit, from the Accelerometer circuit. I also left several empty pads for additional filter capacitors, should I need them. Although I used a 47uh inductor to attenuate noise on the VCC line it is possible to leave this off or change the inductor value as needed, depending on your environment. I also left a couple of shorted pads on the PCB layout for an optional filter diode, should you want even more noise filtering. The two parts only draw about 3-5ma of current, so they won’t load down your battery power any. If your running directly off a 4.8v battery, you could leave off the 78L05’s and run a jumper to bypass them. I would probably use the filter diode in this case though, as RFI or noise can get into the circuit more easily. The secret to making this work is to use liquid flux. Also you can’t use just any flux, it has to be a non-corrosive flux. Some flux will be trapped under the gyroscope IC, thus corrosive flux residue would be bad. I like to use GC Electronics number 10-4202 Liquid Solder Flux myself. The thin paste fluxes would work too. After the solvent evaporates some it gets nice and sticky, which helps aid in holding parts in place. The flux also is invaluable in helping to prevent solder bridges from occurring when soldering. Then of course it also serves as an aid in getting the parts to solder well. After you have completed the PCB you can use some denatured alcohol to clean off the flux. Gently using an old toothbrush helps with the cleaning too. First we need to mount the gyro chip. Since this is the hardest part, we need to do it first. In my case I opted to use a hot air SMD rework station. So we need to apply some flux to the PCB, and wait a little while for it to get sticky. Then we carefully align the gyro chip onto the PCB using the corner guides I had etched into the PCB. Note that there is a little arrow on the chip that should match up to the Rate Out corner on the PCB. Steve insert picture (gyro pcb 2.png) Now with the SMD tool all heated up good and adjusted to a low air pressure setting, we carefully and gently hold the chip in place with a X-Acto knife blade tip and use the hot air SMD tool to heat up and melt the solder on the chip onto the PCB. This is tricky as we need to only lightly apply enough pressure to hold the chip from moving from the hot air, plus we need to move the hot air nozzle around evenly so as to not burn anything. The whole operation should take about 2-3 seconds. After getting it soldered, carefully move everything away and be extremely careful not to jiggle the PCB until it cools down. I used a PCB holding vice/stand unit for this purpose. Steve insert picture (Gyro PCB populated .png) Now after it has cooled down, take a digital multimeter and check to ensure that none of the adjacent pins (that aren’t connected together) have become shorted. If it’s OK you can then proceed to mount the other parts on as needed. If you do have a short, you’ll have to use the SMD tool to remove the gyroscope chip, then “re-ball” the chip’s pins, remove any excess solder from the pads on the PCB, and repeat the process again. “Re-balling” is basically putting a tiny dab of solder back on each pin; it’ll form a small half sphere in the pin as it cools. Which is tricky as the pins are so darned small. Steve insert picture (gyro pcb populated anotated .png) Building up the rest of the Gyroscope circuit is fairly easy now. Note that on the back there are two caps, a 47nF cap and a 100nf cap. In the Analog Devices spec sheet they stated that these two parts have to be as close as possible to the chips pins to help avoid RFI noise problems. I also put in a 2.2uF tantalum on the back of the PCB, but I don’t think it is really needed, but I wanted to cut noise as much as possible. Steve insert picture (gyro pcb reverse side.png) After getting it all soldered down, we now come to the scary part; Powering it up. But before you apply power, use your multimeter to ensure we don’t have a short to ground someplace. With the PCB at rest, apply power. With a multimeter you should read a voltage of approximately 2.5v on the Rate Out line. Now taking the PCB carefully in your hands (you don’t want any of the wires, you may have hooked up, to short against anything) hold the PCB in a vertical position. As you tilt the PCB from side to side you should see the voltage out from the Rate Out line change. Tilting faster increases the voltage change, tilting gently just causes a little change. Using an oscilloscpe you can watch the gyroscope in action, also note how clean the signal is with little or no RFI noise to cause erratic readings: Steve insert picture (gyrorest.png) After building the gyroscope circuit, you can now finish up and build the Accelerometer circuit. This is actually pretty easy as it has only a few simple parts to mount. Nothing complicated like the BGA part on the Gyroscope IC. Plus all the parts are on the same component side of the PCB. Steve insert picture (gyro pcb populated 3.png) Make sure you don’t have a short. Then power it up. This is a bit harder to test, as you really need to use an oscilloscope to see the pulse train outputs on the X and Y output lines. But a quick and dirty test is to run a multimeter with an AC input and see if you can measure the output. As you tilt the unit back and forth, you should see the average AC voltage change a little from the duty cycle changing on the pulse train. Another way is to simply use a logic probe and see if you have a pulse train output running. Using an oscilloscope, you’ll be able to see the pulse train at about a 50% duty cycle. As you tilt the unit you’ll see the duty cycle increase or decrease as the tilt increases or decreases. Accelerometer at rest, 50% duty cycle: Steve Insert Picture (acellerator00.png) Accelerometer tilted one way and then the other, note that the duty cycle or pulse width changes on the oscilloscope: Steve Insert Picture (acellerator02.png) Steve Insert Picture (acellerator03.png) Everyone should actually be able to obtain an oscilloscope. I got mine off of www.ebay.com a long time ago for about $14.00 plus shipping. The probe cost me $15.00. An oscilloscope is invaluable in checking things out on electronic circuits, as you get to see things easier. Tuning and debugging circuits are so much easier with an oscilloscope. At this point if everything is working OK, you’re in business. Depending on the MCU or processor your use you can use an internal or external ADC to convert the Gyroscope’s analog output into a digital value for processing. You would typically measure the pulse width of the accelerometer and determine the duty cycle to get the tilt angle. At this point it is all up to your imagination. Please note that the PCB is designed to stand up on its edge, not down flat. You’ll need to allow for that if you are using it in a balancing type of robot. I plan to build up an Atmel (www.atmel.com or www.avrfreaks.net) ATTiny26 MCU based PCB (I had to have something to fill in that empty space on the PCB that I sent off to Express PCB to have made). The ATTiny26 MCU has 2k of flash program space and 10 ADC channels along with two PWM channels as well. My plan is to use the Gyroscope/Accelerometer combo PCB along with the ATTiny26 PCB running as a coprocessor and have an autonomous balancing unit controlling the motors on the robot. The main MCU or computer would then tell the ATtiny26 to move forward, backwards, turn, stop et cetera. Also I have been tinkering with a New Micros (www.newmicros.com) ISOPOD DSP MCU and I might use it instead, as it has a lot of performance going for it. It is so fast that it could replace several MCU’s and still have time to do other things as well. Thus I wouldn’t have to use co-processors to offload processes and tasks to. Details: Schematic Part 1 (ADXL202 Schematic.png) Schematic Part 2 (ADXRS150 Schematic.png) ExpressPCB Schematic (Gyro Accelerometer Combo Schematic.sch) ExpressPCB PCB layout (Analog Devices ADXr150 Gyro combo ADXL202E Accellerometer PCB.pcb) The ExpressPCB ( www.expresspcb.com ) software is offered for free to those who want to use it. Parts List: Gyro circuit: 3 22nF ceramic capacitors 25v or 50v 805 size (note the charge pump capacitors need to be 25v or greater) 1 47nF ceramic capacitor 25v or 50v 805 size 2 100nF ceramic capacitors 25v or 50v 805 size 1 1.5uF electrolytic 16v or 25v or 50v 1 47uF electrolytic 16v or 25v or 50v 1 2.2uf tantalum 16v or 25v 1206 size (note this is optional) 2 47uH inductor 1210 size (note this could vary depending on conditions, up to 470uh or even 1mh) 1 78L05 voltage regulator IC TO92 package 1 ADXRS150 or ADXRS300 Gyroscope IC Accelerator Circuit: 2 .047uf ceramic capacitors 25v or 50v 805 size (note these are tunable, see specs) 1 .47uf ceramic capacitor 25 v or50v 805 size 1 124k ohm 1% resistor 805 size (note this is tunable see specs) 1 1.5uf electrolytic 16v or 25v or 50v 1 47uf electrolytic 16v or 25v or 50v 1 78L05 voltage regulator IC TO92 package Copyright © 2002 Dallas Person Robotics Group The Quickie Servo Tester code, schematic and PCB artwork are licensed under version 2 or later of the GNU GPL. This means everyone has the freedom to use this design for any purpose, to study it, to copy it, to distribute it, and to change or improve it, provided such changes are also made freely available to everyone.