IMT3 Environmental Monitoring Pt.1

IMT3 Environmental Monitoring Pt.1
Bob Trevan – Aug2019

When Dave, Mark and I first started planning what equipment we were going to install in IMT3 we started with a block diagram of what we thought we were going to install so we could determine the number of USB ports we would need and the power requirements. This soon morphed into much more as we started adding kit to the project.

Although the Observatory is install in the UK and not Spain as was originally planned, we decided we would still need a fair bit of monitoring to allow remote sensing of the local conditions. In particular making sure it was safe to open the shutter for a remote observing session

During AstroFest in Feb 2019 we bought a HiTechAstro Deluxe Weather Station which can be used as an ASCOM safety device to autonomously close the Dome Shutter if rain or cloud is detected. Although we were lead to believe it would directly interface with the Pulsar Dome Controller, this was not the case and required a simple interface consisting of a SPST Relay to control the shutter. Once the Relay is picked the shutter closes and will stay closed until the operator manually resets the state of the relay via the weather station software. The software has a number of options to configure to determine when to close the shutter

Although the Shutter itself has a battery pack that has sufficient capacity to close the shutter in the event of a power outage we decided to add an APC UPS with PowerChute software so provide AC power resilience to critical components. The shutter battery is wirelessly charged when the dome is parked at the end of each observing session.

In addition to the Cloud and Rain sensor, we also have a Sky Quality Meter and All Sky camera mounted on the same pole. The cable run to the pole from the panel inside the dome to which we were mounting various components … MAC Mini, 10-port USB HUB, Power Bricks, etc … is about 10m. The cabling provided with the Weather Station was somewhat shorter than this which meant having to extend it with the challenges of making the external connections water tight.

The HiTechAstro Wx Stn is also a Cloud Sensor utilizing an IR sensor to measure the Sky Temperature and a Dallas DS18B20 to measure Ambient Temperature. The waterproof probe is attached to the underside of the mounting bracket.

For monitoring the Dome Internal conditions I started looking at what we could achieve using an Arduino (*1) with various sensors. Currently we have two Arduinos installed, the first utilizes an Arduino UNO R3 with a Bosch BME280 (*2) Temperature, Humidity and Pressure Sensor and a pair of Dallas DS18B20 (*3) temperature probes for monitoring the internal temperatures of the enclosures housing the MAC Mini and Intel NUC (*4) (more on the NUC later). The current version of code running on this Arduino is provided at the end of this part of the blog.

A second Arduino has a 4-relay shield attached. The relays are used to control two 380 lumens LED lights inside the dome and after modifying a couple of short USB extension leads, breaking into the +5v line, the remaining 2 relays are used to reset the All Sky Camera and HiTechAstro Deluxe Wx Stn, when the need arises (which is all too frequently). This Arduino is programmed to run Standard Firmata code allowing Node-RED to communicate via the serial port and control the relays.

*1   Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs – light on a sensor, a finger on a button, or a Twitter message – and turn it into an output – activating a motor, turning on an LED, publishing something online.

The Arduino integrated development environment (IDE) is a cross-platform application (for Windows, macOS, Linux) that is written in the programming language Java, C, C++. It is used to write and upload programs to Arduino compatible boards. User-written code only requires two basic functions, for starting the sketch and the main program loop. For more info see https://en.wikipedia.org/wiki/Arduino_IDE

*2   Bosch BME280
The BME280 is an integrated environmental sensor developed specifically for mobile applications where size and low power consumption are key design constraints. The unit combines individual high linearity, high accuracy sensors for pressure, humidity and temperature in an 8-pin metal-lid 2.5 x 2.5 x 0.93 mm³ LGA package, designed for low current consumption (3.6 μA @1Hz), long term stability and high EMC robustness.

*3   Dallas DS18B20
The DS18B20-PAR digital thermometer provides 9 to 12–bit centigrade temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20-PAR communicates over a 1-Wire bus, which by definition requires only one data line (and ground) for communication with a central microprocessor. It has an operating temperature range of –55°C to +100°C and is accurate to ±0.5°C over a range of –10°C to +85°C.

*4   Next Unit of Computing (NUC) is a line of small-form-factor barebone computer kits designed by Intel. The NUC motherboard measures 4 × 4 inches (10.16 × 10.16 cm)

