#include <Servo.h> | |
Servo sun_meter; | |
String dataIn = ""; //Variable que almacena el string enviado desde el PI | |
boolean dataIn_done = false; //Bandera que indica que se acabó la rx | |
int S1 = 2; //LED SCIENCE | |
int S2 = 3; //LED SCIENCE | |
int S3 = 4; //LED SCIENCE | |
int C1 = 5; //LED COOKING | |
int C2 = 6; //LED COOKING | |
int C3 = 7; //LED COOKING | |
int E1 = 8; //LED EXCERCISE | |
int E2 = 9; //LED EXCERCISE | |
int E3 = 10; //LED EXCERCISE | |
int T1 = 11; //LED TELECOM | |
int T2 = 12; //LED TELECOM | |
int T3 = 13; //LED TELECOM | |
int ANALOG_IN = A0; //LECTURA DEL POT | |
int LED_BAR; | |
int LED_CONT = 10; | |
int ledPins[] = {31, 33, 35, 37, 39, 41, 43, 45, 47, 49}; | |
int i = 0; | |
int potpin = A2; | |
String sun_rad = ""; | |
int meter_delay = 1; | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
dataIn.reserve(200); | |
pinMode(S1, OUTPUT); | |
pinMode(S2, OUTPUT); | |
pinMode(S3, OUTPUT); | |
pinMode(C1, OUTPUT); | |
pinMode(C2, OUTPUT); | |
pinMode(C3, OUTPUT); | |
pinMode(E1, OUTPUT); | |
pinMode(E2, OUTPUT); | |
pinMode(E3, OUTPUT); | |
pinMode(T1, OUTPUT); | |
pinMode(T2, OUTPUT); | |
pinMode(T3, OUTPUT); | |
sun_meter.attach(52); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
//LECTURA DEL POTENCIOMETRO QUE CONTROLA EL BAR-LED | |
// LED_BAR = analogRead(ANALOG_IN); | |
// int ledLevel = map(LED_BAR, 0, 1023, 0, LED_CONT); | |
for (int thisLed = 0; thisLed < 10; thisLed++) { | |
// if the array element's index is less than ledLevel, | |
// turn the pin for this element on: | |
digitalWrite(ledPins[thisLed], HIGH); | |
delay(500); | |
// turn off all pins higher than the ledLevel: | |
} | |
delay(2000); | |
for (int thisLed = 10; thisLed > 0; thisLed--) { | |
// if the array element's index is less than ledLevel, | |
// turn the pin for this element on: | |
digitalWrite(ledPins[thisLed], LOW); | |
// turn off all pins higher than the ledLevel: | |
} | |
// digitalWrite(S1, HIGH); | |
// digitalWrite(C2, HIGH); | |
// digitalWrite(E1, HIGH); | |
// digitalWrite(T3, HIGH); | |
// sun_meter.write(0); | |
// delay(3000); | |
// sun_meter.write(60); | |
// delay(1000); | |
// sun_meter.write(180); | |
if (dataIn_done) | |
{ | |
//Empezar a enceder los leds | |
//Buscar por las intrucciones | |
//BAR LED | |
// if (dataIn=="a\n") | |
// { | |
// digitalWrite(ledPins[0], HIGH); | |
// } | |
// | |
// else if (dataIn=="b\n") | |
// { | |
// digitalWrite(ledPins[1], HIGH); | |
// } | |
// else if (dataIn=="c\n") | |
// { | |
// digitalWrite(ledPins[2], HIGH); | |
// } | |
// else if (dataIn=="d\n") | |
// { | |
// digitalWrite(ledPins[3], HIGH); | |
// } | |
// else if (dataIn=="e\n") | |
// { | |
// digitalWrite(ledPins[4], HIGH); | |
// } | |
// else if (dataIn=="f\n") | |
// { | |
// digitalWrite(ledPins[5], HIGH); | |
// } | |
// else if (dataIn=="g\n") | |
// { | |
// digitalWrite(ledPins[6], HIGH); | |
// } | |
// else if (dataIn=="h\n") | |
// { | |
// digitalWrite(ledPins[7], HIGH); | |
// } | |
// else if (dataIn=="i\n") | |
// { | |
// digitalWrite(ledPins[8], HIGH); | |
// } | |
// else if (dataIn=="j\n") | |
// { | |
// digitalWrite(ledPins[9], HIGH); | |
// } | |
//Serial.println(dataIn); | |
//SCIENCE 1 | |
if (dataIn=="S11\n") | |
{ | |
digitalWrite(S1, HIGH); | |
} | |
else if(dataIn=="S10\n") | |
{ | |
digitalWrite(S1, LOW); | |
} | |
//SCIENCE 2 | |
else if(dataIn=="S21\n") | |
{ | |
digitalWrite(S2, HIGH); | |
} | |
else if(dataIn=="S20\n") | |
{ | |
digitalWrite(S2, LOW); | |
} | |
//SCIENCE 3 | |
else if(dataIn=="S31\n") | |
{ | |
digitalWrite(S3, HIGH); | |
} | |
else if(dataIn=="S30\n") | |
{ | |
digitalWrite(S3, LOW); | |
} | |
//COOKING 1 | |
else if (dataIn=="C11\n") | |
{ | |
digitalWrite(C1, HIGH); | |
} | |
else if (dataIn=="C10\n") | |
{ | |
digitalWrite(C1, LOW); | |
} | |
else if(dataIn=="C20\n") | |
{ | |
digitalWrite(C2,LOW); | |
} | |
//COOKING 2 | |
else if(dataIn=="C21\n") | |
{ | |
digitalWrite(C2, HIGH); | |
} | |
else if(dataIn=="C20\n") | |
{ | |
digitalWrite(C2, LOW); | |
} | |
//COOKING 3 | |
else if(dataIn=="C31\n") | |
{ | |
digitalWrite(C3, HIGH); | |
} | |
else if(dataIn=="C30\n") | |
{ | |
digitalWrite(C3, LOW); | |
} | |
//EXERCICSE 1 | |
else if (dataIn=="E11\n") | |
{ | |
digitalWrite(E1, HIGH); | |
} | |
else if (dataIn=="E10\n") | |
{ | |
digitalWrite(E1, LOW); | |
} | |
//EXERCISE 2 | |
else if(dataIn=="E21\n") | |
{ | |
digitalWrite(E2, HIGH); | |
} | |
else if(dataIn=="E20\n") | |
{ | |
digitalWrite(E2, LOW); | |
} | |
//EXCERSICE 3 | |
else if(dataIn=="E31\n") | |
{ | |
digitalWrite(E3, HIGH); | |
} | |
else if(dataIn=="E30\n") | |
{ | |
digitalWrite(E3, LOW); | |
} | |
//TELECOM 1 | |
else if(dataIn=="T11\n") | |
{ | |
digitalWrite(T1, HIGH); | |
} | |
else if(dataIn=="T10\n") | |
{ | |
digitalWrite(T1, LOW); | |
} | |
//TELECOM 2 | |
else if(dataIn=="T21\n") | |
{ | |
digitalWrite(T2, HIGH); | |
} | |
else if(dataIn=="T20\n") | |
{ | |
digitalWrite(T2, LOW); | |
} | |
//TELECOM 3 | |
else if(dataIn=="T31\n") | |
{ | |
digitalWrite(T3, HIGH); | |
} | |
else if(dataIn=="T30\n") | |
{ | |
digitalWrite(T3, LOW); | |
} | |
//SUN METER-APLICAR LA DIRECCION | |
else if (dataIn=="0\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="30\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="60\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="90\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="120\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="150\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="180\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
dataIn = ""; | |
dataIn_done = false; | |
// delay(5000); | |
// //APAGAR TODO | |
// digitalWrite(S1, LOW); | |
// digitalWrite(S2, LOW); | |
// digitalWrite(S3, LOW); | |
// digitalWrite(C1, LOW); | |
// digitalWrite(C2, LOW); | |
// digitalWrite(C3, LOW); | |
// digitalWrite(E1, LOW); | |
// digitalWrite(E2, LOW); | |
// digitalWrite(E3, LOW); | |
// digitalWrite(T1, LOW); | |
// digitalWrite(T2, LOW); | |
} | |
} | |
void serialEvent(){ | |
while (Serial.available()){ | |
//Cada vez que están disponibles datos en la línea se lee | |
char inChar = (char)Serial.read(); | |
dataIn += inChar; | |
if (inChar == '\n') | |
// Se finaliza la lectura con el caracter \n | |
dataIn_done = true; | |
} | |
} |
#include <Servo.h> | |
Servo sun_meter; | |
String dataIn = ""; //Variable que almacena el string enviado desde el PI | |
boolean dataIn_done = false; //Bandera que indica que se acabó la rx | |
int S1 = 2; //LED SCIENCE | |
int S2 = 3; //LED SCIENCE | |
int S3 = 4; //LED SCIENCE | |
int C1 = 5; //LED COOKING | |
int C2 = 6; //LED COOKING | |
int C3 = 7; //LED COOKING | |
int E1 = 8; //LED EXCERCISE | |
int E2 = 9; //LED EXCERCISE | |
int E3 = 10; //LED EXCERCISE | |
int T1 = 11; //LED TELECOM | |
int T2 = 12; //LED TELECOM | |
int T3 = 13; //LED TELECOM | |
int ANALOG_IN = A0; //LECTURA DEL POT | |
int LED_BAR; | |
int LED_CONT = 10; | |
int ledPins[] = {31, 33, 35, 37, 39, 41, 43, 45, 47, 49}; | |
int i = 0; | |
int potpin = A2; | |
String sun_rad = ""; | |
int meter_delay = 1; | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
dataIn.reserve(200); | |
pinMode(S1, OUTPUT); | |
pinMode(S2, OUTPUT); | |
pinMode(S3, OUTPUT); | |
pinMode(C1, OUTPUT); | |
pinMode(C2, OUTPUT); | |
pinMode(C3, OUTPUT); | |
pinMode(E1, OUTPUT); | |
pinMode(E2, OUTPUT); | |
pinMode(E3, OUTPUT); | |
pinMode(T1, OUTPUT); | |
pinMode(T2, OUTPUT); | |
pinMode(T3, OUTPUT); | |
sun_meter.attach(52); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
//LECTURA DEL POTENCIOMETRO QUE CONTROLA EL BAR-LED | |
// LED_BAR = analogRead(ANALOG_IN); | |
// int ledLevel = map(LED_BAR, 0, 1023, 0, LED_CONT); | |
for (int thisLed = 0; thisLed < 10; thisLed++) { | |
// if the array element's index is less than ledLevel, | |
// turn the pin for this element on: | |
digitalWrite(ledPins[thisLed], HIGH); | |
delay(500); | |
// turn off all pins higher than the ledLevel: | |
} | |
delay(2000); | |
for (int thisLed = 10; thisLed > 0; thisLed--) { | |
// if the array element's index is less than ledLevel, | |
// turn the pin for this element on: | |
digitalWrite(ledPins[thisLed], LOW); | |
// turn off all pins higher than the ledLevel: | |
} | |
// digitalWrite(S1, HIGH); | |
// digitalWrite(C2, HIGH); | |
// digitalWrite(E1, HIGH); | |
// digitalWrite(T3, HIGH); | |
// sun_meter.write(0); | |
// delay(3000); | |
// sun_meter.write(60); | |
// delay(1000); | |
// sun_meter.write(180); | |
if (dataIn_done) | |
{ | |
//Empezar a enceder los leds | |
//Buscar por las intrucciones | |
//BAR LED | |
// if (dataIn=="a\n") | |
// { | |
// digitalWrite(ledPins[0], HIGH); | |
// } | |
// | |
// else if (dataIn=="b\n") | |
// { | |
// digitalWrite(ledPins[1], HIGH); | |
// } | |
// else if (dataIn=="c\n") | |
// { | |
// digitalWrite(ledPins[2], HIGH); | |
// } | |
// else if (dataIn=="d\n") | |
// { | |
// digitalWrite(ledPins[3], HIGH); | |
// } | |
// else if (dataIn=="e\n") | |
// { | |
// digitalWrite(ledPins[4], HIGH); | |
// } | |
// else if (dataIn=="f\n") | |
// { | |
// digitalWrite(ledPins[5], HIGH); | |
// } | |
// else if (dataIn=="g\n") | |
// { | |
// digitalWrite(ledPins[6], HIGH); | |
// } | |
// else if (dataIn=="h\n") | |
// { | |
// digitalWrite(ledPins[7], HIGH); | |
// } | |
// else if (dataIn=="i\n") | |
// { | |
// digitalWrite(ledPins[8], HIGH); | |
// } | |
// else if (dataIn=="j\n") | |
// { | |
// digitalWrite(ledPins[9], HIGH); | |
// } | |
//Serial.println(dataIn); | |
//SCIENCE 1 | |
if (dataIn=="S11\n") | |
{ | |
digitalWrite(S1, HIGH); | |
} | |
else if(dataIn=="S10\n") | |
{ | |
digitalWrite(S1, LOW); | |
} | |
//SCIENCE 2 | |
else if(dataIn=="S21\n") | |
{ | |
digitalWrite(S2, HIGH); | |
} | |
else if(dataIn=="S20\n") | |
{ | |
digitalWrite(S2, LOW); | |
} | |
//SCIENCE 3 | |
else if(dataIn=="S31\n") | |
{ | |
digitalWrite(S3, HIGH); | |
} | |
else if(dataIn=="S30\n") | |
{ | |
digitalWrite(S3, LOW); | |
} | |
//COOKING 1 | |
else if (dataIn=="C11\n") | |
{ | |
digitalWrite(C1, HIGH); | |
} | |
else if (dataIn=="C10\n") | |
{ | |
digitalWrite(C1, LOW); | |
} | |
else if(dataIn=="C20\n") | |
{ | |
digitalWrite(C2,LOW); | |
} | |
//COOKING 2 | |
else if(dataIn=="C21\n") | |
{ | |
digitalWrite(C2, HIGH); | |
} | |
else if(dataIn=="C20\n") | |
{ | |
digitalWrite(C2, LOW); | |
} | |
//COOKING 3 | |
else if(dataIn=="C31\n") | |
{ | |
digitalWrite(C3, HIGH); | |
} | |
else if(dataIn=="C30\n") | |
{ | |
digitalWrite(C3, LOW); | |
} | |
//EXERCICSE 1 | |
else if (dataIn=="E11\n") | |
{ | |
digitalWrite(E1, HIGH); | |
} | |
else if (dataIn=="E10\n") | |
{ | |
digitalWrite(E1, LOW); | |
} | |
//EXERCISE 2 | |
else if(dataIn=="E21\n") | |
{ | |
digitalWrite(E2, HIGH); | |
} | |
else if(dataIn=="E20\n") | |
{ | |
digitalWrite(E2, LOW); | |
} | |
//EXCERSICE 3 | |
else if(dataIn=="E31\n") | |
{ | |
digitalWrite(E3, HIGH); | |
} | |
else if(dataIn=="E30\n") | |
{ | |
digitalWrite(E3, LOW); | |
} | |
//TELECOM 1 | |
else if(dataIn=="T11\n") | |
{ | |
digitalWrite(T1, HIGH); | |
} | |
else if(dataIn=="T10\n") | |
{ | |
digitalWrite(T1, LOW); | |
} | |
//TELECOM 2 | |
else if(dataIn=="T21\n") | |
{ | |
digitalWrite(T2, HIGH); | |
} | |
else if(dataIn=="T20\n") | |
{ | |
digitalWrite(T2, LOW); | |
} | |
//TELECOM 3 | |
else if(dataIn=="T31\n") | |
{ | |
digitalWrite(T3, HIGH); | |
} | |
else if(dataIn=="T30\n") | |
{ | |
digitalWrite(T3, LOW); | |
} | |
//SUN METER-APLICAR LA DIRECCION | |
else if (dataIn=="0\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="30\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="60\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="90\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="120\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="150\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
else if (dataIn=="180\n") | |
{ | |
sun_meter.write(dataIn.toInt()); | |
} | |
dataIn = ""; | |
dataIn_done = false; | |
// delay(5000); | |
// //APAGAR TODO | |
// digitalWrite(S1, LOW); | |
// digitalWrite(S2, LOW); | |
// digitalWrite(S3, LOW); | |
// digitalWrite(C1, LOW); | |
// digitalWrite(C2, LOW); | |
// digitalWrite(C3, LOW); | |
// digitalWrite(E1, LOW); | |
// digitalWrite(E2, LOW); | |
// digitalWrite(E3, LOW); | |
// digitalWrite(T1, LOW); | |
// digitalWrite(T2, LOW); | |
} | |
} | |
void serialEvent(){ | |
while (Serial.available()){ | |
//Cada vez que están disponibles datos en la línea se lee | |
char inChar = (char)Serial.read(); | |
dataIn += inChar; | |
if (inChar == '\n') | |
// Se finaliza la lectura con el caracter \n | |
dataIn_done = true; | |
} | |
} |
# coding: utf-8 | |
# Estimate average day that corresponds to month | |
# In[1]: | |
#libraries | |
import pvlib | |
import pandas as pd | |
import datetime | |
#import pysolar | |
import os | |
os.chdir("C:\\Users\paulo\OneDrive\space_apps\\Notebooks") | |
#import sunposition | |
from datetime import datetime | |
import numpy as np | |
import sys | |
# In[2]: | |
#location and solar panel array data - We tried to estimate real W/m2 depending on tilt and azimuth | |
alt=4169 | |
lat=19.453771 | |
lon=-155.603582 | |
tilt=45 | |
az=180 | |
Mission="HI-SEAS" | |
timez="Pacific/Honolulu" | |
#temp=60 | |
array_area=72 #m2 | |
eff=0.08 #low | |
#location objet to consider panel tilt and azimuth | |
loc=pvlib.location.Location(lat,lon, tz=timez, altitude=alt, name=Mission) | |
# In[3]: | |
#load historic weather data from energy plus epw converted to csv using EP-Weather | |
w_data= pd.read_csv("Hawaii.csv") | |
w_data.index=pd.date_range("1/1/2015","1/1/2016",freq="H")[1:] #time stamp | |
# In[4]: | |
#get radiation data from weather file | |
datA=list(w_data.keys()) | |
datA=[e for e in datA if "extraterrestrial" not in e.lower()] | |
ghi=[e for e in datA if "global horizontal radiation" in e.lower()] | |
dni=[e for e in datA if "direct normal radiation" in e.lower()] | |
dhi=[e for e in datA if "diffuse horizontal radiation" in e.lower()] | |
# In[5]: | |
#calculate solar angles to consider tilt and azimuth | |
solar=loc.get_solarposition(w_data.index) | |
#calculate real radiation considering tilt and azimuth (CHECK) | |
rad_tilted=pvlib.irradiance.total_irrad(tilt,az,solar["zenith"].values,solar["azimuth"].values, w_data[dni].values, w_data[ghi].values, w_data[dhi].values, dni_extra=None, airmass=None, albedo=0.25, surface_type=None, model='isotropic', model_perez='allsitescomposite1990') | |
#interested in global radiation that reaches the array | |
real_rad=pd.DataFrame(rad_tilted["poa_global"],index=pd.date_range("1/1/2015","1/1/2016",freq="H")[1:])[1] | |
# In[6]: | |
#seems to be working good | |
Compare_WTAZ=pd.concat([real_rad.resample("m").mean()[:12],w_data[ghi].resample("m").mean()[:12]],axis=1) | |
Compare_WTAZ | |
# In[7]: | |
#find an average day per month using weather data | |
w_data_ni=w_data.reset_index() | |
real_rad_ni=real_rad.reset_index() | |
av_month=w_data_ni[ghi].groupby([w_data_ni["index"].dt.month, w_data_ni["index"].dt.hour]).mean() #weather | |
av_month_r=real_rad_ni.groupby([real_rad_ni["index"].dt.month, real_rad_ni["index"].dt.hour]).mean() | |
#av_month.loc[2] #view data for month 2 | |
# Sun scale will be based on the difference between monthly expected hour value and measured value | |
# In[17]: | |
def sun_meter_pos(mon,hr,measured): | |
""" | |
too tired to think a better way | |
mon: month (1-12) | |
hr: hour (0-23) | |
""" | |
p=1 | |
expected=float(av_month.loc[mon].loc[hr]) #view data for month and hour | |
if expected<3: #not measure at night | |
deg=0 | |
p=1 | |
else: | |
p=abs(expected-measured)/expected | |
deg=0 | |
if p>1 and p<1.1: | |
deg=90 | |
if p>1.1 and p<=1.2: | |
deg=60 | |
if p>1.2 and p<=1.3: | |
deg=30 | |
if p>1.3: | |
deg=0 | |
if p<1 and p>=0.9: | |
deg=120 | |
if p<0.9 and p>0.8: | |
deg=150 | |
if p<0.8: | |
deg=180 | |
return [p,deg] | |
# In[35]: | |
#calculate maximum batery "charge" | |
max_battery=float(w_data[ghi].max()*4*eff*array_area) #4 good hours | |
# In[10]: | |
def best_hr(mon): | |
return int(av_month.loc[mon].idxmax()) | |
# In[11]: | |
best_hr(1) | |
# In[37]: | |
#estimate cumulative energy by the end of the day usig real rad and efficiency data | |
#this will be the "battery" measurment for now | |
def cumulative_day(s_meter): | |
return (s_meter[0]*float(av_month_r.loc[mon].sum())*eff*array_area) | |
def battery_meter(last_base,mon,hr,s_meter): | |
bh=best_hr(mon) | |
if hr==(bh-1): | |
last_base=[0,0] | |
value=cumulative_day(s_meter) | |
e_p=value/max_battery | |
led=np.ceil(10*value/max_battery) | |
return [e_p,int(abs(led))] | |
if hr in [bh,bh+1]: | |
value=cumulative_day(s_meter) | |
e_p=(last_base[0]+(value/max_battery))*0.5 | |
led=(last_base[1]+np.ceil(10*value/max_battery))*0.5#visual representation | |
return [e_p,int(led)] | |
if hr not in [bh-1,bh,bh+1]: | |
return last_base | |
# In[54]: | |
#base consumptions of categories, this (idealy) will be loaded with data from an excel table | |
science=[0.4,600,4500,8000] | |
food=[0.4,500,2600,5500] | |
recreation=[0.1,60,1500,3000] | |
telecom=[0.1,500,1700,3000] | |
allcat=[science,food,recreation,telecom] | |
# In[52]: | |
#how to turn on leds according to available power, i'm really tired to make it nice | |
def get_cat_leds(av_power): | |
vals=[] | |
vals.append(av_power*science[0]) | |
vals.append(av_power*food[0]) | |
vals.append(av_power*recreation[0]) | |
vals.append(av_power*telecom[0]) | |
l=[] | |
for e in range(len(allcat)): | |
l.append(allcat[e].index(min(allcat[e],key=lambda x:abs(x-vals[e])))) | |
return l | |
# In[13]: | |
#run example using HI SEAS data | |
ex_data= pd.read_csv("solar_radiation_HISEAS.csv",parse_dates=[["date","time"]]) | |
ex_data.index=ex_data["date_time"] | |
# In[39]: | |
#check data (not necessary) | |
measured_data=ex_data["RAD"].sort_index().resample("h").mean().dropna() | |
measured_data | |
# In[15]: | |
# send data to controller | |
import serial | |
ser = serial.Serial( | |
port='\\\\.\\COM3', | |
baudrate=9600, | |
parity=serial.PARITY_ODD, | |
stopbits=serial.STOPBITS_ONE, | |
bytesize=serial.EIGHTBITS | |
) | |
# In[65]: | |
# send data | |
last_base=[1,10] | |
for e in range(len(measured_data))[:500]: | |
measured=float(measured_data[e]) | |
mon=int(measured_data.index[e].month) | |
hr=int(measured_data.index[e].hour) | |
s_pos=sun_meter_pos(mon,hr,measured) | |
b_pos=battery_meter(last_base,mon,hr,s_pos) | |
last_base=b_pos | |
to_c=[s_pos,b_pos,get_cat_leds(b_pos[0]*max_battery),hr] | |
to_cont=[to_c[0][1],,list(zip(to_c[2],["S","C","E","T"]))] | |
#if ser.isOpen(): | |
#ser.close() | |
#ser.open() | |
#ser.isOpen() | |
#print(to_cont[0]) | |
ser.write(to_cont[0].encode()) | |
time.sleep(0.6) | |
for e in to_cont[1]: | |
#print(e[1]+str(e[0])) | |
ser.write(str(e[1]+str(e[0])+"\n").encode()) | |
time.sleep(0.6) | |
time.sleep(5) | |
# In[16]: | |
ser.write(b"0\n") | |
# In[ ]: | |
# In[41]: | |
df1['hexatime'] = pd.to_datetime(df1['hexatime'],unit='s') | |
# In[147]: | |
total_d_power.resample("M").min() | |
# In[188]: | |
df1["W-h"]=df1["RAD"]*eff*array_area*(5/60) | |
df1.resample("d").sum().resample("m").min() | |
# In[ ]: | |
#libraries | |
import pvlib | |
import pandas as pd | |
import datetime | |
#import pysolar | |
import os | |
os.chdir("C:\\Users\paulo\OneDrive\space_apps\\Notebooks") | |
#import sunposition | |
from datetime import datetime | |
import numpy as np | |
import sys | |
#location and solar panel array data - We tried to estimate real W/m2 depending on tilt and azimuth | |
alt=4169 | |
lat=19.453771 | |
lon=-155.603582 | |
tilt=45 | |
az=180 | |
Mission="HI-SEAS" | |
timez="Pacific/Honolulu" | |
#temp=60 | |
array_area=72 #m2 | |
eff=0.08 #low | |
#location objet to consider panel tilt and azimuth | |
loc=pvlib.location.Location(lat,lon, tz=timez, altitude=alt, name=Mission) | |
#load historic weather data from energy plus epw converted to csv using EP-Weather | |
w_data= pd.read_csv("Hawaii.csv") | |
w_data.index=pd.date_range("1/1/2015","1/1/2016",freq="H")[1:] #time stamp | |
#get radiation data from weather file | |
datA=list(w_data.keys()) | |
datA=[e for e in datA if "extraterrestrial" not in e.lower()] | |
ghi=[e for e in datA if "global horizontal radiation" in e.lower()] | |
dni=[e for e in datA if "direct normal radiation" in e.lower()] | |
dhi=[e for e in datA if "diffuse horizontal radiation" in e.lower()] | |
#calculate solar angles to consider tilt and azimuth | |
solar=loc.get_solarposition(w_data.index) | |
#calculate real radiation considering tilt and azimuth (CHECK) | |
rad_tilted=pvlib.irradiance.total_irrad(tilt,az,solar["zenith"].values,solar["azimuth"].values, w_data[dni].values, w_data[ghi].values, w_data[dhi].values, dni_extra=None, airmass=None, albedo=0.25, surface_type=None, model='isotropic', model_perez='allsitescomposite1990') | |
#interested in global radiation that reaches the array | |
real_rad=pd.DataFrame(rad_tilted["poa_global"],index=pd.date_range("1/1/2015","1/1/2016",freq="H")[1:])[1] | |
#seems to be working good | |
Compare_WTAZ=pd.concat([real_rad.resample("m").mean()[:12],w_data[ghi].resample("m").mean()[:12]],axis=1) | |
Compare_WTAZ |
We use weather data files (TMY format) to compare the expected energy and the actual energy measured in real time. This helps to determine how much energy (estimated) would be available for consumption.
Python pvlib helped us a lot to calculate the "real" global radiation reaching a solar panel array for given tilt, azimuth, location and date-time data.
SpaceApps is a NASA incubator innovation program.