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.
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
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?
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.
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?
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.