I have developed a library for reading remote wireless temperature sensors. Reading data from these sensors requires accurately measuring the time between up/down transitions on the data line (typically connected to GPIO 27).
These are the timings, in microseconds, that I need to test against:
The way the code works with pigpio, I use a the function gpioSetAlertFunc to register for callbacks when the data line changes value. The code has been working great this way, but, of course, won't work on the Raspberry 5 which is incompatible with pigpio.
The closest equivalent to gpioSetAlertFunc that I see in libgpiod is gpiod_ctxless_event_monitor, which I'm using like this:
Where dataPin typically has the value 27, and TIME_OUT is one hour.
I'm definitely getting lots of callbacks to signalHasChanged, at a rapid pace that I sincerely doubt I'd get if I were reading the wrong pin. But none of the signal I get back is ever good enough to parse as a distinct message from one of the remote thermometers.
This makes me wonder if libgpiod is up to the task I'm asking of it. There's very little I can find googling about for info on this topic -- not much chatter about using libgpiod, and nothing about needing precise timing from it.
These are the timings, in microseconds, that I need to test against:
Code:
// Signal timings in microseconds// 0 bit is short high followed by long low, 1 bit is long high, short low.static const int SHORT_PULSE = 210;static const int LONG_PULSE = 401;static const int BIT_LENGTH = SHORT_PULSE + LONG_PULSE;static const int THIRD_OF_A_BIT = BIT_LENGTH / 3;static const int PRE_LONG_SYNC = 207;static const int LONG_SYNC_PULSE = 2205;static const int SHORT_SYNC_PULSE = 606;static const int TOLERANCE = 100;static const int LONG_SYNC_TOL = 450;
The closest equivalent to gpioSetAlertFunc that I see in libgpiod is gpiod_ctxless_event_monitor, which I'm using like this:
Code:
gpiod_ctxless_event_monitor("gpiochip0", GPIOD_CTXLESS_EVENT_BOTH_EDGES, dataPin, false, "", &TIME_OUT, nullptr, signalHasChanged, this);
I'm definitely getting lots of callbacks to signalHasChanged, at a rapid pace that I sincerely doubt I'd get if I were reading the wrong pin. But none of the signal I get back is ever good enough to parse as a distinct message from one of the remote thermometers.
This makes me wonder if libgpiod is up to the task I'm asking of it. There's very little I can find googling about for info on this topic -- not much chatter about using libgpiod, and nothing about needing precise timing from it.
Statistics: Posted by kshetline — Sun Feb 09, 2025 1:03 am — Replies 0 — Views 23