ANZAC Day
Go Back   IceInSpace > Equipment > ATM and DIY Projects
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Rate Thread
  #101  
Old 25-05-2020, 04:49 PM
peter_4059's Avatar
peter_4059 (Peter)
Big Scopes are Cool

peter_4059 is offline
 
Join Date: Jun 2007
Location: SE Tasmania
Posts: 4,532
Hi Rob,

Here's my Arduino sketch. Could probably be a bit tidier but it works .

I'll zip the VB code and put it on google drive for you. You might also need the excel spreadsheet to see how the calibration works and add your own data points.


//
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
#include "Adafruit_TSL2591.h"
#include "Adafruit_SHT31.h"
#include "DHT.h"

Adafruit_BMP085 bmp;
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
Adafruit_SHT31 sht31 = Adafruit_SHT31();

#define DHTPIN 12 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11

DHT dht(DHTPIN, DHTTYPE);

int LightSensorPin = A3; // select the input pin for LDR
float lsv = 0; // variable to store the value coming from the sensor

int RainSensorPin = A1; // select the input pin for Rain
float rsv = 0; // variable to store the rain sensor value

int WindSensorPin = A2; // select the input pin for Wind
float wsv = 0; // variable to store the wind sensor value

boolean debug = false;
uint16_t ir;
uint16_t full;
float IR;
float FULL;
float vis;
float lux;
float del;
float last;
float current = 10000;
float nightTh = 10;
float dayTh = 10000;
bool allowChange = true;
int readCount = 0;
String mode = "DAY";
int tslm=1;

char val; // data received from serial port
int ledPin = 13;
boolean ledState = LOW;
boolean contact = false;
int waitTime;
int delayTime = 0;
unsigned long startTime;
unsigned long finishTime;

void setup() {
pinMode(ledPin, OUTPUT); // set ledPin pin as output
Serial.begin(9600);

dht.begin();
mlx.begin();
bmp.begin();
tsl.begin();
sht31.begin();

// start with TSL sensor in DAY mode
tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light)
tsl.setTiming(TSL2591_INTEGRATIONTI ME_500MS);

establishContact(); // send an 'A' down the serial port until the PC responds
}

