Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Nokia 5110 LCD
Page 3 of 4 | |||||
Author | Message | ||||
Justplayin Guru Joined: 31/01/2014 Location: United StatesPosts: 326 |
I think it was that message thread which got me to order the BMP085. --Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!! |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6102 |
This is the BMP085 code I posted a few weeks ago with a function added to get altitude from local pressure and sealevel pressure. ' reading the BMP085 pressure sensor
' TassyJim 06 JAN 2014 'Cls Dim BMPData(2) ' store data from BMP085 dim cal(11) ' calibration data oss = 0 ' over sampling 0 to 3 alt = 240 ' your altitude in metres f$="%6.1f" ' format string BMP085calMEM = &HAA ' start of 11 calibration values BMP085address = &H77 ' BMP085 address BMP085control = &HF4 ' BMP085 control register BMP085temp = &H2E ' BMP085 temperature command BMP085pres = &H34 ' BMP085 pressure command BMP085pres = BMP085pres + oss*&H40 ' adjust command for oversampling BMP085reading = &HF6 ' register for results of reading I2C open 400, 200 ' Enable I2C. use slow speeds for long leads pause 20 mySecs = setMyTime(time$) settick 1002, myTick, 1 'myTick z = Calibrate() ' read the calibration data 'setpin(20,8) 'pin(0)=0 do 'logfile$=mid$(Date$,7,4)+mid$(Date$,4,2)+mid$(Date$,1,2)+". log" t=temperature() 'pin(0)=1 p=pressure(oss) ' pin(0)=0 p0=Psl(p,alt) myHour= int(mySecs/3600) myMin = int((mySecs mod 3600)/60) mySec = mySecs mod 60 myTime$=right$("00"+str$(myHour),2)+":"+right$("00"+str$(myM in),2)+":"+right$("00"+str$(mySec),2) print time$;" ";myTime$;" T:";uFormat$(t,1);" P:";uFormat$(p/100,1);" P(sl):";uFormat$(p0/100,1) print uFormat$(myAlt(p, p0),1) pause (300000) ' delay 5 minutes between readings loop until k$ = "q" or k$ = "Q" 'pin(0)=1 end function Calibrate() ' needs to be called once for each module. ' safest to do it on every program start. local n, calMEM calMEM= BMP085calMEM for n = 1 to 11 I2C write BMP085address, 0, 1, calMEM ' first calibration location pause 1 I2C read BMP085address, 0, 2, BMPData(0) 'print BMPData(1), BMPData(0)*256 + BMPData(1) cal(n) = BMPData(0)*256 + BMPData(1) if n < 4 or n > 6 then ' need to convert some to signed numbers if cal(n) > 32767 then cal(n) = cal(n) - 65536 endif endif 'print n,cal(n) pause 1 calMEM=calMEM+2 ' advance to the next calibration location next n end function function temperature() ' returns the temperature in degrees C to one decimal place local UT, x1, x2, b5 I2C write BMP085address, 0, 2, BMP085control, BMP085temp pause 5 I2C write BMP085address, 0, 1, BMP085reading I2C read BMP085address, 0, 2, BMPData(0) UT = BMPData(0)*256 + BMPData(1) 'calculate true temperature x1= int( (UT-cal(6))*cal(5)/32768) x2=int( cal(10)*2048/(x1+cal(11))) b5=x1+x2 temperature = int((b5+8)/16)/10 end function function pressure(oss) ' returns the pressure in pascals. Divide by 100 for millibars ' recalculates the temperatre. ' time could be saved by reading the temperature once evry 10 minutes ' when taking readings at short intervals local UT, UP, x1, x2, x3, b5, b6, b7, pres, p pres = BMP085pres + oss*&H40 I2C write BMP085address, 0, 2, BMP085control, BMP085temp pause 5 I2C write BMP085address, 0, 1, BMP085reading I2C read BMP085address, 0, 2, BMPData(0) UT = BMPData(0)*256 + BMPData(1) I2C write BMP085address, 0, 2, BMP085control, pres if oss = 0 then ' different oversampling requires different pause 5 ' reading times elseif oss = 1 then pause 8 elseif oss = 2 then pause 14 else pause 26 endif I2C write BMP085address, 0, 1, BMP085reading I2C read BMP085address, 0, 2, BMPData(0) UP = BMPData(0)*256 + BMPData(1) I2C write BMP085address, 0, 1, BMP085reading+2 I2C read BMP085address, 0, 1, BMPData(0) UP=(UP*256+BMPData(0))/2^(8-oss) 'calculate true temperature x1= int( (UT-cal(6))*cal(5)/32768) x2=int( cal(10)*2048/(x1+cal(11))) b5=x1+x2 t=int((b5+8)/16)/10 'print "Temperature: ",t 'calculate true atmospheric pressure b6 = b5 - 4000 x1 = int((cal(8)*(b6*b6/4096))/2048) x2 = int(cal(2)*b6/2048) x3 = x1 + x2 b3 = int(((cal(1)*4+x3)*2^oss +2)/4) x1 = int(cal(3)*b6/8192) x2 = int((cal(7)*(b6*b6/4096))/65536) x3 = int(((x1+x2)+2)/4) b4 = int(cal(4)*x3/32768+cal(4)) b7 = int((UP - b3)*(50000/2^oss)) p = int((b7*2)/b4) x1 = int(int(p/256)*int(p/256)) x1 = int((x1*3038)/65536) x2 = int((-7357*p)/65536) pressure = int(p+(x1 + x2 + 3791)/16) end function function Psl(p, alt) 'given local pressure and altitude, returns pressure at sea level Psl= p/(1-alt/44330)^5.255 end function function uFormat$(x,p) ' given a number (x) and the required number of decimal places (p) ' returns formatted string. Negative and zero p is permitted local x1, f$ f$=str$(cint(x*10^p)) if p>0 then uFormat$=left$(f$,len(f$)-p)+"."+right$(f$,p) elseif p = 0 then uFormat$=f$ else uFormat$=f$+string$(abs(p),"0") endif end function function setMyTime(Nowtime$) local myHour, myMin, mySec myHour = val(left$(NowTime$,2)) myMin = val(mid$(NowTime$,4,2)) mySec = val(mid$(NowTime$,7,2)) setMyTime=myHour*60*60+myMin*60+mySec end function function myAlt(p, p0) ' given local pressure (p) and pressure at sea level (p0) ' returns altitude in metres myAlt = 44330*(1-(p/p0)^0.1903) end function sub myTick mySecs=(mySecs+1)mod 86400 end sub It also has code to adjust the internal clock for better timekeeping and uFormat$()which is a basic format function to print realistic degrees of precision. Using the BMP085 for altitude requires a reliable source of sealevel pressure for your location. I intent to put a BMP085 into the bottom of water tanks to give water level. I have the parts for the water tight container, just short of time to play at the moment. Jim VK7JH MMedit MMBasic Help |
||||
MOBI Guru Joined: 02/12/2012 Location: AustraliaPosts: 819 |
Silicon Chip went down a similar path with a tank level indicator using a pressure sensor and as I recall, had difficulty keeping the water out. I did a prototype using a length of twin flex (sealed on the end) as a capacitor in conjunction with a resistor, comparator and counter. The water altered the dielectric constant and hence the capacitance and (also) hence, the time constant of the RC. It wasn't linear, but it worked with a lookup table to "linearize" the result. That was on a raw PIC. Don't think MMbasic would be fast enough. Anyway, that could be the subject of a different thread. Don't want to hijack. David M. |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Whoaah Jim, I didn't remember that - but maybe I was on holidays in Sydney. Good to see that's already done for me! Greg |
||||
Zonker Guru Joined: 18/08/2012 Location: United StatesPosts: 761 |
I for one would be very interested in getting a good altitude readout based on pressure.. But how accurate would it be... Taking off in an ultra-light, you would need to set the value before you leave the airport, say 400 feet. During the flight, would the readings be within 5 feet..? I would like to create a good airspeed indicator using pressure IC's also.. There are good air pressure sensors using SPI that are from several places... Sensormatic site has several.... Has anyone out there played around with this type of code..? I had tried out a Paralax Quick-Start board that had a pre-configured tropospheric model in table form (no big math) but seemed to work well.. I was hoping to get something like that going on the uMite... It would seem that many of the same calculations are going on in the above code also... (nice).. Not sure how it all works.. But, am very interested.. |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6102 |
A change of one hPa is equivalent to about 10 metres elevation. With the BMP085, relative accuracy +-0.2hPa at constant temperature +-0.5 hPa over 0 to 65 degrees C Noise in readings about 0.05 hPa or 0.4 metres You also need to consider how much the pressure will change while out flying. If the rate of change was enough to be a problem I reckon the wind would be too strong to consider flying anyway! Well worth a test. The sensors are cheap... But I would still have a look out the window as I come into land. For my water level, I should get about 10mm resolution. Once I have a working water proof sensor, I will post photos. Jim VK7JH MMedit MMBasic Help |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Zonk/Jim, I'd looked at the BMP085 accuracy too Jim and it seemed to me good for +/- 1 metre altitude. I'm interested because my brother-in-law has built a two-seater KitFox light plane and I thought I might see how a little box I could build (rather more easily) would compare to his 'proper' instruments! Like all absolute pressure altimeters you definitely have to set your current sea-level atmospheric pressure at take-off. The airspeed indicator issue is something I've had a bit of a look at too; not because of airspeed as such, but using it as an 'angle-of-attack' (i.e. 'stall') meter which he doesn't have - trusting soul! Unfortunately the entry price on this is a bit steep because the only transducer I could find that had enough sensitivity (10" water gauge) costs about US$50 at Digi-Key or $70 over here and you need two of them. Freescale transducer The differential transducer is the one needed and that has to connect to a dedicated wing pitot tube. There's a fair bit of info on the net about 'angle-of-attack' indicators but lots of different opinions too. Greg |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6102 |
I tend to destroy weather instruments on a regular basis (too windy) so I have considered pitot tubes as an option. Jim VK7JH MMedit MMBasic Help |
||||
jman Guru Joined: 12/06/2011 Location: New ZealandPosts: 711 |
Hi Jim I think the copy past god's have had hand in the above (myM in) should be (myMin) Thank you for your code it works spot on Jman |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6102 |
The old "put a space in just for fun" trick. The uFormat() function has a problem with zero. This one should be better: function uFormat$(x,p)
' given a number (x) and the required number of decimal places (p) ' returns formatted string. Negative and zero p is permitted local f$ f$=str$(cint(x*10^p)) if len(f$)<=p then f$=string$(p+1-len(f$), "0")+f$ endif if p>0 then uFormat$=left$(f$,len(f$)-p)+"."+right$(f$,p) elseif p = 0 then uFormat$=f$ else uFormat$=f$+string$(abs(p),"0") endif end function Jim VK7JH MMedit MMBasic Help |
||||
plasma Guru Joined: 08/04/2012 Location: GermanyPosts: 437 |
hmm i need a schemata , pin layout because my lcd looks different |
||||
jman Guru Joined: 12/06/2011 Location: New ZealandPosts: 711 |
Hi My LCD's look like this Connect like this this for 28 Pin uMite LCD uMite 7 SCLK (SPI Clock) Pin 25 6 D/C (data command) Pin 5 5 DN(mosi) SPI Out Pin 3 4 RST (Reset) Pin 4 3 SCE (Chip Select) Pin 2 2 Gnd -ve 1 Vcc +3.3V Regards Jman |
||||
plasma Guru Joined: 08/04/2012 Location: GermanyPosts: 437 |
thx a lot jman , post my result later . thx |
||||
plasma Guru Joined: 08/04/2012 Location: GermanyPosts: 437 |
ive ordered 3 pieces but it looks like 2 are buggy ! booth shows some wandering bytes the last is working finally thanks jman |
||||
Zonker Guru Joined: 18/08/2012 Location: United StatesPosts: 761 |
Hey Jman, Is it possible to get just the display units NOT mounted to a board so that you could design them onto your own..? I haven't spent time looking up some of the newer displays being offered yet... Hummm .. I'll do that... |
||||
jman Guru Joined: 12/06/2011 Location: New ZealandPosts: 711 |
It's real easy to take the LCD off the adapter PCB They use a Elastomeric connector I have taken one apart to change the backlight Led's here is a pic Regards Jman |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Ho John, What are you going to use? I guess it would be pretty easy to glue a bit of light-pipe or diffuser up against the LED's and along the PCB. If that's the idea, where can you get some? Greg |
||||
plasma Guru Joined: 08/04/2012 Location: GermanyPosts: 437 |
not so cheap backlight |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
Finally found time to play with my Nokia screen. It works great but something peculiar happened when I connected the backlight. I was running it from my power supply set to about 8v. As soon as I turn on the backlight the voltmeter on my power supply jumps to about 17v. but the actual input voltage on my protoboard drops to about 5.5v. It still works with the backlight on but why the voltage readings. I tried another power supply and the same thing happens. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
My LCD's arrived a week or so ago - I really MUST play with them, but I have so many other things on my "To-do" pile! Smoke makes things work. When the smoke gets out, it stops! |
||||
Page 3 of 4 |
Print this page |