The Bosch BME280 Sensor uses the I2C bus and the Dallas DS18B20 probes use a One-Wire interface. Each of the DS18B20 has a unique internal 64-bit address created during the manufacturing process, so you can just keep adding as many as you need with relative ease.

Currently, every 20 seconds, the Arduino spits out 7 values separated by commas and terminated with a line feed, these are:

  1. DS18B20 Ext sensor Temperatue in °C
  2. DS18B20 Ext sensor Temperature in °F
  3. DS18B20 Int sensor Temperature in °C
  4. DS18B20 Int sensor Temperature in °F
  5. BME280 sensor Temperature in °C
  6. BME280 sensor Humidity in %
  7. BME280 sensor Pressure in mPa

e.g. 27.0000,80.6000,26.0000,78.8000,28.53,43.53,1008.28

Mark also donated a HiTechAstro Hub to the project which is used to control DC power to the Cameras, Focuser, Filter Wheels and potentially Dew Heaters, but with three rigs mounted on the SB Paramount ME-II we were quickly using all available USB Ports and Switched DC power ports available.

After several ‘Hangs’ of the NUC due the to the software packages tested with the All Sky Camera, we added a MAC mini to run the environment applications, leaving the Intel NUC to run the Main Applications to control the mount and Cameras. The Sky X, Sequence Generator Pro etc…

So we now have a number of PC / MAC applications, controlling and displaying various functions of IMT3. But how do we display the Arduino data ?

Working for IBM, Dave had been exposed to Node-RED. Originally developed by IBM, Node-RED is a flow based development tool for visual programming for wiring together hardware devices, APIs and online services as part of the Internet of Things.

Node-RED provides a web browser-based flow editor, which can be used to create Javascript fuctions. The runtime is built on Node.js. The flows created in Node-RED are stored using JSON. Since version 0.14 MQTT nodes can make properly configured TLS connections.

In 2016, IBM contributed Node-RED as an open source JS Foundation project.

One of the Node-RED projects is a dashboard UI for Node-RED, and this is how the Arduino sensor data is displayed, along with the flow that controls the 4 relays on the Arduino Relay Shield.

We have a new vocabulary to learn; IoT, MQTT, node.js, Node-RED, JSON, Arduino, Sketch, Flow and new languages to learn C, C++, Javascript and we haven’t even mentioned the BBC MicroBit or Raspbery Pi and Python 🙂

I’ll describe the Node-RED flows I currently have working and the Dashboard in Pt. 2.

Arduino Code:

/********************************************************************
* Arduino code used for monitoring the Internal Ambient Temperature,
* Humidity and Air Pressure of IMT3 Observatory using a Bosch BME280 sensor
* and two Dallas DS18B20 temperature probes to measure the temperatures of
* the MAC Mini and Intel NUC enclosures.
*
* I have commented out alot of the lines used during development, but left
* them in to help comment the code.
*
* Currently, every 20 seconds, the Arduino spits out 7 values separated by
* commas and terminated with a line feed, these are:
*
* DS18B20 Ext sensor Temperatue in °C
* DS18B20 Ext sensor Temperature in °F
* DS18B20 Int sensor Temperature in °C
* DS18B20 Int sensor Temperature in °F
*
* BME280 sensor Temperature in °C
* BME280 sensor Humidity in %
* BME280 sensor Pressure in mPa
*
* e.g. 27.0000,80.6000,26.0000,78.8000,28.53,43.53,1008.28
*
* The above will be displayed as Gauges on a Node-RED Dashboard.
*
* Bob Trevan August 2019
*******************************************************************/
/******************************************************************
This is a library for the BME280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME280 Breakout
----> http://www.adafruit.com/products/2650
 These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface. The device's I2C address is either 0x76 or 0x77.
 Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing products from Adafruit! 
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
*******************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

Adafruit_BME280 bme; // I2C
char buffer[60];
// Onewire Reference and assign it to pin 5 on the Arduino
OneWire oneWire(5);
// declare as sensor reference by passing oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// declare the device addresses
//Device 1: 0x28, 0x41, 0x0F, 0x84, 0x1F, 0x13, 0x01, 0x16
//Device 2: 0x28, 0x89, 0x25, 0x6E, 0x1F, 0x13, 0x01, 0x3F

//Device 3: 0x28, 0xAD, 0x43, 0xE2, 0x1B, 0x13, 0x01, 0x8D
//Device 4: 0x28, 0x0B, 0xA9, 0x63, 0x1F, 0x13, 0x01, 0xCC

//Device 5: 0x28, 0x52, 0xDA, 0x71, 0x1F, 0x13, 0x01, 0x68
//Device 6: 0x28, 0xAA, 0xBD, 0x68, 0x3C, 0x14, 0x01, 0x4E

// Select the pair of sensor used with this Arduino, these addresses have previously been read with a separate piece of Arduino code.
DeviceAddress ExtSensor = {0x28, 0xAA, 0xBD, 0x68, 0x3C, 0x14, 0x01, 0x4E};
DeviceAddress IntSensor = {0x28, 0x52, 0xDA, 0x71, 0x1F, 0x13, 0x01, 0x68};

// Variables to hold the temperatures
float ExtC; // originally had one sensor hanging out of my study window
float IntC; // and a second sensor by my desk.

void setup() {
Serial.begin(9600);

// Serial.println(F("BME280 test"));
bool status;
status = bme.begin(0x76); // I2C Address
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}

// Serial.println("-- Default Test --");

Serial.println();

// set the resolution to 9 bit - Valid values are 9, 10, or 11 bit.
sensors.setResolution(ExtSensor, 9);

// confirm that we set that resolution by asking the DS18B20 to repeat it back
//Serial.print("Exterior Sensor Resolution: ");
//Serial.println(sensors.getResolution(ExtSensor), DEC);
//Serial.println();
// set the resolution to 9 bit - Valid values are 9, 10, or 11 bit.

sensors.setResolution(IntSensor, 9);

// confirm that we set that resolution by asking the DS18B20 to repeat it back
//Serial.print("Interior Sensor Resolution: ");
//Serial.println(sensors.getResolution(IntSensor), DEC);
//Serial.println();
}

void loop() {
// Tell the Ext sensor to Measure and Remember the Temperature it Measured
sensors.requestTemperaturesByAddress(ExtSensor); // Send the command to get temperatures
// Get the temperature that you told the sensor to measure

ExtC = sensors.getTempC(ExtSensor);

//Serial.print("Exterior Sensor: ");
//Serial.print("Temp C: ");

Serial.print(ExtC,4); // The four just increases the resolution that is printed
Serial.print(",");

//Serial.print(" Temp F: ");
// The Dallas Temperature Control Libray has a conversion function... we'll use it

Serial.print(DallasTemperature::toFahrenheit(ExtC),4);
Serial.print(",");

// Tell the INT sensor to Measure and Remember the Temperature it Measured sensors.requestTemperaturesByAddress(IntSensor); // Send the command to get temperatures
// Get the temperature that you told the sensor to measure

IntC = sensors.getTempC(IntSensor);

//Serial.print("Interior Sensor: ");
//Serial.print("Temp C: ");

Serial.print(IntC,4); // The four just increases the resolution that is printed
Serial.print(",");

//Serial.print(" Temp F: ");
// The Dallas Temperature Control Libray has a conversion function... we'll use it

Serial.print(DallasTemperature::toFahrenheit(IntC),4);
Serial.print(",");
//Serial.println("\n");
printTemp();
printHum();
printPa();
delay(20000);
}

void printTemp() {
dtostrf(getTemp(),1,2,buffer);

// Serial.print("Temperature = ");

Serial.print(buffer);
Serial.print(",");

// Serial.println(" *C");
}

void printHum() {
dtostrf(getHum(),1,2,buffer);

// Serial.print("Humidity = ");

Serial.print(buffer);
Serial.print(",");

// Serial.println(" %");
}

void printPa() {
dtostrf(getPa(),1,2,buffer);

// Serial.print("Pressure = ");

Serial.println(buffer);

// Serial.println(" hPa");
}

double getTemp(void) {
double t;
t = bme.readTemperature();
return (t);
}

double getHum(void) {
double h;
h = bme.readHumidity();
return (h);
}

double getPa(void) {
double p;
p = (bme.readPressure() / 100.0F);
return (p);
}