void loop() {
startTime=millis();

if (Serial.available() > 0){
val = Serial.read();
delayTime = val - 48;
}

if (delayTime==0){
ledState = LOW; // turn the LED off
contact = false;
digitalWrite(ledPin, ledState);
waitTime = 1000;
}
if (delayTime>0){
ledState = HIGH; // turn the LED on
contact = true;
digitalWrite(ledPin, ledState);
waitTime = 1000 * delayTime;
}

//perform the TSL light readings and gain control functions
last = current;
sensorRead(); // perform sensor read routine
// Serial.print(F("Mode: ")); Serial.print(mode); Serial.print(F(" "));
// Serial.print(F("ReadCount: ")); Serial.print(readCount); Serial.print(F(" "));
// Serial.print(F("AllowChange: ")); Serial.print(allowChange); Serial.print(F(" "));
// Serial.print(F("Last: ")); Serial.print(last); Serial.print(F(" "));
// Serial.print(F("Current: ")); Serial.println(current);

if((current < last) && (mode == "DAY")){
// getting darker and in Day mode - consider night mode
//Serial.println(F("running night mode routine"));
nightMode();
}

else if ((current >= last) && (mode == "NIGHT")){
// getting lighter and in Night mode - consider day mode
//Serial.println(F("running day mode routine"));
dayMode();
}
if(readCount > 6){
allowChange = true;
}

// read the other sensors

// Read humidity and temperature from the SHT31
float sh = sht31.readHumidity();
float st = sht31.readTemperature();

// Read humidity and temperature from the DHT
float h = dht.readHumidity();
float t = dht.readTemperature();

// Read ambinet and sky temperature from the MLX
float a = mlx.readAmbientTempC();
float s = mlx.readObjectTempC();

// Read barometric pressure at ambient temperature from BMP
float at = bmp.readTemperature();
float p = bmp.readPressure() / 100;

// read the value from the LDR light sensor
lsv = analogRead(LightSensorPin);

// read the value from the rain sensor
rsv = analogRead(RainSensorPin);

// read the value from the wind sensor
wsv = analogRead(WindSensorPin);

// random number to include in checksum
int rcs = int(random(0,99));

// checksum based on BMP pressure, DHT Humidity, Rain, Light, Vis and IR values
// int chksum = int(st)+int(t)+int(a)+int(at)+int(r sv)+int(wsv)+rcs;
int chksum = int(p)+int(IR)+int(vis)+int(tslm)+i nt(rsv)+int(wsv)+rcs;
if (contact==true) {

// set up print string for PC interface
String dataTrans = "V:";
dataTrans += String(st,1); // SHT31 ambient temp
dataTrans += String(':');
dataTrans += String(t,1); // DHT ambient temp
dataTrans += String(':');
dataTrans += String(a,1); // MLX ambient temp
dataTrans += String(':');
dataTrans += String(at,1); // BMP ambient temp
dataTrans += String(':');
dataTrans += String(p,0); // barometric pressure
dataTrans += String(':');
dataTrans += String(sh,1); // SHT31 humidity
dataTrans += String(':');
dataTrans += String(h,1); // DHT humidity
dataTrans += String(':');
dataTrans += String(s,1); // sky temperature
dataTrans += String(':');
dataTrans += String(lsv,0); // LDR coarse light sensor
dataTrans += String(':');
dataTrans += String(IR,0); // TSL light sensor IR
dataTrans += String(':');
dataTrans += String(vis,0); // TSL light sensor visible
dataTrans += String(':');
dataTrans += String(FULL,0); // TSL light sensor full
dataTrans += String(':');
dataTrans += String(lux,4); // TSL light sensor lux
dataTrans += String(':');
dataTrans += String(tslm); // TSL mode (0=night, 1=day)
dataTrans += String(':');
dataTrans += String(rsv,0); // rain sensor value
dataTrans += String(':');
dataTrans += String(wsv,0); // wind sensor value
dataTrans += String(':');
dataTrans += String(rcs); // random integer
dataTrans += String(':');
dataTrans += String(chksum); // checksum value
dataTrans += String(';');
//send the string to the PC
Serial.println(dataTrans); //
}

else {
Serial.println("A");
}
finishTime=millis();
int elapsedTime = int(finishTime - startTime);
if (waitTime > elapsedTime){
// Pause between measurements.
delay(waitTime - elapsedTime);
}

}

void establishContact() {
while (Serial.available() <= 0){
Serial.println("A");
delay(1000);
}
}


void sensorRead() {
// Advanced data read. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
uint32_t lum = tsl.getFullLuminosity();
uint16_t ir, full;
ir = lum >> 16;
full = lum & 0xFFFF;
lux = tsl.calculateLux(full, ir);
IR = float(ir);
FULL = float(full);
vis = full - ir;// TSL visible light
current = FULL;
//Serial.print(F("IR: ")); Serial.print(ir); Serial.print(F(" "));
//Serial.print(F("full: ")); Serial.print(full); Serial.print(F(" "));
//Serial.print(F("vis: ")); Serial.print(vis); Serial.print(F(" "));
//Serial.print(F("lux: ")); Serial.println(lux);
readCount = readCount + 1;
return;
}

void nightMode() {
if(debug) Serial.println(F("running night mode routine"));
if((current < nightTh) && (allowChange = true)){
if(debug) Serial.println(F("met criteria - change to night mode"));
// Serial.print(F("Mode: ")); Serial.print(mode); Serial.print(F(" "));
// Serial.print(F("Current: ")); Serial.print(current); Serial.print(F(" "));
// Serial.print(F("nightTh: ")); Serial.print(nightTh); Serial.print(F(" "));
// Serial.print(F("allow change: ")); Serial.println(allowChange);
tsl.setGain(TSL2591_GAIN_HIGH); // switch to night mode 428x gain
mode = "NIGHT";
tslm = 0;
allowChange = false; // switch allow change to false
readCount = 0;
return;
}
return;
}

