BMP183 SPI and a Raspberry Pi

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
pghpete
 
Posts: 9
Joined: Thu Jul 03, 2014 11:49 am

BMP183 SPI and a Raspberry Pi

Post by pghpete »

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

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: BMP183 SPI and a Raspberry Pi

Post by Franklin97355 »

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.

User avatar
pghpete
 
Posts: 9
Joined: Thu Jul 03, 2014 11:49 am

Re: BMP183 SPI and a Raspberry Pi

Post by pghpete »

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.

User avatar
pghpete
 
Posts: 9
Joined: Thu Jul 03, 2014 11:49 am

Re: BMP183 SPI and a Raspberry Pi

Post by pghpete »

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.

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: BMP183 SPI and a Raspberry Pi

Post by Franklin97355 »

I'm not having much luck either. You may end up porting the code for the Arduino to the pi.

User avatar
pghpete
 
Posts: 9
Joined: Thu Jul 03, 2014 11:49 am

Re: BMP183 SPI and a Raspberry Pi

Post by pghpete »

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.

User avatar
przemo
 
Posts: 43
Joined: Tue Jul 22, 2014 4:28 pm

Re: BMP183 SPI and a Raspberry Pi

Post by przemo »

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):

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.

User avatar
pghpete
 
Posts: 9
Joined: Thu Jul 03, 2014 11:49 am

Re: BMP183 SPI and a Raspberry Pi

Post by pghpete »

Fantastic! Thank you for this information... I will try this weekend and report back. :-)

User avatar
przemo
 
Posts: 43
Joined: Tue Jul 22, 2014 4:28 pm

Re: BMP183 SPI and a Raspberry Pi

Post by przemo »

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.

User avatar
przemo
 
Posts: 43
Joined: Tue Jul 22, 2014 4:28 pm

Re: BMP183 SPI and a Raspberry Pi

Post by przemo »

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

User avatar
draugrim
 
Posts: 1
Joined: Sat Nov 22, 2014 3:30 am

Re: BMP183 SPI and a Raspberry Pi

Post by draugrim »

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

Code: Select all

sudo nano /etc/modprobe.d/raspi-blacklist.conf
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:

Code: Select all

ls /dev/spidev*
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.

User avatar
thorn79
 
Posts: 20
Joined: Tue Mar 10, 2015 1:28 pm

Re: BMP183 SPI and a Raspberry Pi

Post by thorn79 »

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

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: BMP183 SPI and a Raspberry Pi

Post by Franklin97355 »

If you could post pictures and wiring diagram it would help.

User avatar
thorn79
 
Posts: 20
Joined: Tue Mar 10, 2015 1:28 pm

Re: BMP183 SPI and a Raspberry Pi

Post by thorn79 »

franklin97355 wrote:If you could post pictures and wiring diagram it would help.
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/1105

I'll take a photo and post it in a little bit.

Thanks, Greg

User avatar
thorn79
 
Posts: 20
Joined: Tue Mar 10, 2015 1:28 pm

Re: BMP183 SPI and a Raspberry Pi

Post by thorn79 »

Here's the setup.
BMP183 Sensor
BMP183 Sensor
20150311-GT2_2456.jpg (587.82 KiB) Viewed 1383 times


I also have the UV sensor that's on the I2C and works fine.

Thanks, Greg

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”