I am struggling with I2C and a flow-meter Sensirion SFM3000 connected to a Pi4B.
Using Python command line and pigpio bb_i2c_zip() I can read the correct expected value, but
is it here at all possible to use Xojo with pigpio-GPIO?
I tried i2c_write_device() and i2c_read_device(). Both give errors -82 and -83 respectively.
The write I can do, without errors, using three i2c_write_byte() instead,
but a corresponding i2c_read_byte() seems missing(?)
And the i2c_read_byte_data() needs a register (unknown).
I don’t know how much pigpio-GPIO will take care of start, restart, stop, end and what not.
i2cdetect -y 1 says &h40 as expected.
In this example I try to read the Scale factor from the device with the command &h30DE
The command sequence here for pigpio bb_i2c_zip() is
# address 0x40 4 0x40 # start 2 # write two bytes 7 2 0x30 0xDE # restart 2 # read 2 bytes 6 2 # stop 3 # end 0
cmd = [4, 0x40, 2, 7, 2, 0x30, 0xDE, 2, 6, 2, 3, 0]
So, with Python which gives correct result:
pi@raspberrypi:~ $ sudo pigpiod pi@raspberrypi:~ $ sudo python Python 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pigpio >>> pi=pigpio.pi() >>> SDA=2 >>> SCL=3 >>> baud=50000 >>> pi.bb_i2c_open(SDA, SCL, baud) 0L >>> cmd = [4, 0x40, 2, 7, 2, 0x30, 0xDE, 2, 6, 2, 3, 0] >>> (count, data) = pi.bb_i2c_zip(SDA, cmd) >>> print(count, data) (2L, bytearray(b'\x00\x8c')) >>> pi.bb_i2c_close(SDA) 0L >>> pi@raspberrypi:~ $
x8C = 140 which is the expected Scale factor.
Trying the same in Xojo. Baudrate is set in Pi4B to 50000.
For better readability I removed error checks and property declarations below.
pi = New pigpio Call pi.gpioInitialise() pi.Handle = pi.pigpio_start(nil, nil) bus = 1 FileHandle = pi.i2c_open(bus, &h40, 0) 'Sensirion SFM3000: &h40
Dim returncode As integer dim buf as Ptr dim mb as MemoryBlock mb = NewMemoryBlock(3) returncode=pi.i2c_write_byte(FileHandle,&h40) 'Gives returncode = 0 returncode=pi.i2c_write_byte(FileHandle,&h30) 'Gives returncode = 0 returncode=pi.i2c_write_byte(FileHandle,&hDE) 'Gives returncode = 0 MessageBox "In case a delay is needed" 'Didn't seem to matter. ' buf = mb returncode=pi.i2c_read_device(FileHandle,buf,2) 'Gives returncode = -83 '