Using pigpio, AM2320 sensor works with pigpio, not pigpiod

The Raspberry Pi is a series of credit card-sized single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools and developing countries.

Post Reply
User avatar
/RaspberryPi
Corporate
Posts: 2449
Joined: Wed Jun 05, 2019 1:29 am

Using pigpio, AM2320 sensor works with pigpio, not pigpiod

Post by /RaspberryPi »


I am using an AM2320 i2c temperature sensor with pigpio, first calling

i2cOpen(i2cbus=1, addr=92, flag=0)

Flag is always 0 according to docs.

This works fine in the hardware linked pigpio library and I get valid temperature and humidity, but using pigpiod daemon library I call

i2c_open(handle=0, i2cbus=1, addr=92, flag=0) ;; pipgiod has '_' in names

I get error "PI_BAD_FLAGS (-77): bad i2c/spi/ser open flags" at the first device open. Here, handle is the pigpiod's internal designation of the open socket to the pigpiod server. But flag is always supposed to be zero.

My use of pigpiod seems to be OK because gpio_read(handle=0, PIN) returns an answer without complaining.

Curiously, "i2cdetect 1" doesn't see the AM2320 device at 0x5c=92, returning just a screen of "__" for all addresses. i2c is enabled in the rpi config, of course.

(edit - first clue: running "i2cdetect -y 1" twice on same command line sees the device; it appears to need to wake up. But putting a dummy open / read / 0.01s sleep (ignoring errors) in front of the pigpiod i2c_open() doesn't seem to wake it up as far as pigpiod is concerned. And my code already had a wakeup call that doesn't trigger the -77 error in pigpio).

Any suggestions why this might be happening?



---



edit: looking at the code for i2c_open() at line 976 it seems to me that 'handle' is not an argument (it is called 'pi' in docs) - what daemon connection is being used for the call, then? So docs say 4 args, code says 3.

And i2c_flags is a uint32_t and not an unsigned int as stated in docs. Though on my platform, unsigned int is 32 bits, this is not guaranteed.

Is there a chance pigpiod is buggy for i2c, and it's never been noticed?

edit2: actually, pigpiod_if.c is obsolete and pigpiod_if2.c is the correct version, and pigpiod_if2.c has the 'pi' variable indicating the connection ID. It seems that the 'flag' might be incorrectly sent between the pipgpiod library and the pigpiod daemon. Question re-posted on github.
submitted by /u/jet-monk
[link] [comments]

Source: https://www.reddit.com/r/raspberry_pi/c ... igpio_not/
/RaspberryPi
Post Reply

Return to “Raspberry Pi Forum”