The DHT11 is a temperature and humidity sensor with a maximum frequency of 0.5Hz (one read per 2 seconds). So speed is not the issue here!

Yes, data can be read only once every two seconds, but that's not the timing one needs to be concerned with. The real timing issue is in issuing digital signals to the device to inform it that we're about to read data from it. This is measured in microseconds. Perl, at best can reliably deal in milliseconds.

You can extract two formats of data from this device. First, you have to hold the signal pin LOW for 18us (microseconds) to tell it you want to read data, then set it back HIGH. For the first format that is returned, the device sets the data pin low for exactly 50us (microseconds), then immediately hold it high for 26-28us. For format two, holds low for 50us, then high for 70us. If you're off even marginally sending or receiving these signals, you'll possibly get the incorrect format, corrupt or no data at all.

So on a Raspberry Pi, even while using C, you can still get mis-timed events because of possible contention of the CPU. This is why microcontrollers are so much better for this. They operate instructions in a linear fashion and never have the overhead of other processes competing for CPU cycles.

Also, Perl can't manipulate hardware registers like this directly. Even if it could, the timing would be too unreliable to be effective.


In reply to Re: XS Modules - why and when? by stevieb
in thread XS Modules - why and when? by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.