BME280 SPI interface to Raspberry pi 2

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
User avatar
Owl2623
 
Posts: 7
Joined: Wed Aug 10, 2016 2:55 pm

BME280 SPI interface to Raspberry pi 2

Post by Owl2623 »

I'm having a problem trying to get the SPI bus to work with a BME280 module. The Raspberry pi 2 is connected to a 40 pin
breakout adapter to solder less breadboard.
BME280 SCK-> SCLK Raspberry pi
BME280 SDO -> MISO
BME280 SDI -> MOSI
BME280 CD -> GPIO 8 (CE0)

I'm using Python. I have activated the Raspberry pi 2 SPI using the raspi-config setup menu.
I run Adafruit_BME280_Example.py and get the following errors. Any idea what my problem is?

The BME280 works when connected to the I2C bus.

Traceback (most recent call last):
File "/home/pi/Downloads/Adafruit_Python_BME280_master/Adafruit_BME280_Example.py", line 3, in <module>
sensor = BME280(mode=BME280_OSAMPLE_8)
File "/home/pi/Downloads/Adafruit_Python_BME280_master/Adafruit_BME280.py", line 90, in __init__
self._load_calibration()
File "/home/pi/Downloads/Adafruit_Python_BME280_master/Adafruit_BME280.py", line 96, in _load_calibration
self.dig_T1 = self._device.readU16LE(BME280_REGISTER_DIG_T1)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-1.0.1-py2.7.egg/Adafruit_GPIO/I2C.py", line 185, in readU16LE
return self.readU16(register, little_endian=True)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-1.0.1-py2.7.egg/Adafruit_GPIO/I2C.py", line 164, in readU16
result = self._bus.read_word_data(self._address,register) & 0xFFFF
File "/usr/local/lib/python2.7/dist-packages/Adafruit_PureIO-0.2.1-py2.7.egg/Adafruit_PureIO/smbus.py", line 173, in read_word_data
ioctl(self._device.fileno(), I2C_RDWR, request)
IOError: [Errno 5] Input/output error

Thanks,
Owl2623

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: BME280 SPI interface to Raspberry pi 2

Post by adafruit_support_mike »

The errors say the code is still trying to find the BME280 on the I2C bus.

I'm afraid the Adafruit_Python_BME280 module is only written for I2C.

User avatar
Owl2623
 
Posts: 7
Joined: Wed Aug 10, 2016 2:55 pm

Re: BME280 SPI interface to Raspberry pi 2

Post by Owl2623 »

Mike,

I was hoping to use the I2C bus for a Adafruit HMC5883 module which only has I2C interface and the BME280 on the SPI bus not knowing how to address each module separately on a I2C bus.

Can you advise on how to structure the code to address the individual modules? Samples would be appreciated.

I'm open to any other suggestion you can offer.

Thanks,
Alan

PS. I did some more searching and I believe that I have found code implementing SPI communication for the BME280.

https://github.com/spooky360/BME280_Pyt ... /BME280.py

Comments?

Alan

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: BME280 SPI interface to Raspberry pi 2

Post by adafruit_support_mike »

All I2C devices have built-in addresses, usually built right into the chip circuit. Some have pins that let you change the address so you can use more than one of the chip on the same I2C bus, but some only give you one choice.

The HMC5883's address is 0x17, and the BME280 uses address 0x77. The code libraries already have those values written in, and the two devices can share the same I2C bus. All you have to do is connect the SDA and SCL lines.

User avatar
Owl2623
 
Posts: 7
Joined: Wed Aug 10, 2016 2:55 pm

Re: BME280 SPI interface to Raspberry pi 2

Post by Owl2623 »

That was simpler than expected. I will give it a try.

Thanks

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”