Shop OBEX P1 Docs P2 Docs Learn Events
How to use a digital barometer with the BS1 — Parallax Forums

How to use a digital barometer with the BS1

ghost13ghost13 Posts: 133
edited 2007-08-17 03:02 in BASIC Stamp
I have the BS1. Right now, I am developing an altimeter for rocketry. I'm currently using an analog barometric sensor and then using the LTC1298 ADC. Unfortunately, either the readings are too slow, or my conversions are off, but my end result is about 200 to 300 feet off from my commercially made altimeter.

So, I have considered my options and decided to go with a 17 bit digital barometric sensor. It is here:
www.sparkfun.com/commerce/product_info.php?products_id=8161

I want to get it, but before I invest the $60, I want to make sure it will work with the BS1. Also, I know how to hook up the 3.3V and GRND pins, but the other 5 utterly confuse me. I looked at the datasheet... and... well... got more confused shakehead.gif

So any advice would be greatly appreciated... THANKS!!!!! tongue.gif
«13

Comments

  • JonathanJonathan Posts: 1,023
    edited 2007-06-30 14:37
    Ghost,

    I have never used a BS1. Taking a look at the sensor briefly, I can see it uses SHIFTIN/SHIFTOUT, so if the Bs1 has those commands, it should work.

    Nice looking sensor, but a little expensive. I built a altimeter using a cheap Motorola MPX4115A. I got it to work pretty well, getting within 20 feet of my *very* expensive climbing altimiter. Seems like that is adequate for a rocket. I was using the BS2 and an LTC1298.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-30 14:43
    The BS1 doesn't have the built-in SHIFTIN/SHIFTOUT commands, but can be used with devices that use a clocked serial data transfer. See the Nuts and Volts column #4 (www.parallax.com/dl/docs/cols/nv/vol1/col/nv4.pdf) for one example.
  • ghost13ghost13 Posts: 133
    edited 2007-06-30 20:04
    The BS1 does have a SHIFTIN/SHIFTOUT command. [noparse]:D[/noparse]

    Any advice on what all of those pins connect to? I'm a bit confused...

    Thanks!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-30 20:19
    The BS1 does not have a SHIFTIN/SHIFTOUT command. Check the manual.

    Most SPI interfaces have 4 pins, MasterOutSlaveIn (MOSI), MasterInSlaveOut (MISO), Clock, and Chip Select. Depending on the device, sometimes you can connect MOSI and MISO together (if only one is active at a time) to save a pin. The example I mentioned for the BS1 and LTC1298 would be similar to what you need since the LTC1298 is an SPI interface device as well.

    Your pressure sensor is a 3.3V device and the BS1 is a 5V device. You need to put current limiting resistors (like 1K) between the BS1 pins and the pressure sensor pins to protect the pressure sensor. Have a look through the thread on mixing 5V and 3.3V devices that's at the beginning of the Propeller forum.
  • JonathanJonathan Posts: 1,023
    edited 2007-06-30 20:39
    Ghost,

    It sounds to me as if you should be able to get better results with your current set up. For one thing, what is the output range of your current sensor? If it is less than 0-5V, like say 0-3V, you can use a voltage refernence of 3V for the LTC1298. This will increase your resolution.

    Also, have you used a pot to check that the LTC1298 is indeed reading correctly? If it is, is the input set up as it should be? Tracy Allen, math whiz that just saved my butt, has a great page on his website about ADCs.

    http://www.emesystems.com/OL2tlc2543.htm

    The link above is about using a different ADC, but the same principals apply.

    There are other things you can do. For example, if you have bouncy readings, you can add a small cap on the input to smooth it out. It will however slow down the reaction time. You can sample and average to reduce jitter too. So, tell us more about your setup, what you have tried and what happened. Then maybe you can save the $60. [noparse]:)[/noparse]

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • ghost13ghost13 Posts: 133
    edited 2007-07-03 07:25
    Here's the problem. This altimeter will be used for model rocketry. Therefore, it should be within 10 feet of my commercial altimeter. So, when testing, I first looked at my altimeter's "ground" altitude. It correctly reported 784'. Then, I put both altimeters in a jar jar and sucked out the air, creating a vacuum. When I let air back in, they both reported an altitude. The first report was 300' higher than the commercial one. The second report was 200' lower. The next one was 100' higher. Then next 300' lower. It seems like something is seriously wrong, but it computing the ground altitude correctly so I am completely confused shakehead.gif
    Any suggestions? The code and schematics are attached...
    And I'm using the LTC1298:
    www.linear.com/pc/productDetail.jsp?navId=H0,C1,C1155,C1001,C1158,P1445
    and the MPX4115AP:
    www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPX4115&fsrch=1

    Thanks for your help [noparse]:)[/noparse]
    This is getting really frustrating [noparse]:([/noparse]
  • ThaMnoSThaMnoS Posts: 2
    edited 2007-07-03 13:45
    At my univercity we have a class that deals with BS1 circuits and applications. When i will be done with it(probably next cemester) i promise to upload all the circuits along with the code...perhaps it would help anyone who wishes to make a complicated application or simply take ideas!
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2007-07-03 15:01
    ghost13, I'm trying to understand your experiment. Was the commercial altimeter inside the jar with the other 4 of your homemade altimeters when you took the pressure down and back up? Or were you comparing the reading of your 4 altimeters only at ambient pressure, before and after the excursion in the jar? I wonder if a sudden pressure change might be bad for the MPX4115AP, the kind of pressure change that would come from suddenly letting all the air back in.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • pwillardpwillard Posts: 321
    edited 2007-07-03 18:16
    Are you keeping track of how much current each portion of the project is taking?

    I'm concerned that your electronics portion of the design is not robust enough.· You are running all this off of a 9V battery, right?· When the G-Switch kicks in, how much does your load on the battery increase?· A 9V battery will probably need a good deal more current available to fire the Nichrome fuse..


    Also... this circuit is ONLY for parachute deployment, right?

    Do you plan to have maybe a backup option?· Like, regardless of height from the transducer (not >850'), if 15 seconds elapse since launch, fire the Nichrome?

    Pete

    Post Edited (pwillard) : 7/3/2007 7:44:55 PM GMT
    1025 x 660 - 14K
  • ghost13ghost13 Posts: 133
    edited 2007-07-03 18:19
    Sorry for the confusion. Here is the experiment. I put both the homemade and commercial altimeters in the same jar, at the same time, created a vacuum and re-equalized the pressure. The altimeter readings were very off, as described in my last post. Then, I had my home-made altimeter beep-out the ground altitude before the apogee one. The ground one was correct, but in the jar test, the readings were just as far off.

    I also let the air back in fairly slowly... I just created a vacuum quickly. And I know the MPX4115AP is used a lot in commercial rocketry altimeters, so creating the vacuum quickly shouldn't be a problem...
  • JonathanJonathan Posts: 1,023
    edited 2007-07-03 19:09
    Ghost,

    I'm still curious to know if your ADC is reading correctly and stable. Does it read correctly if you use a pot? The sensor is supposed to output 45.9 mV/kPa, so if you use a 10 turn precison pot, does it all read as it should? Can you test the sensor with a voltmeter in your test chamber to see if it is putting out as it should?

    BTW, I had a typo in my first post, my results with the same sensor where within 200 feet, not 20 feet as I posted.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • ghost13ghost13 Posts: 133
    edited 2007-07-03 19:17
    I really need, at worst, a 20 foot accuracy. I do not know how to hook up the pot and there is no way to test the voltage inside the chamber. I do know the ADC is working, though, because it correctly reads the ground altitude.
  • JonathanJonathan Posts: 1,023
    edited 2007-07-03 20:07
    20 feet accuarcy is asking a LOT. Too much, even. My very, very expensive (US$400) climbing altimiter does not claim that degree of accuracy. And it is pretty much the best you can buy. 20 foot resolution, sure.

    Also, I would not assume that because it seems to read correctly at one end of the range that it must be reading correctly at the other end of the scale. Nor does it mean the sensor is working properly.

    From a troubleshooting perspective, I would want to take the small amount of time required and make sure my set up was working correctly. A pot is really easy to hook up. Get a 10 turn pot of say 10 to 100k. Hook up one end to + and the other end to GND. The center lead will have a voltage that varies with turning the pot. This way you can check the full scale.

    Also, do you have the 750 ohm series resistor and .033uF cap reccomended on the output of the sensor?

    Can you put a voltmeter on the sensor, supplt it with 5V and stuff that in your chamber? Then you could verify easily that sensor is OK.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • ghost13ghost13 Posts: 133
    edited 2007-07-03 20:36
    Commercial rocketry altimeters have 4 foot accuracy. The digital sensor had 4" accuracy.

    Where is the .033 cap supposed to go? I don't have that... I also don't have the 750 ohm resistor
  • FranklinFranklin Posts: 4,747
    edited 2007-07-03 21:03
    Did you fix your circuit to include a real ground on the pressure sensor?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • ghost13ghost13 Posts: 133
    edited 2007-07-03 21:22
    All the components are connected to the battery's - terminal, so yes.
    Sorry for the confusion with the schematics. I'm new at this blush.gif
  • pwillardpwillard Posts: 321
    edited 2007-07-03 21:44
    Check my post above... I tried to draw a cleaner schematic
  • JonathanJonathan Posts: 1,023
    edited 2007-07-03 23:44
    Ghost,

    The data sheet shows where to hook up the cap/resistor. It also shows the proper power supply side decoupling caps. You are running on a battery, so probably those are not too big a deal, but I'd include 'em anyway, just for say-so's sake.

    I think we may be talking at cross purposes about accuarcy. Do you mean resolution, meaning that the sensor can detect a 4 foot change in altitude, or that the reading will be correct within with 4 feet? I find it really hard to beleive that it can accuarcy. I mean, the slightest change in baro pressure will spoof the sensor way more than that. My climbing altimeter claims ~ 1 meter resolution.

    I still say you should start from the ground up and make sure the ADC is OK and the sensor is OK before buying another sensor. I suspect the problem is in implementation, not the parts per se.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • LarryLarry Posts: 212
    edited 2007-07-04 00:27
    Somebody said...
    In BASIC Stamp, ghost13 wrote:

    Commercial rocketry altimeters have 4 foot accuracy. The digital sensor had 4" accuracy.

    I'd be pretty careful about those types of claims. When you wrote that, I started hunting around, and found several sites that played fast and loose between the concepts of accuracy and resolution. Just because they reading might be a 16 bit reading, it doesn't mean that it is accurate to that degree. I ain't namin' no names, but one site that popped up pretty early in my googling made a similar accuracy claim in big type, but qualified that further down the page as being resolution.

    Just because a sensor can spit out numbers after the decimal point, doesn't mean that it's accurate. It's not just altimeters. there are similar issues with temperature sensors, compasses, GPS sensors and many other sensors as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • ghost13ghost13 Posts: 133
    edited 2007-07-04 01:58
    perfectflite.com

    And the sensor's datasheet doesn't have that cap or resistor...
    do you mean the ADC?
  • FranklinFranklin Posts: 4,747
    edited 2007-07-04 02:10
    So far you have shown us three different sensor packages, which one are you using and how do you have it connected and what code are you using to read it?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • ghost13ghost13 Posts: 133
    edited 2007-07-04 03:12
    the link above is my commercial rocketry altimeter. My homemade one uses the code from above and the two datasheets I linked to
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2007-07-04 16:32
    Hi ghost,

    The perfectflite ALTxxK altimeter looks like a nice enough device, and they do claim one foot resolution, which is fine, but as others have pointed out, that is not equivalent to accuracy. Their stated accuracy is +/- (0.25% + 2 feet), which means that a t 10000 feet it should be within +/- 27 feet.

    To attain that kind of accuracy, the microprocessor on their device has to do a computation based on an exponential equation, or a table lookup. That is because the relationship between pressure and altitude is not a straight line. It is a gentle curve. Your BS1 program does not have that calculation. In fact, in looking at the program you posted above (altApogee.bs1), I don't see any calculation at all to convert the ADC reading either to units of volts or pressure, much less than to units of altitude. If that is not done, you are comparing apples to oranges.

    Your program does makes use of the ADC reading to flag the apogee and to flash the pyro. Stability of your ADC and sensor is important, because you don't want to detect a noise fluctuation mistakenly as apogee and jump to the Pyro subroutine prematurely. To do that, it is not necessary to convert the ADC reading to any other units. The BS1 does not have the horsepower for much in the way of calculations. Your program does have the statement "if lastread > prev+5", which makes it trigger only when there is a large change going down. That should overcome any noise.

    Back to the subject of the altimeter. If you are interested in the theory behind it, the Portland Aerospace Society has some nice tutorials. Look at the one called PressureAltitude_derived.pdf for a summary of the model behind pressure based altimetry. It is based on a mathematical model of the atmosphere that assumes an ideal gas, a known sea level barometric pressure, and a constant 6.5 degrees Celsius per kilometer decrease in temperature with altitude. But the atmosphere is not an ideal gas in equilibrium and it rarely has exact or constant lapse rate (temperature vs altitude). The model can be refined, but the bottom line is that the accuracy is always limited by our current knowledge of atmospheric conditions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • JonathanJonathan Posts: 1,023
    edited 2007-07-04 17:21
    Ghost,

    I have to say that I really have doubts over the claims made by the maker. It certainly flies in the face of my experience with climbing and airplanes. Even radar based altimeters don't get that kind of accuracy. There are so many variables, from weather, temp., vibrations etc, etc.

    I'm not saying this to be contentious, and maybe the product does what it says. I am saying it because I don't want you to get an unrealistic goal stuck in your head because of the hyped claims by others.

    And how important is it to really know if you are at 12000 or 12200 feet? What I would want is reliable apogee detection. That is worth throwing as much energy, time and equipment as you have. Total accuracy of altitude is nice, but not essential IMHO.

    Also, in your Stamp code I ddin't see a calibration routine to determine starting altitude, which will vary day to day. Or if you launch from a different spot.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • ghost13ghost13 Posts: 133
    edited 2007-07-04 18:16
    First, I do not do the conversion from ADC Vout with the stamp... I do that with an excel spreadsheet. I'll attach that when I go back to my main computer.

    The accuracy is fairly important. I will be using this in a contest where the goal is to get the rocket to 750 feet. I will want the parachute to deploy at exactly 750 feet.

    And how doesn't the stamp calibrate? It gets the ground ADC output when the program first starts... isn't that calibration? If not, how do I calibrate it?

    And one more question: I can't figure out where to put that 750 ohm resistor and 0.033uf cap!!?!?
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2007-07-04 20:00
    With an altitude change of less than 1000 feet it should be possible to use a linear approximation to calculate directly from the ADC output to feet, and the BS1 is capable of doing that. It should attain very good results and hit very close to the 750 foot mark.

    Yes, the zero point is a calibration. That is the value from the ADC at the launch altitude. You need one more point to determine the straight line slope, in units of feet per bit of ADC reading. Given that you can't get that point experimentally by driving up a local mountain, it is possible to get that second point from theory. For the best accuracy you need to know the altitude of the launch site, and the barometric pressure and temperature there at the time of launch (and also the temperature a few hours before if you can). I'd like to see what goes into your spreadsheet. It should kick out a single number that you can plug into the BS1 just before launch to get a reading directly in feet.

    How long do you expect the flight to be? One reason this works is that atmospheric conditions will not change much over that short duration on the order of one minute. When you are using a barometer from an activity like backpacking, conditions can change much in the course of an hour or more, so that the initial calibrations are thrown off.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • ghost13ghost13 Posts: 133
    edited 2007-07-04 20:06
    The flight will always be less than 60 seconds; usually 45 seconds. My spreadsheet simply takes the ADC output and converts it. Is there a number I should be plugging into the stamp?
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2007-07-04 21:32
    >>My spreadsheet simply takes the ADC output and converts it.

    Yes?

    There are a several steps. First is to convert the raw count from the ADC to voltage, second to convert the voltage to pressure, and third is to convert pressure to altitude. All that could be combined into one step so that the BS1 can go directly from ADC reading to altitude above launch site.

    By the way, do you live in an area where you could ride your bike or somehow get a reading from your setup at one altitude and then at a time not too much later get a reading at an altitude something like 750 or 1000 feet higher? Use Google to find altitudes of waypoints. That way you could get a calibration number without having to go through a lot of steps or make assumptions. It would help if you get a current barometer and temperature reading from a local weather station at the same time. That way you can make corrections to your calibration number when the weather changes.

    Suppose you live at sea level, then the conversion from pressure to altitude for short excursions will be around 27.8 feet per millibar. On the other hand, if you live in Denver, the mile high city, as your launch site, then the conversion will be around 31.9 feet per millibar.

    The MPX4115 has its own calibration equation, something like this:
    millibar = (Vread / Vx + offsetFactor ) * scaleFactor
    where Vread is the current voltage reading and Vx is the excitation (power supply) voltage to the MPX4115. The data sheet gives typical values for the offsetFactor (0.095) and the scaleFactor (1/0.0009). But those are only typical values and each MPX4115 will have its own calibration that varies a little from the next one.

    That is why I am asking if you have a nearby hill you could climb and try to bypass all of the intermediate steps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • ghost13ghost13 Posts: 133
    edited 2007-07-04 21:51
  • ghost13ghost13 Posts: 133
    edited 2007-07-05 08:29
    What if I used the GPS module (by Parallax) and the BS2? That is .1 meter resolution.

    Has anyone done this? Will the GPS module refresh fast enough?
Sign In or Register to comment.