Anyone who knows me, knows that I sometimes bang on about how Galileo is different from other arduino boards due to the fact that it's a full computing system, not a micro-processor hosted board. That give rise to the fact that the GPIO on Galileo is has non-deterministic timing, for reasons that I have covered before, several times.
So, what happens when you need to interface to a device which requires specific timing on the IO? Well, just as you would if you were interfacing that device to a PC or Mac, then you need to use an appropriate interface to make the GPIO interface of the device compatible with one of the many standard interfaces available on Galileo.
In this example, I have interfaced a DHT22 (Also known as AM2303) sensor which requires fixed rate GPIO, to the UART (CMOS Level RS232) of the Galileo.
My interface uses a very cheap PIC12F629 to provide the interface conversion. Here is the schematic :-
You connect +5V and GND to the PWR Header, and the DHT22/AM2303 Sensor to the 4-Pin header.
JP2 provides an RS232 Transmit signal which transmits the data back to the host, and GND along with an AUX signal which is not yet implemented, but you could use is as RS232 RX, or as a trigger or anything else really.
The ICSP header simply allows you to program the PIC with a PicKIT 2/3 or ICD3 programmer.
As you can see, the interface uses just a PIC, some headers and a single 1K resistor. The whole circuit could easily be knocked up on some veroboard, and would cost about $2 in total.
Here is the circuit formed on some breadboard:
(I added an LED and pullup resistor on the TX line, but that is optional).
The source code is attached.
The source is a single file of C code which includes everything you need.
It sets up the hardware, and uses a software UART to transmit the data from the sensor back to the host at 14.4 Kbps. It reads from the sensor about once per second, and you can tweak this in the source, or you could use that AUX input to only read the sensor on receipt of a signal on that pin. The long and short pulses from the sensor are decoded to create the 5 Byte response.
The data sent from the PIC consists of the byte 0xAA, followed by the 5 Bytes from the sensor, followed by a <CR> character. See the DHT22 or AM2303 data sheet for details of the 5 Bytes received from the sensor.
The 0xAA is useful as a SYNC byte and for auto-detecting the baudrate, where possible, since in binary a start bit, the byte 0xAA and a stop bit will form the pattern:
The <CR> character is useful for detecting the end of the input. The output repeats every 1 second.
main.c.zip 1.5 K