Sky Quality Meter

Triggered by a discussion on Cloudy Nights, I decided to dive in and make my own SQM. As an additional feature, I have included also sensors for ambient temperature, relative humidity and air pressure. The device also needed a Unihedron SQM-LU compatible interface on USB, so that it can be connected to my INDI box.

SQM Block diagram

The SQM is based on an Arduino NANO, with an ATMega 328P processor. This processor does not have a lot of memory (2kB of RAM), but still runs at 16MHz. The NANO also features a serial interface accessible over USB, which can be used to implement the interface to INDI and at the same time to power the device.
The sensors and the display are all connected via I2C, which makes integration very easy. The SCL and SDA lines of this bus need pullups since the NANO does not provide those. I have used 22k resistors. Also, to enable debugging through the onewire interface I have removed the reset circuit of the NANO. Therefore an external 33k pullup is required on the reset pin as well.

Sensors

The SQM contains three sensors:

  • TSL2591, an AMS light sensor with a very high dynamic range;
  • SHT31-D, a Sensirion humidity and temperature sensor;
  • BMP280, a Bosch air pressure sensor and secondary temperature sensor.
  
These sensors are all available as breakout boards from Adafruit, and can be ordered through various channels. Also the Arduino NANO can be ordered from many sources.
Datasheets can be found on the internet as well, but I have included them in the package for download.

Display

The display is a 128x64 pixel, 0.96" diagonal, white OLED variant, based on the SH1106 driver chip. This chip is similar to the DSS1306 you see more often and it has almost the same command set. You can also find such displays in 1.3" size, just make sure it has an I2C interface. The datasheet is fairly crappy, but after some experimentation you will find out what works.

Software

Adafruit also delivers a set of drivers, for sensors as well as display, to be used in an Arduino sketch. However, I have chosen to create my own set of drivers which better match my realtime OS, Juggler. As a build environment I do not use Arduino, but directly Atmel Studio (7.0). This allows to develop your own execution environment, which I needed in order to use the Juggler multi threading.
You need to download/install Atmel Studio from the MicroChip website. There are some tutorials/instructables on the web which may help if you don't succeed. Key is to install the right tool to enable use of the bootloader through USB. I have purchased an AtAtmel ICD basic module to also be able to debug my code. For just program loading this ICD is not required though.

The preliminary sources can be found in this archive: SQM - 0v1.zip

The software contains four tasks:

  • Sensor, every second this task polls the sensors and calculates the values of the parameters.
  • Display, every two seconds this task updates the display memory with whatever needs to be shown and purges to the SH1106.
  • Monitor, this task waits for input on the serial port and handles that accordingly.
  • Idle, this is the lowest priority task, and endless loop in the main() function.
Everything is fully event driven, meaning that tasks are usually waiting on an event to be signalled. This is caused by timeouts or data from an interface, both initiated from interrupt service routines.
The display thread writes into the display buffer, which contains one bit for each pixel. This buffer therefore is 1kByte in size, and takes half of the available RAM memory. To save as much RAM as possible, all fonts and fixed strings are stored in Flash, aka program memory, of which there is a generous 128kWord.

Prototype

A prototype serving to support software development has been made with a breadboard. In the breadboard you can see the components as in the block diagram, Arduino and display, while the three sensors are connected by wires in the top. The Atmel ICD can be connected to the 6-pin ICD interface on the left. The USB interface for power and control is on the right. The display shows air temperature, dewpoint temperature, relative humidity and air pressure in small font. At the bottom of the dislplay the sky quality measurement in magnitude per square arcsecond is shown in large font. The value still needs to be calibrated.
Possibly the display will be made switchable, by means of a toggling push-button.
SQM Breadboard

Download

When the final version has been qualified, the software and datasheets will be downloadable from here.