IR-controlled A/C (7/many) - Modulating
To summarize a bit, I’m down to the point where I’m going to use the
pigpio library to drive the GPIO directly
instead of using lirc
.
Talking to libgpio
I continued being stubborn and wanting to do things in Go. The library is written in C, has python bindings, but nothing for Go, and I was also too lazy to do a CGo binding (it’s totally doable and not that hard, but it’s long).
Conveniently enough there is also a daemon called pigpiod
with a network
interface. All I need to do is dial localhost
! And so off we go. I pretty much
reimplemented the daikin-pi project in order to recreate the full fame, except
that instead of writing out a file, I would connect to the pigpiod
socket, and
send the command.
Here’s the example of the first part of the frame.
As we’ll see, in order to talk to pigpiod
there was a little bit of learning
and a little bit of frustration.
Learning
From the documentation it’s not always
super clear what to send. For example, to start a new wave, the C function is
gpioWaveAddNew
(documentation) and you
need to find in the list of codes that
it is command WVNEW
ie 53.
Once that was clear, sending commands was easy
Frustration
At the pigpio dameon
There were a few shortcomings in the documentation.
The first one was around then endianness of the uint32
fields, or even how to
properly send a structure through a TCP connection. I assumed just put one
uint32
after another, that was right.
I had assumed bigendian, and that was wrong (I modified the snippet above after I figured that out)
At myself
So after a bit of work, I think I have it. I look at piscope and the timings are right. Hurray!.
And so I point the LED at the A/C unit and ….. nada. Over and over and over.
At that point, I was ready to give it up. Until my brother sent me a link to this video (in French Québécois), where the creator explains a specific IR protocol … and highlights something obvious that I should totally have remembered: the signal has to be modulated !!!
What even more frustraing is that zooming in on the piscope window, I had seen it!
I just had totally forgotten 😡😡😡
At PWM
PWM should have been a way to modulate. I just could never figure it out. I don’t remember fully what I tried, but it didn’t work.
At this point, I had done everything very manually, I might as well “modulate” manually! Instead of sending X ms of “high” signal, I would just “cut” it, ie. alternate high an low state.
Here’s how it works. Some functions to get from bytes to the “high” and “low” state durations.
And how to modulate it. pulseTimeMicro
is initialized based on a 38kHz
frequency. And you need to divide by 2 because I need 2 states per cycle.
At the dameon again
Turns out there’s a maximum command length you can send over the socket! It might be documented somewhere, but I didn’t find it.
Luckily there’s a command called WVAG
which corresponds to
gpioWaveAddGeneric,
and by trying values, I found that the maximum message size seemed to be aroudn
65000 bytes, I’m ready to bet it’s actually around 65535…
At that point, I had probably gone as far as I would ever be ready to go.