-
• #2
Sorry for the delay...
The
Puck.light()
command is measuring the voltage across the red LED (pin D5) since LEDs actually generate a small voltage from light (as well as creating it). So you don't need an LDR for it to work. -
• #3
Wow that is amazing, I am guessing the dynamic range is not that great?
-
• #4
No, it's not fantastic, but as far as detecting the difference between night and day or whether a door is open goes, it's fine
-
• #5
Great I will give it a try, I want to see if it can pickup the light pulses of my energy meter.
-
• #6
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.
-
• #7
Just to add that this is actually preferable to the LDR solution as it uses amazingly little power when idle.
Hi there,
I have the Espruino Puck Lite and would like to know when I call the Puck.light() which pins is reading?
Do I always need to add a light dependent resistor?
Cheers.