pixl.js with analog moister sensor

Posted on
Page
of 2
Prev
/ 2
  • I c. I just changed the ”high” variable to a lower value and it worked. Thanks for the help! :)

  • i just tested my seeed grove moisture sensor with success, and a few notes:

    1. need to convert from the sensor document values (0 - 950) to the espruino analogRead range (0-1)
    2. different values depending on battery power vs usb. not sure how much the values will change over the life of the battery. sensor in water from the battery was .47, and from usb was .55
    3. in order to use the sensor from the grove shield, i had to put a jumper from the 3.3v to 5v pins, as the shield uses the 5v pin for power. the sensor works with 3.3v - 5v range, so this was acceptable

    when i replace my full code i'll post in another thread

  • Good news!

    Even got it work on a esp32 with espruino
    Here is the code

    var high = 0.5;
    var low = 0.0;
    
    function map_value(val, in_min, in_max, out_min, out_max){
      var result = (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
      
      if(result < out_min) {
        return out_min;  
      } 
      else if(result > out_max) {
        return out_max;
      }
      
      return result;
    }
    
    function onTimer() {
      var h = analogRead(D35); // D35 is a adc-port (analog to digital converter)
      var hp = map_value(h, low, high, 0, 100);
      var percentage = hp.toFixed(0)+"%";
      
      console.log("Soil moister", percentage);
    }
    
    // Update soil moister every 2 seconds
    setInterval(onTimer, 2000);
    // Update soil moister immediately
    onTimer();
    

    To bad there are no bluetooth support yet :(

  • Ahh - but there is now Bluetooth support for the esp32!

  • Nice! I just asumed because of the documentation sudgested otherwise :)

  • It's still pretty beta, but with a bit of work you can get it doing simple advertising stuff :)

  • Im trying to broadcast ble data with the esp32. But its not implemented yet the console informs me. Didnt you guys say it worked now?

    var high = 0.5;
    var low = 0.0;
    
    function map_value(val, in_min, in_max, out_min, out_max){
      var result = (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
      
      if(result < out_min) {
        return out_min;  
      } 
      else if(result > out_max) {
        return out_max;
      }
      
      return result;
    }
    
    function onTimer() {
      var h = analogRead(D35);
      var hp = map_value(h, low, high, 0, 100);
      var percentage = hp.toFixed(0)+"%";
      
      NRF.setServices({
        0xBCDE : {
          0xABCD : {
            value : percentage,
            readable : true
          }
        }
      });
      console.log("Soil moister", percentage);
    }
    
    // Update soil moister every 2 seconds
    setInterval(onTimer, 2000);
    // Update soil moister immediately
    onTimer();
    

    Console

    
    Soil moister 0%
    WARNING: has connected not implemented yet
    
    
  • I think I said it was very beta. You can get advertising going with some work - maybe with NRF.wake()? It'll still give you warnings all over the place.

    If you have issues with it post on the ESP32 forum though. ESP32 isn't something I can provide any support for.

  • Ok, thanks I will try that.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

pixl.js with analog moister sensor

Posted by Avatar for furuskog @furuskog

Actions