Change default address of I2C sensor

Hello, I want to use BMP280 sensor with cayenne connected to RPI 3. The sensor has default address 0x76. I as read in Cayenne Docs, the supported sensor by the platform - BMP180 has default address 0x77.

Is there anyway to change the discover address of the sensor so I can display the data in dashboard using this sensor?
Any other methods with custom widgets?

Thanks.

You can use the MQTT API. I have an example here that demonstrates using the DHT11/22 sensor. You can use it as a guide and replace the bits that read DHT sensors with your code that reads the BMP. If you need any help let me know.

Thank you very much! I will give it a try first by myself and then I will ask you. Thanks for the fast and reliable response!

@ognqn.chikov,

You can also implement MQTT on the Pi with the Cayenne C libraries, but @adamā€™s solution in Python is a lot less steps.

Let me know if you need a C solution.

Cheers,

Craig

Hello,
So in order to get working the BMP280 Sensor, I have to install its library instead of the library for DHT as in the example? Right?

After that, can you help me with the read command, because in the example the following line is used:

humidity11, temp11 = Adafruit_DHT.read_retry(11, 17) #11 is the sensor type, 17 is the GPIO pin number

but I used to connect BMP280 as shown here: Cayenne Docs

ā€¦so I donā€™t have a number of GPIO pin.

Thanks a lot!

Yes, install this library GitHub - adafruit/Adafruit_Python_BMP: Python library for accessing the BMP series pressure and temperature sensors like the BMP085/BMP180 on a Raspberry Pi or Beaglebone Black. (if you havenā€™t already) and then try the code below (I did not test this- just guessing that it will work). For testing donā€™t use the cron I have in the project just run the file with ā€œpython (filename).pyā€

import paho.mqtt.client as mqtt
import time
import sys
import Adafruit_BMP.BMP085 as BMP085

time.sleep(30) #Sleep to allow wireless to connect before starting MQTT

mqttc = mqtt.Client(client_id="")
mqttc.username_pw_set("username", password="")
mqttc.connect("mqtt.mydevices.com", port=1883, keepalive=60)

sensor = BMP085.BMP085()

topic_temp = "v1/username/things/clientid/data/1"
topic_pressure = "v1/username/things/clientid/data/2"
topic_altitude = "v1/username/things/clientid/data/3"
topic_sealevel_pressure = "v1/username/things/clientid/data/4"

while True:
    try:
        temp = sensor.read_temperature()
        pressure = sensor.read_pressure()
        altitude = sensor.read_altitude()
        sealevel_pressure = sensor.read_sealevel_pressure()
        
        mqttc.publish(topic_temp, payload=temp, retain=True)
        mqttc.publish(topic_pressure, payload=pressure, retain=True)
        mqttc.publish(topic_altitude, payload=altitude, retain=True)
        mqttc.publish(topic_sealevel_pressure, payload=sealevel_pressure, retain=True)
		
        time.sleep(5)
    except (EOFError, SystemExit, KeyboardInterrupt):
        mqttc.disconnect()
        sys.exit()
1 Like

Thank you very much for the whole code!!!

I will test it and return an answer!

I appreciate it.
Thank you!

For testing you can also take out that ā€œtime.sleep(30) #Sleep to allow wireless to connect before starting MQTTā€ line so you donā€™t have to wait 30 seconds every time you run the script. Thatā€™s only in there because I had problems with the script running before there was a connection available on boot.

Okey,
Later when I go back from work, I will make tests.

Thank you!

Hello,
I use to try your code and when I try to run it with python ā€œfilenameā€, it gives me the following error:

Traceback (most recent call last):
  File "bmp280.py", line 12, in <module>
    sensor = BMP085.BMP085()
  File "build/bdist.linux-armv7l/egg/Adafruit_BMP/BMP085.py", line 69, in __init__
  File "build/bdist.linux-armv7l/egg/Adafruit_BMP/BMP085.py", line 72, in _load_calibration
  File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 200, in readS16BE
  File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 177, in readS16
  File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 164, in readU16
  File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py", line 173, in read_word_data
IOError: [Errno 5] Input/output error

On my dashboard, a device with name 737f appeared. It is with empty dashboard. When I try to add widget, it asks for an address which I donā€™t know.

Can you help me a little bit more please?
Thanks.

Hmm I think I have one of these sensors but finding it will be the problem. Iā€™ll try to test it tonight if I can find it. Until then maybe someone that has one accessible can try? As far as the dashboard your widgets will show up automatically when the script successfully runs.

@ognqn.chikov,

Have you tried it with:

sudo python "filename"

Sometimes there are permission issues accessing I/O.

Cheers,

Craig

Yes, of course. I read already about the GPIO permissions.

I suddenly burn the sensor, so I am waiting for the new one to come.

@ognqn.chikov,

ā™« Suddenly, the wheels are in motionā€¦ ā™«

Sorryā€¦ moment of silence for the dead.

crickets

:wink: