Use a red LED's photovoltaic voltage to approximately tell if it is day or night.
Note: use the Day_AttachDayWork() and Night_AttachWork() functions to register a callback that will be run at the start of each day. This framework is how I debuged the day-night stat machine.
The LED is a CREE C503B-RCN-CW0Z0AA1. The LED works somewhat like a solar cell but it develops up to 1.6V with red light and shorter wavelengths. The LED will act as a current source to the NPN transistor base which will then do common emitter current gain which can be measured with ADC1 on R4. Over a very short time, the sun will move through the LED focus. Adding a diffuser reduces this effect and extends the day/night debounce to more appropriate times.
With a solar panel use a voltage divider.
With a serial port connection (set the BOOTLOAD_PORT in Makefile) and xboot installed on the Irrigate7 run 'make bootload' and it should compile and then flash the MCU.
sudo apt-get install git gcc-avr binutils-avr gdb-avr avr-libc avrdude
git clone https://github.com/epccs/Irrigate7/
cd /Irrigate7/DayNight
make bootload
...
avrdude done. Thank you.
Now connect with picocom (or ilk).
#exit is C-a, C-x
picocom -b 38400 /dev/ttyUSB0
Commands are interactive over the serial interface at 38400 baud rate. The echo will start after the second character of a new line.
rpu_address is taken from the I2C address 0x29 (e.g. ../Uart/id.h get_Rpu_address() ). The value of rpu_address is used as a character in a string, which means don't use a null value (C strings are null terminated), but the ASCII value for '1' (0x31) is easy and looks nice.
The STATUS_LED is bliked fast (twice per second) if the I2C address is not found, also the rpu_address defaults to '0'.
Commands and their arguments follow.
Identify is from ../Uart/id.h Id().
/1/id?
{"id":{"name":"DayNight","desc":"Irrigate7 (14320^5) Board /w atmega1284p","avr-gcc":"5.4.0"}}
Report status of the state machine.
/1/day?
{"day_state":"DAY"}
... 11 hr
{"day_state":"DAY"}
{"day_state":"EVENING"}
... 15 min
{"day_state":"EVENING"}
TurnOnLED's
{"day_state":"NIGHT"}
... 12 hr
{"day_state":"NIGHT"}
{"day_state":"MORNING"}
... 15 min
{"day_state":"MORNING"}
WaterTheGarden
{"day_state":"DAY"}
... 20 hr (e.g. using an indoor lamp)
{"day_state":"DAY"}
{"day_state":"FAIL"}