Just been playing with the pigpio module as wiringpi is no longer flavour of the month…
I have followed the code examples from Eugene’s book on setting up I2C.
Using the following code snippet:
pi = New pigpio
Call pi.gpioInitialise()
pi.Handle = pi.pigpio_start(nil, nil)
bus = 1
//init ADC1
ADCHandle = pi.i2c_open(bus, ADC1Address)
Listbox1.AddRow "MyHandle = " + ADCHandle.ToText
If ADCHandle < 0 then
Listbox1.AddRow "Error with address - use i2cdetect -y 1 to find it. Error: " + ADCHandle.ToString
End If
System.DebugLog "pi.handle: " + pi.Handle.ToString
System.DebugLog "ADChandle: " + ADCHandle.ToString
I always get 0 for pi.handle and ADCHandle, even if the ADC chip is not on the I2C bus.
I would assume that if the ADC chip is not on the bus, then when “ADCHandle = pi.i2c_open(bus, ADC1Address)” is run I should get an error, but the code carries on happily and reports 0.
Also having a bit of fun with i2c_write_device:
Data = pi.i2c_write_device(ADCHandle,buf, 3)
buf points to a memory block where I have 3 bytes to send. The count variable - should it be 2 (as in 0 to 2, that is 3 bytes), or 3 (as in 1 to 3)? Assuming the former - same as an array.
I had all of this working fine with the old wiringpi and GPIO module. I am trying to talk to an ADS1115 ADC.
I’m using a Pi Compute Module 4, latest OS.
All I2C devices are IDed when using suso i2cdetect -y 1