ASCOM Temperature Sensor

Motivation

TEPMerHUM Stick.
TEPMerHUM Stick.

As the focus motor of my photo setup is driven by the Avalon Linear, my focuser does not have a temperature sensor.  The Esprit is by far not as bitchy as some other famous refractors in this range. So far I helped myself by initiating an autofocus run from time to time. Usually I initiated a focus run every 90 minutes which is more than necessary. In the second part of the night even less focus runs are adequate. Sequence Generator Pro (SGP) allows this way of controlling  autofocus runs in a quite easy way. My intension was to improve this using a temperature sensor.

SGP allows to evaluate other sensors for focusing as well. So my first idea was to trigger focus run by the temperature sensed by a TEMPerHUM stick. Acually SGP works with ASCOM devices. The TEMPerHUM stick is an exception, but it is not supported officially. Then happened, what had to happen: My stick operated with  APT but not with SGP. The BlueAstro USB weatherstation would be an ASCOM compatible solution, but it is not available due to the passing of Per Frejvall.

Thus I came to the conclusion that I had to design my own solution. Based on an Arduino the hardware part should not be a real issue, but developing the ASCOM driver was fully new for me.

Sensor Hardware

The sensor hardware consists of an Arduino Nano PCB and a DHT22 sensor for temperature and humidity. There are many sketches to be found dealing with that parts. I added an energy save function, which allows the Nano to sleep most of the time. The interrupt for awakening is triggered by the serial communication. This is bit unusual, as the first part of serial communication coming from the computer certainly will get lost in this scenario, but my drivers care for that case. My system seems to run stable without any issues.

DHT 22 Temperature Sensor.
DHT 22 Temperature Sensor.

The circuit is straightforward and very easy to realize.  One should be careful to match the pins with the pin numbers of the sketch. The sleep mode reduces the supply current which is drawn from the USB  connector. Removing the power LED from the PCB and introducing the sleep mode reduced the the current from 32 mA down to 12 mA. I think this is worth it for two reasons: Firstly in the field I only have limited energy available, secondly current produces heat and this compromises temperature measurements in a narrow compartment.

Experimental setup.
Experimental setup.

The photo shows my experimental setup where the DHT 22 is soldered directly upon the Nano. I used this system for developing the ASCOM code. The final arrangement fits in a 65 mm x 32 mm x 20 mm box. At one side the DHT 22 sits and the USB socket sits at the opposite side. Below is a gallery showing the final temperature sensor in its box.

Software

Software downloaded from this web site is provided ‚as is‘ without warranty of any kind, either express or implied.  You should know what you do. Any action you take upon the information on this website is strictly at your own risk.

ASCOM Telescope Driver

The ASCOM driver (version 2.0) is available to download here. Off course, the ASCOM Platform should be installed before this driver. I coded the driver based on a skeleton of an ASCOM Observing Conditions driver in VB. It runs successful at my office PC under Windows 10, at my telescope control notebook under Windows 7 and at a virtual machine running Windows 7, as well.

If somebody wants to compile an own version, I will share the source code. Please send me a message in this case.

Arduino Sketch

The sketch for the Arduino Nano is listed here. Just copy and paste it into your Arduino IDE.

#include <DHT.h>
#include <avr/sleep.h>

#define INT_PIN 2
/* INT_PIN muss mit Pin 0 über 470 Ohm verbunden sein. 	*/
/* Da Tx identisch mit Pin 0 ist, löst die serielle  	*/
/* Schnittstelle bei Aktivität den Interrupt aus.    	*/
#define DHT_PIN 7                                           
#define LED_PIN 13
#define DHTTYPE DHT22                                      

DHT		dht(DHT_PIN, DHTTYPE);
float 	humidity, temperature;

void setup() 
{
	Serial.begin(57600); Serial.flush();
	Serial.println("Starte ...");
	/* Pullup for INT_PIN       						*/
	pinMode(INT_PIN, INPUT);
	/* Arduino sleeps untils serial get actice.        	*/
	digitalWrite(INT_PIN, HIGH); 
	pinMode(LED_PIN, OUTPUT);
	dht.begin();
	delay(100);	
	DHT_messung(); /* to have valid data ready 			*/
	Serial.println("Init erfolgt ...");
	delay(100);
	}

void loop()
{
	/* switch off LED and sleep							*/
	digitalWrite(LED_PIN, LOW);
	enter_sleep();
	
	/* woke up                              */ 
	digitalWrite(LED_PIN, HIGH); 	// LED ON	
	DHT_messung(); 					// measure ..
	  
	String cmd;

  for (int i=0; i &amp;amp;amp;amp;lt;= 5000; i++){ 
	delay(1); 
	while (Serial.available() > 0) {
      		cmd = Serial.readStringUntil('#');
      		if (cmd == "TEM") {
			Serial.print(temperature); Serial.println('#');}
		if (cmd == "HUM") {
			Serial.print(humidity); Serial.println('#');}
		if (cmd == "DEW") {
			Serial.print(dewPointFast(temperature, humidity)); Serial.println('#'); }
	}
  }
}

void INT_PINisr(void)
/* ISR for INT_PIN 											*/
{
  /* Detach Interrupt, one time is enough for now. Lets		*/
  /* the serial communication run without any interrupts.	*/
  detachInterrupt(0);
}

void enter_sleep(void)
{
	attachInterrupt(0, INT_PINisr, LOW);
	/* put arduino to sleep 								*/
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	sleep_mode();
	sleep_disable(); 
}

float dewPointFast(double celsius, double humidity) 
/* 	caculate dew point, not the best method but easy	*/
/*	and good enough for our tasks						*/
{
	double	a 		= 17.271;
	double 	b 		= 237.7;
	double 	temp 	= (a * celsius) / (b + celsius) + log(humidity / 100);
	float 	Td 		= (b * temp) / (a - temp);
	return 	Td;
}

void DHT_messung() 
{
	humidity 	= dht.readHumidity();
	temperature = dht.readTemperature();
}