EOS

Instruments

Barometer Sensor

Programming Exercise in PicAxe

The output of the Philip Harris Barometer Sensor is directly proportional to the barometric pressure of the surrounding air.  The sensor is inside the Blue Box.  The Blue Box output voltage ranges from 0 to +1.0 V, corresponding to a barometric pressure from 950 millibar to 1050 millibar. 

 

Note on units of pressure

The System-International (SI, commonly known as the MKS system) unit of pressure is the pascal (Pa), which is the same as Newton/meter2.   To get an idea of how much pressure is one pascal: an apple has the weight of about one newton, so if the weight is spread over one square meter (about a square yard) it is not much pressure indeed.   One-hundred thousand pascal  (105 Pa) is a unit of pressure defined as the bar, so one millibar (mB) is 100 pascal – a reasonable pressure scale.   The pressure of the atmosphere varies, of course, but it averages roughly 1000 millibar, so the range of the Blue Box is put squarely around atmospheric pressure.

 

Another common unit of pressure is the inch of mercury (inHg).  Atmospheric pressure will produce a height difference in a mercury manometer over a range of about 28 to 30 inches.  More precisely, the conversion is 1 bar = 29.529 inHg.  Notice that the low end of the Blue Box scale is 950 mB = 28.053 inHg.  Useful conversions:

                          1mB = .029529 inHg

                          1 inHg = 33.86 mB

The Assignment

 

Write a program to read the analog input of the PicAxe microprocessor 08M2 at the pin C.1, convert that to barometric pressure, continuously update and display the result on the OLED.  The OLED display must include the word “Barometric” centered on the first line and the second line must display – centered – the current value of barometric pressure with units. 

 

Also, the barometric pressure display must periodically alternate between the two units “milliBar” and “inch Hg”.  Set the timing to an aesthetically pleasing value, about 10 seconds perhaps. 

The simplest solution is to write a Flowchart in Logicator first, then convert the Flowchart into Basic language.  Inevitably, the Flowchart will not be complete so a modification of the program will be necessary.   Use Programming Editor 6 to complete the program.  The Flowchart might look something like this:

Basic commands which might be useful for the solution

First, define some variables such as these:

symbol variablename = pinC.2                         ‘ no space between “pin” and “C.2”

symbol  Vinput = w0

symbol  Pressure = w1                          ‘w0 and w1 are word variables, i.e., 16 bit variables.

 

Commands related to reading the analog input:

             fvrsetup FVR2048

             adcconfig %011

             readadc10 C.2

 

Commands related to displaying the output:

             bintoascii

             serout C.1, N2400_4,(254, 128,”                “) 

             serout C.1, N2400_4,(254, 192, “   “,b9,b10,b11,”          “)

                          Note that whatever is within the parenthesis is displayed on the OLED.

                          Make sure that there are exactly 16 characters or spaces within parenthesis.

                          128 is the leftmost position on line 1 of the OLED

                          192 is the leftmost position of line 2 of the OLED

                          bintoascii converts a binary number to a display character.

 

Commands related to logic and math:

             if   variablename = 0     then . . .

                          endif

             goto (linename)

             VariableA = VariableB * 2 + 800 / 7   ‘math protocol strictly left to right;  integers   only

Power Supply on PicAxe Circuit Board

Power Input:                +7.0 V to +35.0V; connector is center positive; nominally +9.0V dc power adaptor is used (+9.0 V battery for portable use, but avoid if possible since current drain is high - battery won’t last long).

Power Output:            +5.0 V, regulated

                                       200mA maximum current

                                       Red LED “on” indicator.

This power supply is hardwired to both the PicAxe and the OLED display; red lead positive/black lead ground, 0V.

Axe 133Y Serial OLED        

16x2 yellow on black OLED display

Power requirements:    +5.0 V

Axe133Y OLED input, ”IN”, is connected to PicAxe pin C.1 –  green wire.

Note that PicAxe pin C.1 can be used as a serial output to the OLED with the “serout” command.

 

 

 

 

 

 

 

NOTE:                          AXE133Y requires firmware for its AXE18M2 chip; it is already downloaded.  If necessary, however, the firmware can be found at http://www.picaxe.com/downloads/axe133y.bas.txt  (Be sure the line   #define use_OLED   is “uncommented”.)

08M2 Microprocessor                                                                             http://www.picaxe.com/

Power:                                        +5.0 V

Input voltage limits:     0 to +5.0 V

Input leads:                    Red banana plug, C.1

                                       Black banana plug, ground, 0V

In / Out Table:

 

 

 

 

 

 

NOTE:             The red banana plug is hardwired to microprocessor input pin C.2

