Timing issues, imp.sleep() time

Hello there,

I have been using the imp for a project of mine in the pasts months and, so far, it has been a great device. Thanks guys! I have been struggling to implement the communication protocol of RHT03 . I can’t seem to get the synchronization correctly. I used the newly implemented hardware.micros() in a few experiments in order to see how it behaved.

`function test() {
local t0,t1,a;

        t0 = hardware.micros();
        t1 = hardware.micros();
        t0 = hardware.micros();
        t1 = hardware.micros() ;
        t0 = hardware.micros();
        a = hardware.pin1.read();
        t1 = hardware.micros() ;

I am getting the following responses:

Wednesday, January 09, 2013 11:26:29: show: 129
Wednesday, January 09, 2013 11:26:29: show: 268
Wednesday, January 09, 2013 11:26:29: show: 329

Is that correct/expected? How can I give instructions so that the imp will wait precisely 40us ?

Thanks a lot!



Squirrel doesn’t run fast enough (yet, at least) to do bitbanged IO, this has been discussed in other threads related to various 1-wire protocols.

We have an API in development that would allow you to hand off a precisely-timed I/O list and have the imp OS execute it, but it’s not available yet - sorry. I have an RHT03 I’d like to have working too!

Until then the alternative is to use an HIH6130 or SHT21 temp/humidity sensor. More expensive but higher accuracy… and I2C interface.

thanks for the reply, Hugo. Well, i guess I’ll try to work with one of the other sensors for now.

By, the way, do you think that it would be possible to implement a IR decoder/emitter with the imp? My idea was to try to implement a “universal” IR module, that could accept IR input from a range of frequencies and also output it in several (not being limited by the 38khz that the demodulator component has). Would the PWM and the pulse counter be appropriate for that? If so, what is the voltage threshold (the IR receiver is diode) of the pulse counter?

Thanks a lot!


Universal emitter, when we have the SPI running gapless, is just an AND gate. Set modulation frequency with a PLL on on pin and send the waveform with SPI on another, then AND together to get the modulated waveform.

For RX you really need to do the demod in hardware…