Avatar for furuskog

furuskog

Member since Mar 2017 • Last active Jun 2018
  • 4 conversations
  • 50 comments

Webdeveloper and happy family guy.

Most recent activity

  • in Puck.js, Pixl.js and MDBT42
    Avatar for furuskog

    Ok, thanks I will try that.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for furuskog

    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
    
    
  • in Puck.js, Pixl.js and MDBT42
    Avatar for furuskog

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

  • in Puck.js, Pixl.js and MDBT42
    Avatar for furuskog

    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 :(

  • in Puck.js, Pixl.js and MDBT42
    Avatar for furuskog

    I c. I just changed the ”high” variable to a lower value and it worked. Thanks for the help! :)

  • in Puck.js, Pixl.js and MDBT42
    Avatar for furuskog

    I came up with this

    var high = 0.55;
    var low = 0.0017;
    
    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(A0);
      var hp = map_value(h, low, high, 0, 100);
      var percentage = hp.toFixed(0)+"%";
      
      // Clear display
      g.clear();
      // Use the small font for a title
      g.setFontBitmap();
      g.drawString("Soil moister:");
      // Use a large font for the value itself
      g.setFontVector(10);
      g.drawString(percentage, 5,10);
      // Update the screen
      g.flip();
    }
    
    // Update soil moister every 2 seconds
    setInterval(onTimer, 2000);
    // Update soil moister immediately
    onTimer();
    

    Feedback on the code is welcome

    I have 3 pucks im gooing to try next :) Im gooing to send via bluetooth to my pixl.js

    edit:
    Strange the high and low changes with battery vs plug

  • in Puck.js, Pixl.js and MDBT42
    Avatar for furuskog

    hmm 3.3v seems to work now.

    in water
    h = 0.45629882812
    h = 0.45678710937
    h = 0.45971679687
    h = 0.46044921875
    h = 0.46020507812
    h = 0.4619140625
    h = 0.4619140625
    h = 0.462890625
    h = 0.46362304687

    in air
    h = 0.00024414062
    h = 0.00048828125
    h = 0.0009765625
    h = -0.00024414062
    h = 0.00024414062

    Now i just have to calculate it in %, an have som treshold for 0% because of the fluxuation, maybe an upper limit too?

    I will check the code you guys provided :)

  • in Puck.js, Pixl.js and MDBT42
    Avatar for furuskog

    yes I have done that it cycles through.

Actions