Use library MS5837 - Bar30 Sensor

Good evening everyone.

I’m a newbie here.

And I have a question. If you can help thank you.

I’m trying to use the B30 M5837 pressure sensor library on the raspberry pi.

Some difficulties I would like to understand.

Why is it giving this syntax error considering that at some point I managed to make it work?

admin@raspberrypi:~/ms5837-python $
admin@raspberrypi:~/ms5837-python $ python example.py
Pressure: %.2f atm  %.2f Torr  %.2f psi
Traceback (most recent call last):
  File "/home/admin/ms5837-python/example.py", line 20, in <module>
    print("Pressure: %.2f atm  %.2f Torr  %.2f psi") % (
TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'
admin@raspberrypi:~/ms5837-python $
admin@raspberrypi:~/ms5837-python $

Hi @allacmc, welcome to the forum :slight_smile:

It seems that our current example.py file was written for Python 2, and has not yet been updated to support Python 3. I’ve submitted a pull request to fix that here.

Until that gets merged you can refer to the updated example here.

Note that for new programs that don’t require backwards compatibility with old Python versions, it’s generally better to use f-strings or the .format method instead of modulo-formatting. That could look something like this instead:

print("Pressure: {:.2f} atm  {:.2f} Torr  {:.2f} psi".format(
      sensor.pressure(ms5837.UNITS_atm),
      sensor.pressure(ms5837.UNITS_Torr),
      sensor.pressure(ms5837.UNITS_psi)
     ))
1 Like

thanks