You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • I want to see if it can pickup the light pulses of my energy meter.

    Ahh, right - you mean like this? https://www.espruino.com/Smart+Meter

    The code that's there works because using the LDR allows the IO voltage to change enough that it's detected as a 3.3v IO pin changing state - the LED won't generate enough voltage for that.

    However, you can use the low power comparator:

    // D5 (LED) is used for sensing
    // D1 is used as an output which is also read with setWatch
    // so we can called when things change
    
    var ll = require("NRF52LL");
    analogRead(D5);
    // set up D1 as an output
    digitalWrite(D1,0);
    // create a 'toggle' task for the pin D1
    var tog = ll.gpiote(7, {type:"task",pin:D1,lo2hi:1,hi2lo:1,initialState:0});
    // compare D5 against vref/16 (vref:8 would be vref/2)
    var comp = ll.lpcomp({pin:D5,vref:1,hyst:true});
    // use a PPI to trigger the toggle event
    ll.ppiEnable(0, comp.eCross, tog.tOut);
    // Detect a change on D1
    setWatch(function() {
      print("Pin changed");
    }, D1, {repeat:true});
    

    You'll get 'pin changed' written when the value goes high and low, so the actual number of pulses is 1/2 the amount of times that gets called.

    We're comparing against VCC/16 here - and in my quite dark room I'm getting about VCC/4 - so to make this work you'll want to ensure it's quite dark and the Puck's LED sits right over the smart meter's LED. For testing I'm just covering and uncovering the Puck with my hand.

    It may be you're unlucky and the wavelength of light from the smart meter isn't detected by the Puck's red LED, but hopefully it'll work ok.

About

Avatar for Gordon @Gordon started