Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The large code block is the code for the measure() function. Notice that it returns 0 at one point without performing a connReset(). This should be a way to detect a valid device such as ... </p> <pre><code>bool hasHUMI; if (hsensor2.measure(SHT21::HUMI)) { hasHUMI=true; } </code></pre> <p>or</p> <pre><code>if (hsensor2.measure(SHT21::HUMI) &amp;&amp; hsensor2.measure(SHT21::TEMP)) { hsensor2.calculate(h, t); float hum2 = (h); float temp2 = (t); } </code></pre> <p>or</p> <p>Your code should be clearing h and t to 0 before making the read so that you can test for valid values. Like this...</p> <pre><code>void loop() { h=0.00f; t=0.00f; // Get data from sensor soft I²C hsensor2.measure(SHT21::HUMI); hsensor2.measure(SHT21::TEMP); hsensor2.calculate(h, t); float hum2 = (h); float temp2 = (t); if (h&gt;0) { } if (t&gt;0) { } } </code></pre> <p>If not then you could make (copy) your own version of the <code>measure()</code> function that tests for valid return value in <code>meas[type]</code>. You would need to set <code>meas[type]</code> to a known invalid value before the read (such as <code>0</code>).</p> <pre><code>uint8_t SHT21::measure(uint8_t type, void (*delayFun)()) { start(); writeByte(type == TEMP? MEASURE_TEMP : MEASURE_HUMI) for (uint8_t i = 0; i &lt; 250; ++i) { if (!digiRead()) { meas[type] = readByte(1) &lt;&lt; 8; meas[type] |= readByte(1); uint8_t flipped = 0; for (uint8_t j = 0x80; j != 0; j &gt;&gt;= 1) { flipped &gt;&gt;= 1; } if (readByte(0) != flipped) break; return 0; } if (delayFun) delayFun(); else delay(1); } connReset(); return 1; } </code></pre> <p>You probably know that if you add a method to a library cpp then you also need to add a corresponding prototype to the .h otherwise the arduino will fail to compile your code.</p> <p>.cpp</p> <pre><code>uint8_t SHT21::measureTest(uint8_t type, void (*delayFun)()) { } </code></pre> <p>.h</p> <pre><code>uint8_t measureTest(uint8_t type, void (*delayFun)() =0); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload