Connected Bar30 by a USB to the Raspberry Pi4 - Code

Hi

I am using a Raspberry Pi 4 and Using the Bar30 and connected them by using a FT200XD USB to I2C. I am not connecting the Bar30 to the pins in the Raspberry Pi4 because i am using a Sense HAT, but I am connected it by a USB to the Raspberry Pi4. so the code in the website or in the BlueRobotics MS5837 Python Library:

import ms5837
import time

sensor = ms5837.MS5837_30BA() # Default I2C bus is 1 (Raspberry Pi 3)

# We must initialize the sensor before reading it
if not sensor.init():
        print "Sensor could not be initialized"
        exit(1)

# Print readings
while True:
        if sensor.read():
                print("P: %0.1f mbar  %0.3f psi\tT: %0.2f C  %0.2f F") % (
                sensor.pressure(), # Default is mbar (no arguments)
                sensor.pressure(ms5837.UNITS_psi), # Request psi
                sensor.temperature(), # Default is degrees C (no arguments)
                sensor.temperature(ms5837.UNITS_Farenheit)) # Request Farenheit
        else:
                print "Sensor read failed!"
                exit(1)

only works if the Bar30 was connecting to the pins in the Raspberry Pi4. So what is the code if i was connecting the Bar30 to the Raspberry Pi4 by USB.

Thank you

Hi,

Check which I²C bus you want to use, and call the barometer constructor with the correct bus,
E.g:

  • i2c-1: ms5837.MS5837_30BA() or ms5837.MS5837_30BA(bus=1), 1 is default
  • i2c-2: ms5837.MS5837_30BA(bus=2)
  • i2c-3: ms5837.MS5837_30BA(bus=3)

and etc.

Hi

So my setup as seen in the image.

connecting the pressure sensor to the raspberry pi directly using a USB not by pins.

Thank you

Hi,

Sorry if I was not clear in my answer, but your usb device will appears as /dev/i2c-{number}, and this number will be the bus used for the library.

Hi
Thank you for the respond
I tried /dev/i2c-{number} but nothing is shown but when I use
ls /dev|grep usb
Is shows
ttyUSB0
As it seas it as a usb
So it shows as serial

What to do or how can I write the code?

Thank you

Hi

Thank you for the respond

I have tried /dev/i2c-{number} but nothing is shown
But when I tried
ls /dev|grep USB
It shows
ttyUSB0
And as serial
What code should I use in this case so I can get the pressure and depth?

Thank you

Hi,

When I said /dev/i2c-{number}, a mean by {number} as a real number, such as my previous example:

So you’ll see a /dev/i2c-1, /dev/i2c-2, /dev/i2c-3 and etc.

Hi

I am still having issues

What do you recommend to fix this issue?

Thank you

Hi

I am still having issues
<image3.jpeg>

<image1.jpeg>

What do you recommend to fix this issue?

Thank you

From what I can see in your pictures, it appears that your I2C to USB adapter creates a serial port for the I2C sensor, I would recommend to follow the documentation of your USB adapter and modify the library to work with the serial port.

Hi

I have tried to use this code but it is not working, could you help me with the code, i need to get the pressure and the depth using the bar 30 with the serial and I have attached the usb documentation. i have tried a number of codes but nothing seems to work.
could you help me with the code?

thank you

USBI2C1915292.pdf (482 KB)

Hi,

As I said, you’ll need to follow your adapter documentation to see how to communicate with the serial-I²C adapter. Serial has a different communication concept compared to I²C, so you’ll need to implement a middleware layer to make it work.