void dayMode() {
if(debug) Serial.println(F("running day mode routine"));
if((current > dayTh) && (allowChange = true)){
if(debug) Serial.println(F("met criteria - change to day mode"));
// Serial.print(F("Mode: ")); Serial.print(mode); Serial.print(F(" "));
// Serial.print(F("Current: ")); Serial.print(current); Serial.print(F(" "));
// Serial.print(F("dayTh: ")); Serial.print(dayTh); Serial.print(F(" "));
// Serial.print(F("allow change: ")); Serial.println(allowChange);
tsl.setGain(TSL2591_GAIN_LOW); // switch to day mode 1x gain
mode = "DAY";
tslm = 1;
allowChange = false; // switch allow change to false
readCount = 0;
return;
}
return;
}
Reply With Quote
  #102  
Old 26-05-2020, 12:35 AM
turbo_pascale's Avatar
turbo_pascale (Rob)
Registered User

turbo_pascale is offline
 
Join Date: Apr 2006
Location: Melbourne, Australia
Posts: 478
Peter,

Did you end up using that hot-wire wind sensor? I hadn't included a wind sensor yet. I've a weather station setup that is running in to a raspberry pi and pushing data to a web server, but I haven't got around to being particularly clever with that yet in order to use it with this project.

http://weather.turbotalkstech.com
Reply With Quote
  #103  
Old 26-05-2020, 07:02 AM
peter_4059's Avatar
peter_4059 (Peter)
Big Scopes are Cool

peter_4059 is offline
 
Join Date: Jun 2007
Location: SE Tasmania
Posts: 4,532
No Rob - I'm using the Adafruit cup anemometer.

https://core-electronics.com.au/anem...xoChXcQAvD_BwE

It works fine for my purposes however if I was doing it all again I'd probably go for the hot wire sensor as it is a fraction of the cost, no moving parts and probably easier to install/incorporate in the project.

https://moderndevice.com/product/wind-sensor-rev-p/

Both options are a bit flimsy compared to the gold finger one Boltwood use however I haven't found a supplier of that type yet.
Reply With Quote
  #104  
Old 26-05-2020, 09:46 AM
turbo_pascale's Avatar
turbo_pascale (Rob)
Registered User

turbo_pascale is offline
 
Join Date: Apr 2006
Location: Melbourne, Australia
Posts: 478
Thanks Peter,

I got your link - I'll start going through it all and start to consume it!

Thanks for the sketch as well. 98% of it is the same as what I've already done of course, being the nature of the libraries!

I took the plunge and ordered one of the hot-wire wind sensors, although the shipping was ridiculously expensive. I'll let you know how it goes when it arrives.

I will no doubt have many questions! Again, I very much appreciate the effort you've put in to this.
Reply With Quote
  #105  
Old 26-05-2020, 01:05 PM
peter_4059's Avatar
peter_4059 (Peter)
Big Scopes are Cool

peter_4059 is offline
 
Join Date: Jun 2007
Location: SE Tasmania
Posts: 4,532
No problem Rob. Hope you enjoy it and if you ever work out how to write an Ascom driver, there are a number of parameters that the kit measures that the generic Boltwood driver does not pick up.
Reply With Quote
  #106  
Old 26-05-2020, 01:12 PM
turbo_pascale's Avatar
turbo_pascale (Rob)
Registered User

turbo_pascale is offline
 
Join Date: Apr 2006
Location: Melbourne, Australia
Posts: 478
Peter,

That's my "one day wish" to see if I can do that with ASCOM.

I'm hoping to get the template for one for the ObservingConditions driver and see if I can modify it, but, I need to get the sensor kit setup first!

One overwhelming project at a time though!!
Reply With Quote
  #107  
Old 26-05-2020, 02:32 PM
peter_4059's Avatar
peter_4059 (Peter)
Big Scopes are Cool

peter_4059 is offline
 
Join Date: Jun 2007
Location: SE Tasmania
Posts: 4,532
The source code is available for the observing conditions driver - I just cant figure it out!
Reply With Quote
  #108  
Old 28-05-2020, 07:34 PM
RobF's Avatar
RobF (Rob)
Mostly harmless...

RobF is offline
 
Join Date: Jul 2008
Location: Brisbane, Australia
Posts: 5,716
What does the VB code do Peter? Is that for a separate GUI to the generic ASCOM driver interface?
Reply With Quote
  #109  
