You are reading a single comment by @Robin and its replies. Click here to read the full conversation.
  • Sat 2019.04.06

    Hello @sammachin sounds like a fun project.

    ' however I'm seeing very unreliable results'

    Interestingly, . . . we aren't seeing any!  ;-)
    Would you mind posting the current output?


    'the LED which pules every 0.001 kWh of energy thats used'

    Assumptions: So, if 1kW is used per hour, we should be seeing roughly three pulses a second? Based on my actual usage then, roughly one pulse per second perhaps? Have you tried just monitoring the pin with digitalRead() inside a loop to see if actual pulses are being detected by the Pico in order to separate whether this is a hardware or software issue?

    http://www.espruino.com/Reference#l__glo­bal_digitalRead



    or something like: (code untested)

    var intervalID = {};
    
    function ci() { clearInterval( intervalID ); }
     
    var delay = 500;
    var nTimes = 40;
    
    // Start Timer
    function st() {
    
      intervalID = setInterval(function () {
    
        console.log( "D0: " + digitalRead(D0) );
        // Flash onboard Red LED
        digitalWrite(LED1, digitalRead(D0));
         
      }, delay);
    }
    
    



    Would you please post the output so we may verify hardware vs software. Although the version shouldn't be an issue here, would you post process.env also, thanks.

    Should the output appear reasonable based on the assumptions above, then it would make sense to then move on to the setWatch() function.



    Shouldn't line 30 and 32

    count[dt] +=1;
    
    ... be:
    
    count[dt++] +=1;
    
    ... or:
    
    count[count.length] += 1;
    
    

    as I don't see the element indexer 'dt' changing.



    Another thought: (from the passive section in link #1)

    'This means that if the pull-up resistor on the input of the data logger is around 10k, the voltage on the input is around 20% of the supply voltage'

    'The alignment of the passive LPS with the LED of the energy meter can be quite critical in order to achieve the lowest "on" resistance'

    'On' may not be close to 2K so 5% below could be much higher

    With the pin mode that is currently selected

    https://www.espruino.com/Reference#t_l__­global_pinMode
    'input_pullup - Digital input with internal ~40k pull-up resistor'

    It is still possible that ~5% (2K / 40K) of the supply voltage is still not close enough to be detected as a logic zero. Would changing to 'pulldown' and reversing the code logic allow a logic high to be detected instead?

    See: Table 46 doc page 86

    https://www.espruino.com/datasheets/STM3­2F103xC.pdf

    Don't forget to adjust for 3.3V vs 5V

About

Avatar for Robin @Robin started