Saturday, May 28, 2011

gMeter: l'introduction

Preface: As mentioned in the previous post I hit some car trouble in Canada. Actually I had an engine swap, so it's more like a major problem. Between fatigue, sorting that out, and another project in collaboration with ma man Shane, this project is off to a slow and undocumented beginning. To that end, here is an intro while I chip away at the project.

For the longest time I've been interested in doing something with inertial sensors. It's no secret that I am also a car-obsessive, so the logical starting point was to create a g-meter for my car. Does it tell you how "G" or ghetto someone/thing is? No, but later versions may feature a cockometer setting to tell you "how much of a cock you look." Of course, a g-meter measures the lateral cornering force of your car, typically in units of gravities. As a basic reference an average street car can handle just under one gravity, and a formula one car will stay planted while pulling nearly five g's! "How many can the Volvo manage?" I wondered. Time to find out.

Image courtesy of TheEngineersCorner.

The most critical component of this project would be the accelerometer, for which I chose the tried and true 3-axis ADXL335, yours with breakout board for $24. Having no prior experience with accelerometers and no qualitative evidence for comparison I think this is a great sensor. I used it as it came, with 0.1uF decoupling capacitors which restrict the bandwidth to 50Hz. Choosing the bandwidth is a compromise between noise and resolution and the stock setup proved a good balance thus far.

For starters the sensor needed to be calibrated by picking an accurate scaling factor. This is a number in units mV/g which converts the output signal from volts to gravities. The ADXL335 is ratiometric so the data sheet provides experimental values for the scaling factor at the max and min supply voltages. Running the sensor off a 3.3V line I needed to determine the SF in between the given values, which meant linear interpolation. Not the best since clearly the response is not linear, but close enough. To confirm this I devised a shotty test by taping a breadboard with the accelerometer and an Arduino to my dash as a brave friend riding shotgun read the x (lateral axis) outputs off my laptop in realtime. Meanwhile, another friend monitored readings from a free app on my phone and I drove fast (safely, Mom) down a windy road. The results were reasonable, achieving a max of about 0.74g on a particularly tight bend. During this test power was being supplied via USB so I will need to tweak the SF once the power source is finalized, probably a small 2S LiPo.

Quick and dirty g-meter.

This all came together frighteningly quickly. I added an lcd to the mix but even that has a very common HD44780 chipset and pre-made Arduino library of course. I did not like this, and I started to feel guilty about all this Arduino business. Using them is kind of like admitting that you like Britney Spears music...or something. It's just not hardcore. Arduino's are great tools and by no means have I come close to mastering all of their capabilities, but building things shouldn't be like one of those snap-together model airplanes. So instead of soldering what I had together and stuffing it all into a box, it was time to take the project down a windier and potentially bumpy path.

If we're going to dabble in such terrible things as software, then we ought to at least do it right. Enter the AVR ATtiny2313, a very popular microcontroller for small custom applications like this, and most importantly, no Arduino bootloader! In fact, that is the last time I will use the "A-word" in this post. It feels liberating now but pretty soon I'm sure I will begin kicking myself. I bought an AVR ISP II and put together a little target board. In the next few weeks I will work on the software, anticipating that the lcd will probably be the hardest part. No turning back now.

Unnecessary switch, led, and cap. Why not.

After the recent car bill I need to be thriftier than ever. For the circuitry I won't be ordering a shiny new PCB, instead I am researching the process of etching one myself. Failing that look for a perfboard from Radio Shack with a lot of wires. Mechanically, all I can say is I've ordered some 1/16" sheet aluminum...

Monday, May 16, 2011

< Summer Projects >

While studying for finals I realized something, and that is procrastination, NOT necessity, is the mother of invention. With the dark cloud of exams looming overhead my mind naturally started generating ideas for the more exciting ways I could be spending my time. Now that they are over* my ideas are rapidly coming into fruition.

Motors Controllers:

After working with servo's for far too long, I bought some TI SN754410 quad half H-bridges and Sparkfun's cheapest motor, which turned out to also be their smallest! I wrote a quick Arduino/Processing sketch and touchOSC layout to integrate my iPhone control process to this tiny motor. It's very straight-forward, just PWMing the enable pin to control the speed. This was a success.


More recently, a friend handed me a hard drive spindle motor after realizing that a battery and wires alone could not bring it to life. It even has four wires, "what could the extra two do?" he might have asked. I knew it must be brushless and after a little bit of research, it turns out it's a 3-phase BLDC. There is one wire for each phase and the fourth is common. In a trial by fire effort I am in the process of building a controller with some parts I had lying around.


The basic idea is to drive each of the phases with one side with one, or one half-bridge. Thus two SN754410s are used. The Arduino Nano provides the PWMing for the three enable pins, the inputs for the six logic pins, and the back-EMF sensing. The latter will be the tricky part, and I am still doing some reading to determine the best way to do that -both in hardware and software. This is a sensorless motor, meaning instead of onboard hall-effect sensors the position of the rotor is approximated by detecting the back-EMF. Not any easy undertaking, and for now just a clusterfuck of wires.

In the background -or maybe the foreground- another project is in the making. Today I ordered a 3-axis accelerometer and a 20x4 LCD. I've had an itch to start working with inertial sensors for some time and I think I've found the perfect application. Hmm what could those be for? Hint: my car.

*one non-engineering final left