Old 28-05-2020, 07:50 PM
peter_4059's Avatar
peter_4059 (Peter)
Big Scopes are Cool

peter_4059 is offline
 
Join Date: Jun 2007
Location: SE Tasmania
Posts: 4,532
Quote:
Originally Posted by RobF View Post
What does the VB code do Peter? Is that for a separate GUI to the generic ASCOM driver interface?
The VB code takes the raw sensor data string that the Arduino sends down the serial interface via the computer com port (the sketch I posted above makes this happen) and manipulates that into a set of data to be presented on the PC including a prediction of cloud cover based on ambient temperature, sky temperature and relative humidity.

A lot of the code is about the PC GUI that I've shown in previous screenshots in this thread. All up it is about 1000 lines of visual basic code. It also generates a text file that the generic Ascom driver reads to create an interface to image control software like SGP.
Reply With Quote
  #110  
Old 28-05-2020, 08:56 PM
RobF's Avatar
RobF (Rob)
Mostly harmless...

RobF is offline
 
Join Date: Jul 2008
Location: Brisbane, Australia
Posts: 5,716
Quote:
Originally Posted by peter_4059 View Post
The VB code takes the raw sensor data string that the Arduino sends down the serial interface via the computer com port (the sketch I posted above makes this happen) and manipulates that into a set of data to be presented on the PC including a prediction of cloud cover based on ambient temperature, sky temperature and relative humidity.

A lot of the code is about the PC GUI that I've shown in previous screenshots in this thread. All up it is about 1000 lines of visual basic code. It also generates a text file that the generic Ascom driver reads to create an interface to image control software like SGP.
Ahhh. Thanks for explaining. Thought the arduino code might have been larger, but sounds like VB is where most of the magic is happening.
Reply With Quote
  #111  
Old 28-05-2020, 09:06 PM
peter_4059's Avatar
peter_4059 (Peter)
Big Scopes are Cool

peter_4059 is offline
 
Join Date: Jun 2007
Location: SE Tasmania
Posts: 4,532
Quote:
Originally Posted by RobF View Post
Ahhh. Thanks for explaining. Thought the arduino code might have been larger, but sounds like VB is where most of the magic is happening.
Rob,

In my original attempts I performed all of the cloud calcs in the Arduino however as the project developed I made a decision to use the Arduino to just export the raw sensor data and do the heavy lifting in the computer in VB as this was easier to manage as I started changing stuff and making things more complicated.
Reply With Quote
  #112  
Old 29-05-2020, 01:34 PM
stephen2615 (Stephen)
Registered User

stephen2615 is offline
 
Join Date: Feb 2011
Location: Canberra, Australia
Posts: 70
I just found this thread and I am experimenting with a similar concept. I have a Raspberry Pi collecting similar data. I hope to send the data to my NUC (via a socket or even serial if I can be bothered) and then use it to provide some extra ASCOM data (I only have temp and humidity from my Pegasus Pocket Powerbox). I also want to figure out how to send me an alert if cloud cover comes in but that is not really important as I have a good idea of any cloud. Fog is the problem here in winter.

I am very interested in how you make a prediction of cloud cover based on ambient temperature, sky temperature and relative humidity.

Regards

Stephen
Reply With Quote
  #113  
Old 29-05-2020, 03:19 PM
peter_4059's Avatar
peter_4059 (Peter)
Big Scopes are Cool

peter_4059 is offline
 
Join Date: Jun 2007
Location: SE Tasmania
Posts: 4,532
Hi Stephen,

All of the commercial cloud detectors measure the ambient and sky temperature. When the sky is clear, the sky temperature is about 20 degC below the ambient temperature. When there is cloud cover, the sky temperature approaches the ambient temperature (ie the delta T reduces). I initially set up my Arduino project on this basis however I noticed the delta T vs cloud cover relationship wasn't constant such that the model was predicting cloud when it was actually clear. I went searching for any modelling that had been done and found a paper that compared models used for prediction of sky temperatures. Some of those models use cloud cover in the prediction and some use water partial pressure (which is a function of relative humidity). Since I'm directly measuring the sky temperature but want to predict the cloud cover, I rearranged the equations in a couple of those models and that is what my cloud prediction model uses.
Reply With Quote
  #114  
