Post by impactoz on Aug 26, 2019 1:15:52 GMT -8
A couple of people have asked how I did the installation and configuration of the VEML6075. This was the first time I went really off the plan with the SkyWeather - adding a new sensor not currently supported by SkyWeather, and not knowing if SwitchDoc will ever support it...
Its working good enough for me at present - so this is what I did... It should work for you...
I got the VEML6075 from a local supplier - wont mention names - but google your local area to find small little companies selling PI, Arduino, Sensors etc... Amazingly for me it arrived next day - which was great considering it was less than $10 including postage...
OF course its just a sensor with no grove connector - so using this website as confirmation of pin configuration, pimylifeup.com/raspberry-pi-uv-sensor-veml6075/ and this switchdoc web page to confirm grove connector color coded pin outs.... www.switchdoc.com/2016/02/tutorial-intro-to-grove-connectors-for-arduinoraspberry-pi-projects/
I cut a spare Grove cable and soldered it onto the VEML6075.... Easy - hardest part done.
Now for the software
First thing needed is the drivers so within the SKyWeather folder do a
Now for code bit - I tried to write it in alignment with the other sensors, so it would be easier to retrofit SkyWeather upgrade in the future should it ever get fully supported by SwitchDoc - Took a guess of what it might look like...
In conflocal.py I added
Following all the other sensors - Now not necessary - you could just hard code it all, but tried to keep the good ideas of SwitchDoc going here...
Then its time to modify SkyWeather.py
was added in the section where all the sensors are initialised - after # Device Present State Variables, looking like this;
config.Camera_Present = False
config.TCA9545_I2CMux_Present = False
config.SunAirPlus_Present = False
config.AS3935_Present = False
config.DS3231_Present = False
config.BMP280_Present = False
config.BME680_Present = False
config.AM2315_Present = False
config.ADS1015_Present = False
config.ADS1115_Present = False
config.OLED_Present = False
config.WXLink_Present = False
config.Sunlight_Present = False
config.TSL2591_Present = False
config.VEML6075_Present = False
Added an
After config Leds - so it look something like this;
import SI1145Lux
if (config.runLEDs):
from neopixel import *
import pixelDriver
import TSL2591
import veml6075
import SDL_Pi_TCA9545
Then its time to do a setup of the sensor - so just after the section of the # BME680 Setup I added my own;
Still with me? Hardest part done.... Well maybe not - Now we need to check if its available...
I will show the whole block of code, as it may be better than me trying to explain it;
So the above is where the magic happens...
SUnlightUV is the UV values combined,
UnslightUVIndex is rounded to just 1 decimal place to make it look pretty
And forget the SolarRad - I was trying to get solarRadiation by all sorts of means, I have kept this, as at low values it looks accurate but the brighter it gets, the figure comes out too high... Of course since then I have learned you cannot calculate this using lux (which the VEML6075 outputs - so its another sensor to get solar radiation properly).
You will notice I deliberately used the standard variables already defined - so the values get stored in the database, or sent to Weather Underground or Weather Stem - I thought this was important to keep the consistency...
Just to keep it aligned in the section following
# Initialize Variables
bmp180Temperature = 0
I added the print statement to show if the sensor was detected...
And I think that's all there is to it.... If you try it, and its not working, yell out - I might have missed a line somewhere....
Its working good enough for me at present - so this is what I did... It should work for you...
I got the VEML6075 from a local supplier - wont mention names - but google your local area to find small little companies selling PI, Arduino, Sensors etc... Amazingly for me it arrived next day - which was great considering it was less than $10 including postage...
OF course its just a sensor with no grove connector - so using this website as confirmation of pin configuration, pimylifeup.com/raspberry-pi-uv-sensor-veml6075/ and this switchdoc web page to confirm grove connector color coded pin outs.... www.switchdoc.com/2016/02/tutorial-intro-to-grove-connectors-for-arduinoraspberry-pi-projects/
I cut a spare Grove cable and soldered it onto the VEML6075.... Easy - hardest part done.
Now for the software
First thing needed is the drivers so within the SKyWeather folder do a
sudo pip3 install adafruit-circuitpython-VEML6075
Now for code bit - I tried to write it in alignment with the other sensors, so it would be easier to retrofit SkyWeather upgrade in the future should it ever get fully supported by SwitchDoc - Took a guess of what it might look like...
In conflocal.py I added
VEML6075_Present = True
Following all the other sensors - Now not necessary - you could just hard code it all, but tried to keep the good ideas of SwitchDoc going here...
Then its time to modify SkyWeather.py
config.VEML6075_Present = False
was added in the section where all the sensors are initialised - after # Device Present State Variables, looking like this;
config.Camera_Present = False
config.TCA9545_I2CMux_Present = False
config.SunAirPlus_Present = False
config.AS3935_Present = False
config.DS3231_Present = False
config.BMP280_Present = False
config.BME680_Present = False
config.AM2315_Present = False
config.ADS1015_Present = False
config.ADS1115_Present = False
config.OLED_Present = False
config.WXLink_Present = False
config.Sunlight_Present = False
config.TSL2591_Present = False
config.VEML6075_Present = False
Added an
import veml6075
After config Leds - so it look something like this;
import SI1145Lux
if (config.runLEDs):
from neopixel import *
import pixelDriver
import TSL2591
import veml6075
import SDL_Pi_TCA9545
Then its time to do a setup of the sensor - so just after the section of the # BME680 Setup I added my own;
################
# VEML6075 Setup
try:
uv_sensor = veml6075.VEML6075(1)
uv_sensor.set_shutdown(False)
uv_sensor.set_high_dynamic_range(False)
uv_sensor.set_integration_time('100ms')
config.VEML6075_Present = True
except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
config.VEML6075_Present = False
print ("after veml6075", config.VEML6075_Present)
Still with me? Hardest part done.... Well maybe not - Now we need to check if its available...
I will show the whole block of code, as it may be better than me trying to explain it;
# use TSL2591 first
if (config.TSL2591_Present):
################
# turn I2CBus 3 on
if (config.TCA9545_I2CMux_Present):
tca9545.write_control_register(TCA9545_CONFIG_BUS3)
full, ir = tsl2591.get_full_luminosity() # read raw values (full spectrum and ir spectrum)
lux = tsl2591.calculate_lux(full, ir) # convert raw values to lux
SunlightVisible = lux
SunlightIR = ir
SunlightUV = 0
SunlightUVIndex = 0.0
else:
if (config.Sunlight_Present):
################
# turn I2CBus 3 on
if (config.TCA9545_I2CMux_Present):
tca9545.write_control_register(TCA9545_CONFIG_BUS3)
SunlightVisible = SI1145Lux.SI1145_VIS_to_Lux(Sunlight_Sensor.readVisible())
SunlightIR = SI1145Lux.SI1145_IR_to_Lux(Sunlight_Sensor.readIR())
SunlightUV = Sunlight_Sensor.readUV()
SunlightUVIndex = SunlightUV / 100.0
################
# turn I2CBus 0 on
if (config.TCA9545_I2CMux_Present):
tca9545.write_control_register(TCA9545_CONFIG_BUS0)
else:
SunlightVisible = 0
SunlightIR = 0
SunlightUV = 0
SunlightUVIndex = 0.0
if (config.VEML6075_Present):
if (config.TCA9545_I2CMux_Present):
tca9545.write_control_register(TCA9545_CONFIG_BUS0)
print "VEML6075 Present........................."
uva, uvb = uv_sensor.get_measurements()
uv_comp1, uv_comp2 = uv_sensor.get_comparitor_readings()
uv_indices = uv_sensor.convert_to_index(uva, uvb, uv_comp1, uv_comp2)
#print('UVA : {0} UVB : {1} COMP 1 : {2} COMP 2 : {3}'.format(uva, uvb, uv_comp1, uv_comp2))
#print ('UVA INDEX: {0[0]} UVB INDEX : {0[1]} AVG UV INDEX : {0[2]}\n'.format(uv_indices))
SunlightUV = uva + uvb
SunlightUVIndex = round(uv_indices[2],1)
SolarRad = SunlightVisible * 10 / 683
print("UV index:", SunlightUVIndex)
print("SunlightUV:", SunlightUV)
print("SunlightVisible: ", SunlightVisible)
print("Watts sq m: ", SolarRad)
if (as3935LastInterrupt == 0x00):
as3935InterruptStatus = "----No Lightning detected---"
So the above is where the magic happens...
SUnlightUV is the UV values combined,
UnslightUVIndex is rounded to just 1 decimal place to make it look pretty
And forget the SolarRad - I was trying to get solarRadiation by all sorts of means, I have kept this, as at low values it looks accurate but the brighter it gets, the figure comes out too high... Of course since then I have learned you cannot calculate this using lux (which the VEML6075 outputs - so its another sensor to get solar radiation properly).
You will notice I deliberately used the standard variables already defined - so the values get stored in the database, or sent to Weather Underground or Weather Stem - I thought this was important to keep the consistency...
Just to keep it aligned in the section following
# Initialize Variables
bmp180Temperature = 0
I added the print statement to show if the sensor was detected...
print returnStatusLine("SunAirPlus/SunControl",config.SunAirPlus_Present)
print returnStatusLine("SI1145 Sun Sensor",config.Sunlight_Present)
print returnStatusLine("TSL2591 Sun Sensor",config.TSL2591_Present)
print returnStatusLine("VEML6075 UV Sensor",config.VEML6075_Present)
print returnStatusLine("DustSensor",config.DustSensor_Present)
And I think that's all there is to it.... If you try it, and its not working, yell out - I might have missed a line somewhere....