Happy 4th of July to all Americans. Good day to everyone else.
I purchased a bmp183 to use with a rasberry pi weather station I am in the process of building. I am very new to SPI and while I _think_ i understand how this baremetric sensor will be wired to the raspberry pi, I am lost as to how to interface with it. I know I would like to either 1) pull any values directly from the device if possible, or 2) use a python script and an appropriate library/module to utilize the SPI interace and pull the relavant values from the device.
I have been trying to read up on SPI and what python libraries/modules I would need to use but I am still fairly lost and not much close to getting it to function as I was a few days ago. Does anyone here have any pointers or can point me to where I might be able to learn more in regards to the bmp183 spi and the raspberry pi? Any information would be greatly appreciated.
For those interested in seeing what my little "remote station" is already recording, you can see my dashboard here https://grovestreams.com/observationStu ... guest=true
[Remote Station: Rev 2 Rasberry Pi, Overdrive Pro 3g/4g hotspot, HTU21D-F temp/humidity sensor, etc with plans for Wind Speed & Direction, rain & snow guages, and will be entirely solar powered by the winter as it is on an island which is uninhabited during the winter months]
Regards! Pete
BMP183 SPI and a Raspberry Pi
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Franklin97355
- Posts: 23912
- Joined: Mon Apr 21, 2008 2:33 pm
Re: BMP183 SPI and a Raspberry Pi
I don't see any info in the learn section but here is the datasheet that might help. Google bmp183 raspberrypi and see what you find, that's what I'm going to do.
- pghpete
- Posts: 9
- Joined: Thu Jul 03, 2014 11:49 am
Re: BMP183 SPI and a Raspberry Pi
Thank you very much. I was coming up a bit dry with my Google searches besides the data sheet. I think it may be because the bmp183 spi package is newer. (At least the breakout board is) if I find anything I will post it here.
- pghpete
- Posts: 9
- Joined: Thu Jul 03, 2014 11:49 am
Re: BMP183 SPI and a Raspberry Pi
I haven't progressed much with the BMP183 sensor but I now also have the real time data being written to a Google Spreadsheet using the gspread python script/api. I plan to write up a howto once I have this project completed for those who may be interested.
- Franklin97355
- Posts: 23912
- Joined: Mon Apr 21, 2008 2:33 pm
Re: BMP183 SPI and a Raspberry Pi
I'm not having much luck either. You may end up porting the code for the Arduino to the pi.
- pghpete
- Posts: 9
- Joined: Thu Jul 03, 2014 11:49 am
Re: BMP183 SPI and a Raspberry Pi
I have found this http://hertaville.com/2013/07/24/interf ... i-using-c/ which, in conjunction with the bmp183's data sheet, is getting me closer. I wish I knew more about the SPI interface to be able to write the necessary python code.
- przemo
- Posts: 43
- Joined: Tue Jul 22, 2014 4:28 pm
Re: BMP183 SPI and a Raspberry Pi
That should answer most questions about BMP183 and raspberry pi: https://github.com/PrzemoF/bmp183
Its a python module for BMP183. Example usage (measure.py file):
It's a low performance solution and I'm sure it could be improved.
If you need any clarification or see bugs please let me know.
P.S. Currently my raspberr pi + bmp183 shows
Temperature: 20.1 deg C
Pressure: 1013.9 hPa
;-)
Its a python module for BMP183. Example usage (measure.py file):
Code: Select all
from bmp183 import bmp183
bmp = bmp183()
bmp.measure_pressure()
print "Temperature: ", bmp.temperature, "deg C"
print "Pressure: ", bmp.pressure/100.0, " hPa"
quit()
It's a low performance solution and I'm sure it could be improved.
If you need any clarification or see bugs please let me know.
P.S. Currently my raspberr pi + bmp183 shows
Temperature: 20.1 deg C
Pressure: 1013.9 hPa
;-)
Last edited by przemo on Fri Aug 22, 2014 4:32 pm, edited 1 time in total.
- pghpete
- Posts: 9
- Joined: Thu Jul 03, 2014 11:49 am
Re: BMP183 SPI and a Raspberry Pi
Fantastic! Thank you for this information... I will try this weekend and report back. :-)
- przemo
- Posts: 43
- Joined: Tue Jul 22, 2014 4:28 pm
Re: BMP183 SPI and a Raspberry Pi
Some more info: that module by default uses maximum oversampling + software averaging (3 samples) for maximum accurancy. It's slow, but that's what I need.
It should be easy to switch to less accurete measurement as I tried to implement all measurement modes, so it's just a matter of switching to another mode and trimming software averaging.
It should be easy to switch to less accurete measurement as I tried to implement all measurement modes, so it's just a matter of switching to another mode and trimming software averaging.
- przemo
- Posts: 43
- Joined: Tue Jul 22, 2014 4:28 pm
Re: BMP183 SPI and a Raspberry Pi
I just added a threaded version at [1]. It's a more elegant solution for the real life scenarios. Example usage here [2]
It takes about 4% of RPI CPU with 1s measurements.
[1] https://github.com/PrzemoF/bmp183/tree/threaded
[2] https://github.com/PrzemoF/bmp183/blob/ ... measure.py
It takes about 4% of RPI CPU with 1s measurements.
[1] https://github.com/PrzemoF/bmp183/tree/threaded
[2] https://github.com/PrzemoF/bmp183/blob/ ... measure.py
- draugrim
- Posts: 1
- Joined: Sat Nov 22, 2014 3:30 am
Re: BMP183 SPI and a Raspberry Pi
Hi there,
I adapted the Adafruit's library for the BMP183 for Arduino so that it can be used also on the Raspberry Pi using C/C++. I submitted the library to https://github.com/draugrim/BMP183_RaspberryPi_C_Cpp
I also included an example of use written in Qt, which is nothing more than the Arduino example with some minor modifications
For using the library you simply have to make sure that spidev is commented out on the Pi's black list. In other words, type
and check if there is a '#' before "blacklist spi-bcm2708". If not comment it and reboot.
After that you should see /dev/spidev0.0 or /dev/spidev0.1 when typing in the command:
Wire the BMP183 to your Pi like shown here: http://www.lediouris.net/RaspberryPI/BMP183/readme.html
BMP183 Raspberry PI
Vin # 2. 5.0 VDC Power
GND # 6. 0V (Ground)
SCK #23. SCLK
SDO #21. MISO
SDI #19. MOSI
CS #24. CE0
By doing so, the BMP183 will be the /dev/spidev0.0 device, which you can address in your code, when using the library.
This library can also be adapted to other SPI sensors. I made it to be able to use the great amount of C/C++ libraries available for Arduino also on the Pi.
I give all credits to Adafruit's original library for the BMP183 and also to Hussam Al-Hertani (https://github.com/halherta/RaspberryPi-mcp3008Spi), from whom I borrowed the code to interface with spidev on the Pi.
I hope it might be of help to someone. And please, if you adapt some other library take a bit of time to share it.
I adapted the Adafruit's library for the BMP183 for Arduino so that it can be used also on the Raspberry Pi using C/C++. I submitted the library to https://github.com/draugrim/BMP183_RaspberryPi_C_Cpp
I also included an example of use written in Qt, which is nothing more than the Arduino example with some minor modifications
For using the library you simply have to make sure that spidev is commented out on the Pi's black list. In other words, type
Code: Select all
sudo nano /etc/modprobe.d/raspi-blacklist.conf
After that you should see /dev/spidev0.0 or /dev/spidev0.1 when typing in the command:
Code: Select all
ls /dev/spidev*
BMP183 Raspberry PI
Vin # 2. 5.0 VDC Power
GND # 6. 0V (Ground)
SCK #23. SCLK
SDO #21. MISO
SDI #19. MOSI
CS #24. CE0
By doing so, the BMP183 will be the /dev/spidev0.0 device, which you can address in your code, when using the library.
This library can also be adapted to other SPI sensors. I made it to be able to use the great amount of C/C++ libraries available for Arduino also on the Pi.
I give all credits to Adafruit's original library for the BMP183 and also to Hussam Al-Hertani (https://github.com/halherta/RaspberryPi-mcp3008Spi), from whom I borrowed the code to interface with spidev on the Pi.
I hope it might be of help to someone. And please, if you adapt some other library take a bit of time to share it.
- thorn79
- Posts: 20
- Joined: Tue Mar 10, 2015 1:28 pm
Re: BMP183 SPI and a Raspberry Pi
I have been trying to get the BMP183 to work using the python code. . I double checked the wiring but I get an error:
$ sudo python ./measure.py
('BMP183 returned ', 0, ' instead of 0x55. Communication failed, expect problems.')
/home/pi/scripts/bmp183/bmp183.py:224: RuntimeWarning: divide by zero encountered in int_scalars
X2 = self.MC * 2**11 / (X1 + self.MD)
/home/pi/scripts/bmp183/bmp183.py:215: RuntimeWarning: divide by zero encountered in longlong_scalars
p = numpy.uint32 ((self.B7 * 2) / self.B4)
Temperature: 0.0 deg C
Pressure: 2.36 hPa
I guess it's not talking to the board. Any ideas?
Thanks
$ sudo python ./measure.py
('BMP183 returned ', 0, ' instead of 0x55. Communication failed, expect problems.')
/home/pi/scripts/bmp183/bmp183.py:224: RuntimeWarning: divide by zero encountered in int_scalars
X2 = self.MC * 2**11 / (X1 + self.MD)
/home/pi/scripts/bmp183/bmp183.py:215: RuntimeWarning: divide by zero encountered in longlong_scalars
p = numpy.uint32 ((self.B7 * 2) / self.B4)
Temperature: 0.0 deg C
Pressure: 2.36 hPa
I guess it's not talking to the board. Any ideas?
Thanks
- Franklin97355
- Posts: 23912
- Joined: Mon Apr 21, 2008 2:33 pm
Re: BMP183 SPI and a Raspberry Pi
If you could post pictures and wiring diagram it would help.
- thorn79
- Posts: 20
- Joined: Tue Mar 10, 2015 1:28 pm
Re: BMP183 SPI and a Raspberry Pi
I wired it like this example (http://www.lediouris.net/RaspberryPI/BMP183/readme.html) except mine is a Pi2 and I used the Adafruit Cobbler board : https://www.adafruit.com/products/1105franklin97355 wrote:If you could post pictures and wiring diagram it would help.
I'll take a photo and post it in a little bit.
Thanks, Greg
- thorn79
- Posts: 20
- Joined: Tue Mar 10, 2015 1:28 pm
Re: BMP183 SPI and a Raspberry Pi
Here's the setup.
I also have the UV sensor that's on the I2C and works fine.
Thanks, Greg
I also have the UV sensor that's on the I2C and works fine.
Thanks, Greg
Please be positive and constructive with your questions and comments.