mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-13 17:22:54 -05:00
Arduino script updates
This commit is contained in:
@@ -37,44 +37,49 @@ float humidity = 0; // Instantaneous humidity [%]
|
|||||||
float tempH = 0; // Instantaneous temperature from humidity sensor [F]
|
float tempH = 0; // Instantaneous temperature from humidity sensor [F]
|
||||||
float tempP = 0; // Instantaneous temperature from pressure sensor [F]
|
float tempP = 0; // Instantaneous temperature from pressure sensor [F]
|
||||||
float pressure = 0; // Instantaneous pressure [pascals]
|
float pressure = 0; // Instantaneous pressure [pascals]
|
||||||
|
float rain = 0; // Instantaneous rain [inches]
|
||||||
|
|
||||||
float batt_lvl = 0; // Battery level [Analog value from 0 to 1023]
|
float batt_lvl = 0; // Battery level [Analog value from 0 to 1023]
|
||||||
float light_lvl = 0; // Light level [Analog value from 0 to 1023]
|
float light_lvl = 0; // Light level [Analog value from 0 to 1023]
|
||||||
|
|
||||||
// volatiles are subject to modification by IRQs
|
// volatiles are subject to modification by IRQs
|
||||||
volatile unsigned long raintime, rainlast, raininterval, rain;
|
volatile long lastRainIRQ = 0;
|
||||||
|
volatile byte rainClicks = 0;
|
||||||
|
|
||||||
volatile long lastWindIRQ = 0;
|
volatile long lastWindIRQ = 0;
|
||||||
volatile byte windClicks = 0;
|
volatile byte windClicks = 0;
|
||||||
|
|
||||||
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
|
|
||||||
//Interrupt routines (these are called by the hardware interrupts, not by the main code)
|
//Interrupt routines (these are called by the hardware interrupts, not by the main code)
|
||||||
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
void rainIRQ()
|
|
||||||
// Count rain gauge bucket tips as they occur
|
|
||||||
// Activated by the magnet and reed switch in the rain gauge, attached to input D2
|
|
||||||
{
|
|
||||||
raintime = millis(); // grab current time
|
|
||||||
raininterval = raintime - rainlast; // calculate interval between this and last event
|
|
||||||
|
|
||||||
if (raininterval > 10) // ignore switch-bounce glitches less than 10mS after initial edge
|
void rainIRQ()
|
||||||
|
{
|
||||||
|
// Count rain gauge bucket tips as they occur
|
||||||
|
// Activated by the magnet and reed switch in the rain gauge, attached to input D2
|
||||||
|
|
||||||
|
long timeNow = millis();
|
||||||
|
|
||||||
|
if (timeNow - lastRainIRQ > 10) // Ignore switch-bounce glitches less than 10ms after the reed switch closes
|
||||||
{
|
{
|
||||||
rain += 0.011; //Each dump is 0.011" of water
|
lastRainIRQ = timeNow; // Update to the current time
|
||||||
rainlast = raintime; // set up for next event
|
rainClicks++; // Each click is 0.011" of water
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wspeedIRQ()
|
void wspeedIRQ()
|
||||||
// Activated by the magnet in the anemometer (2 ticks per rotation), attached to input D3
|
|
||||||
{
|
{
|
||||||
if (millis() - lastWindIRQ > 10) // Ignore switch-bounce glitches less than 10ms (142MPH max reading) after the reed switch closes
|
// Activated by the magnet in the anemometer (2 ticks per rotation), attached to input D3
|
||||||
|
|
||||||
|
long timeNow = millis();
|
||||||
|
|
||||||
|
if (timeNow - lastWindIRQ > 10) // Ignore switch-bounce glitches less than 10ms (142MPH max reading) after the reed switch closes
|
||||||
{
|
{
|
||||||
lastWindIRQ = millis(); //Grab the current time
|
lastWindIRQ = timeNow; // Update to the current time
|
||||||
windClicks++; //There is 1.492MPH for each click per second.
|
windClicks++; // There is 1.492MPH for each click per second
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
@@ -179,6 +184,9 @@ void calcWeather()
|
|||||||
|
|
||||||
//Calc battery level
|
//Calc battery level
|
||||||
batt_lvl = get_battery_level();
|
batt_lvl = get_battery_level();
|
||||||
|
|
||||||
|
rain = rainClicks * 0.011;
|
||||||
|
rainClicks = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Returns the voltage of the light sensor based on the 3.3V rail
|
//Returns the voltage of the light sensor based on the 3.3V rail
|
||||||
@@ -283,7 +291,7 @@ void printWeather()
|
|||||||
Serial.print(",tempP=");
|
Serial.print(",tempP=");
|
||||||
Serial.print(tempP, 1);
|
Serial.print(tempP, 1);
|
||||||
Serial.print(",rain=");
|
Serial.print(",rain=");
|
||||||
Serial.print(rain, 2);
|
Serial.print(rain, 3);
|
||||||
Serial.print(",pressure=");
|
Serial.print(",pressure=");
|
||||||
Serial.print(pressure, 2);
|
Serial.print(pressure, 2);
|
||||||
Serial.print(",batt_lvl=");
|
Serial.print(",batt_lvl=");
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ weather:
|
|||||||
arduino-cli compile -b arduino:avr:uno Weather.ino -o bin/Weather
|
arduino-cli compile -b arduino:avr:uno Weather.ino -o bin/Weather
|
||||||
|
|
||||||
install:
|
install:
|
||||||
sudo service weather stop
|
kubectl scale --replicas=0 --namespace=home-monitor deployment/weather-serial-reader
|
||||||
arduino-cli upload -b arduino:avr:uno -p /dev/ttyACM0 -i bin/Weather
|
arduino-cli upload -b arduino:avr:uno -p /dev/ttyACM0 -i bin/Weather
|
||||||
sudo service weather start
|
kubectl scale --replicas=1 --namespace=home-monitor deployment/weather-serial-reader
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf bin/
|
rm -rf bin/
|
||||||
Reference in New Issue
Block a user