The Memsic Dual-Axis Accelerometer Chapter 3 Parallax Book: Smart Senors & Applications Version 1.0
Keith Hilton
Posts: 150
in BASIC Stamp
I worked through all the scaling samples. Got my LCD working with all the samples. Understood brads to degrees. Figured out measuring rotations, tilt angles. After completing everything in Chapter 3, some of which taxed my brain, I have no idea how to apply this information to something I want to do. I want to do something "real" simple. I would like this tilt sensor to send a variable output voltage to one of the pins 0 to 15. The variable output voltage would be in relation to either the x or y axis and how much I tilt the sensor. I can figure the sine, cosine, tangent, arcsine, arccosine, arctangent --even sweep the numbers between -127 and 127-- and get the debug screen to display numbers. I have no idea how to convert these numbers to an output pin which has a variable voltage in relation to the sweep of -127 to 127. I know there are "many" things this accelerometer will do, but all I am wanting to do is convert tilt to a variable output voltage. Say 0 to 1 volt on one of the output pins. This is a great book, and great work explaining the basic stamp and the many things the accelerometer will do. Problem is, in all the examples---on the debug screen, and LCD-- nothing is directed to be an output on one of the output pins--except the LCD. Not one example beyond the bebug screen and LCD of how to apply this tilt sensor. I would like to see just one example in the book, where the tilt angle of the accelerometer would change the brightness of an LED. Now that is simple. The tragic thing is this: After going through all this complex information, I am not able to change the brightness of a LED with this tilt sensor. Something is wrong with this picture, maybe I am stupid, or thick headed, but I do understand the material in the book. Is there anything-- anywhere-- that would show me an example of the tilt sensor and basic stamp changing the brightness of a LED? Of course changing the brightness of and LED gets back to what I want to do, make one of the basic stamp output pins have a variable voltage in relation to tilt. I am kind of irritated at myself. After all this hard work racking my brain, and working through Chapter 3 and this tilt sensor, I can't even do the simplest of things. Is something wrong with me?
Comments
Controlling a led or producing a dc voltage is actually quite simple to do. All you need is use the PWM function (page 355 of the Stamp manual). It can vary the brightness of a led and current limiting resistor connected to a pin, and if you want a DC voltage an RC filter on the pin can produce that.
Maybe I am wrong, but it seems that 95% of the basic stamp teaching material never gets further than the debug screen. I have found myself wanting samples of stuff leaving the basic stamp, and leaving the debug screen. I worked through a difficult chapter on the Parallax tilt sensor. Got all the numbers correct on the debug screen.
But I do not have a clue what the numbers on the debug screen mean. Are they a string of zeros and ones, are they voltage readings, pulse train---what? See what I mean? In the following tilt display, can someone tell me what the numbers on the debug screen mean? You might ask what application----OK what if I want a variable voltage output related to the tilt. In this example what do the numbers mean? Here is the code--and the code works!
' {$STAMP BS2}
' {$PBASIC 2.5}
angle VAR Word
x VAR Word
y VAR Word
DO
PULSIN 6, 1, x
PULSIN 7, 1, y
x = (x MIN 1875 MAX 3125) - 1875 ** 13369 - 127
y = (y MIN 1875 MAX 3125) - 1875 ** 13369 - 127
angle = x ATN -y
angle = angle */ 361
'LCD Display Routine
SEROUT 14, 84, [ 138, " ",138, DEC angle, 7,
152, " ", 152, SDEC x,
159, " ", 159, SDEC y ]
PAUSE 350
LOOP
You could modify the calculation to show +- g, angle, slope, or any other result that could be deduced from the acceleration measurement. For instance if you put it in a road grader it could measure the slope/grade of the road in both the front/rear and side to side direction.