Old 29-05-2020, 04:23 PM
troypiggo's Avatar
troypiggo (Troy)
Bust Duster

troypiggo is offline
 
Join Date: Nov 2008
Location: Brisbane, Australia
Posts: 4,846
Check out the big brain on Peter
Attached Thumbnails
Click for full-size image (438awy.jpg)
46.1 KB15 views
Reply With Quote
  #115  
Old 29-05-2020, 04:35 PM
peter_4059's Avatar
peter_4059 (Peter)
Big Scopes are Cool

peter_4059 is offline
 
Join Date: Jun 2007
Location: SE Tasmania
Posts: 4,532
Quote:
Originally Posted by troypiggo View Post
Check out the big brain on Peter
Use it or you'll lose it
Reply With Quote
  #116  
Old 29-05-2020, 08:05 PM
stephen2615 (Stephen)
Registered User

stephen2615 is offline
 
Join Date: Feb 2011
Location: Canberra, Australia
Posts: 70
Hi Peter,

What sort of model did you come up with if you don't mind me asking? Is there just some sort of a correlation between the ambient ground level and sky temp with the relative humidity and then trying to forecast the lifting condensation level or something along those lines?

I don't know what time the radiation fog sets in here but basically in winter, the humidity is 99% from about 30 mins past sunset to sometime the next morning or on a bad day, sometimes early afternoon.

I have never been convinced of a (cheaper) sensor's ability to accurately measure relative humidity compared to the web bulb method that is used to get perfect measurements. Those couple of percentage points can make all the difference.

Cheers

Stephen
Reply With Quote
  #117  
Old 29-05-2020, 09:36 PM
peter_4059's Avatar
peter_4059 (Peter)
Big Scopes are Cool

peter_4059 is offline
 
Join Date: Jun 2007
Location: SE Tasmania
Posts: 4,532
Stephen,

The models I'm using work on emissivity calculations. One model predicts the clear sky emissivity and the other one back calculates the cloud cover based on the observation of actual emissivity (calculated from ambient and sky temperature measurement). I've used the form of equations from literature but fitted the coefficients of the literature models to my local observations.

I also heard the DHT humidity sensors can be a bit hit and miss so ended up changing to an Adafruit SHT31 to get a more accurate humidity measurement.

https://www.adafruit.com/product/2857
Reply With Quote
  #118  
Old 30-05-2020, 01:00 PM
stephen2615 (Stephen)
Registered User

stephen2615 is offline
 
Join Date: Feb 2011
Location: Canberra, Australia
Posts: 70
Hi Peter,

Thanks for the info.

That sensor looks interesting if you believe the humidity hype. I might give it a go.

I have been mulling over throwing a light sensor into my range of sensors and seeing what difference it would make. Fog (in my situation) would have to have a different light value than a clear or cloudy sky because the clouds are much higher than fog. Just so many things to play with.

Cheers

Stephen
Reply With Quote
  #119  
Old 30-05-2020, 01:46 PM
turbo_pascale's Avatar
turbo_pascale (Rob)
Registered User

turbo_pascale is offline
 
Join Date: Apr 2006
Location: Melbourne, Australia
Posts: 478
I hadn't seen this before, but the author of the myFocuser arduino project also has a Sky Quality Meter project which uses all the same components as described here in Peter's project.

His code for the Cloud Sensor side of things is pretty rudimentary compared with Peter's.

However, the project as a whole adds a few possibilities in the ASCOM driver side of things which may make it a bit easier to use than pushing files around.

https://sourceforge.net/projects/ard...yqualitymeter/
Reply With Quote
  #120  
Old 15-06-2020, 04:35 PM
stephen2615 (Stephen)
Registered User

stephen2615 is offline
 
Join Date: Feb 2011
Location: Canberra, Australia
Posts: 70
Hi Peter,

I just "discovered" ASCOM Alpaca. The mind boggles what can be exported from my RPi to my imaging computer. Have you looked at it?

Cheers

Stephen
Reply With Quote
Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +10. The time is now 04:48 PM.

Powered by vBulletin Version 3.8.7 | Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Advertisement
Testar
Advertisement
Bintel
Advertisement