Notice from the diagram that pin C.2 can be used as an ADC (analog-to-digital) input.

NOTE:  The numbers 1-8 refer to the “actual legs”, not pin numbers.  For example, pin C.5 is actual leg number 2.

Philip Harris Barometer Sensor                    Blue Box

Use only the red and black banana jack connectors on the Blue Box.  Never use the blue banana jack.

 

Power requirements:    +6.0 V; separate external battery pack

                                       Battery pack red lead positive/Black lead ground, 0V

Output (red/black banana jacks):

             Output ranges from 0 Volts to +1 Volt, and is linear in barometric pressure sensed by the probe. 

             Red jack, voltage out; Black jack, ground, 0V.

             Switch in “BATT” position:

             The Blue Box output will be +1.0 V if the battery voltage is +6.0 V.   Replace batteries if this output is below +0.75 V (corresponding to a battery voltage of +4.5 V).

NOTE: Do not use blue banana jack – negative voltage on the PicaAxe input may damage the microprocessor.

Blue Box Manual

Text Box: 01	'BASIC 
02	'converted from flowsheeet; altered:
03	
04	'           	1" mercury = 33.86 mBar
05	'     	      1 mBar = 0.02953" mercury
06	{ ;Symbols
07	symbol Pressure = w0
08	symbol Vinput = w1
09	symbol DeltaP = w2
10	symbol E = w8
11	symbol timecount = w11
12	}
13	main:
14	fvrsetup FVR2048  		'set adc voltage reference to 2.048 Volts (not +5)
15	adcconfig %011    		'first bit (=0) means: adc low reference point is 
16						'Vref- (=0)
17						'next two bits (11) mean: use fvrsetup command to
18						'set adc high reference point Vref+ (2.084 V)
19	let dirs = 0			'sets pins to outputs
20	timecount = 0
21	
22	Cell_7_4:
23		inc timecount
24		if timecount > 80 then  	'arbitrary time units 30, 80
25			timecount = 0
26			end if
27		fvrsetup FVR2048  		'set voltage input reference to 2.048 volts
28		adcconfig %011    		
29		readadc10 C.2, Vinput         'read adc using a 10-bit byte (or, word w12)
30		if Vinput >= 0 and Vinput <= 500 then  'check for on-scale input up to 1 Volt
31			goto Cell_7_5     	'500 bits per input Volt
32		end if
33		goto Cell_7_4
34	
35	Cell_7_5:
36		fvrsetup FVR2048  		'repeat commands for each readadc (?)
37		adcconfig %011    		'
38		readadc10 C.2, Vinput   	'input voltage ranges from 0 to 1V, or 
39							'zero to 100 Torr
40							'zero V corresponds to atmospheric 950 mBar
41							'1 V  corresponds to 1050 mBar
42		let DeltaP = Vinput / 5 	'convert bits to pressure difference above 950
43	
44		let Pressure = 950 + DeltaP   'add to reference 950 mBar
45	
46		if Pressure < 1000 then
47		goto Cell_7_11
48		end if
49							'display pressure if >= 1000
50	
51				if timecount > 30 then  		'arbitrary time units
52					goto Cell_7_15    		
53				endif
54			bintoascii Pressure,b8,b9,b10,b11,b12
55			serout C.1,N2400_4,(254,128,"   Barometric   ")
56			serout C.1,N2400_4,(254,192," ",b9,b10,b11,b12," milliBar  ")
57		goto Cell_7_4
58							'convert to inches Mercury
59	Cell_7_15:  	E = DeltaP * 500 / 339 * 10 /5 + 2805
60				bintoascii E, b8,b9,b10,b11,b12  
61				serout C.1,N2400_4,(254,192," ",b9,b10,".",b11,b12," inch Hg  ")  
62		goto Cell_7_4
63	
64							'if Pressure < 1000, delete the first zero
65	Cell_7_11:
66	
67				if timecount > 30 then  		'arbitrary time units
68					goto Cell_7_17
69				endif
70			bintoascii Pressure,b8,b9,b10,b11,b12
71			serout C.1,N2400_4,(254,128,"   Barometric   ")
72			serout C.1,N2400_4,(254,192,"  ",b10,b11,b12," milliBar  ") 
73		goto Cell_7_4
74							'convert to inches Mercury
75				
76	Cell_7_17:     E = DeltaP * 500 / 339 * 10 /5 + 2805
77				bintoascii E, b8,b9,b10,b11,b12  
78				serout C.1,N2400_4,(254,192," ",b9,b10,".",b11,b12," inch Hg  ") 
79	
80		goto Cell_7_4
81		
82	#no_data    'reduce download time

Solution