Ok, so this page details an 8266 connected to an ambient light sensor, the MAX 440099.
It's a straighforward i2c device and is available on a breakout board as shown below:
 |
Got it from make.net.za/ |
What is it good for? Well, it's pretty good to to estimate the energy that you can get our of your
solar panels, given the light intensity. Someone on the net published a formula between lux
and potential output power. In my tests, it seemed pretty good. I unfortunately no longer remember
where I got the formula or what exactly it is, but you can derive it from the Annex RDS code for 8266
below:
' --- Maxim 440099 Tester ---
Address = &H4A
Dim R(7)
DoSendUDP = 0
PANELS = 4
PANELW = 330
PANELE = 17 ' Panel Efficiency percentage
AREA = PANELW/PANELE/10 * PANELS
PFACTOR = AREA * PANELE/100
INFO$ = STR$(PANELS) & " Panels of " & STR$(PANELW) & "W @ " & STR$(PANELE) & "% "
INFO$ = INFO$ & " have an area of " & STR$(AREA,"%.2f") & " m<sup>2</sup>.<br><br>"
INFO$ = INFO$ & "MAX44009 REGISTERS:"
ONHTMLRELOAD StartPage
GOSUB StartPage
TIMER0 120000,DoTIMER0
I2C.SETUP 4, 5 ' set I2C port on pins 4 and 5
WHILE 1 = 1
R(0) = I2C.READREGBYTE(Address,0)
'-- Just a temporary fix until I can solder a pulldown on A0
'-- A0 seems to float so the address flips between 4A and 4B
'-- This snippet tries to adapt it (talk about too lazy to solder :-)
IF R(0) = -1 Then
IF Address = &H4A Then
Address = &H4B
Else
Address = &H4A
End If
R(0) = I2C.READREGBYTE(Address,0)
End If
R(1) = I2C.READREGBYTE(Address,1)
R(2) = I2C.READREGBYTE(Address,2)
R(3) = I2C.READREGBYTE(Address,3)
R(4) = I2C.READREGBYTE(Address,4)
R(5) = I2C.READREGBYTE(Address,5)
R(6) = I2C.READREGBYTE(Address,6)
R(7) = I2C.READREGBYTE(Address,7)
REXP = R(3)\16
RMANH = R(3) MOD 16
RMANL = R(4)
RMAN = RMANH * 16 + RMANL
IF REXP = 15 THEN
V$ = "OVER"
W$ = "OVER"
Y$ = ""
ELSE
V = 2^REXP * RMAN * 0.045
W = V * 0.0079
Y = W * PFACTOR
V$ = STR$(V)
W$ = STR$(W,"%.0f")
Y$ = STR$(Y,"%.0f")
END IF
H$ = ""
For X = 0 To 7
' WLOG X,HEX$(R(X))
H$ = H$ & "R" & STR$(X) & " : " & HEX$(R(X)) & "<br>"
Next
H$ = H$ & "<BR>"
H$ = H$ & V$ & " lux<br>" & W$ & " W/m<sup>2</sup><br>"
H$ = H$ & Y$ & " W Max Array Power"
J$ = "document.getElementById(""d"").innerHTML = '" & H$ & "';"
JSCRIPT J$
If DoSendUDP = 1 Then
DoSendUDP = 0
SendUDP
End If
Pause 1000
WEnd
StartPage:
CLS
HTML INFO$
HTML "<div id=""d"">This is a div</div>"
HTML BUTTON$("SendUDP",DoTIMER0)
RETURN
DoTIMER0:
DoSendUDP = 1
RETURN
Sub SendUDP
LOCAL D$
D$ = "lux1" & CHR$(10)
D$ = D$ & "lux:" & V$ & CHR$(10)
D$ = D$ & "w:" & W$ & CHR$(10)
D$ = D$ & "wmax:" & Y$ & CHR$(10)
WLOG TIME$ & " : " & D$
UDP.BEGIN 5222
UDP.WRITE "192.168.29.80",5222,D$
UDP.WRITE "192.168.29.2",5222,D$
UDP.STOP
End Sub