Jump to content

Banner.jpg.b89429c566825f6ab32bcafbada449c9.jpg

Arduino Sky Quality Meter - working!


Corpze

Recommended Posts

The above post was delayed by over an hour due to a power cut here :(  My offer still applies I guess we should arrange by PM.  Drat the power's gone off again :(  Guess this will go when it comes back on...

Link to comment
Share on other sites

  • Replies 119
  • Created
  • Last Reply

I've the code for the last SQM I made (fitted with a GPS receiver and sits on the top of my car). It's written for a PIC, but might be useful for someone writing for Arduino.
I'm sure it could be optimised, but it seems to work fine.

#define TSL237 PIN_B0;int16 timermsb=0;int16 timermsbbuf=0;int16 timerlsbbuf=0;int16 i;int8 send=0;int8 bytes[5];int8 mult;#INT_TIMER0void  TIMER0_isr(void){  //set_timer0(0);  timermsb++;}#INT_RDA HIGHvoid  RDA_isr(void){	int8 in;	in=getc(PORT1);	if(in=='S'){		if(send==1){ //ok to send			fputc(bytes[0], PORT1);			fputc(bytes[1], PORT1);			fputc(bytes[2], PORT1);			fputc(bytes[3], PORT1);			fputc(bytes[4], PORT1);		}else{ //not ok, buffer still writing			fputc(255, PORT1);			fputc(255, PORT1);			fputc(255, PORT1);			fputc(255, PORT1);			fputc(255, PORT1);		}	}}void main(){      	setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);//333ns resolution, 21.8 ms overflow	enable_interrupts(INT_TIMER0);	enable_interrupts(INT_RDA);	enable_interrupts(GLOBAL);	while(1){					restart_wdt();		enable_interrupts(INT_TIMER0);		while(input(TSL237)); //wait for falling edge        		while(!input(TSL237));//wait for rising edge		set_timer0(0);		timermsb=0;		while(input(TSL237));		while(!input(TSL237));		timermsbbuf=timermsb;		timerlsbbuf=get_timer0();		mult=1;				if(timermsbbuf==0){ //short period, repeat a few times (improves resolution in brighter conditions)			while(input(TSL237));			while(!input(TSL237));			set_timer0(0);			timermsbbuf=0;			for(i=0; i<100; i++){				while(input(TSL237));				while(!input(TSL237));				mult++;				if(timermsb>50){break;}			}			timermsbbuf=timermsb;			timerlsbbuf=get_timer0();           		}		disable_interrupts(INT_TIMER0);		send=0;		bytes[0]=mult;		bytes[1]=(timermsbbuf>>8) & 0xFF;		bytes[2]=timermsbbuf & 0xFF;		bytes[3]=(timerlsbbuf>>8) & 0xFF;		bytes[4]=timerlsbbuf & 0xFF;		send=1;	}}
Link to comment
Share on other sites

ok so we have the arduino, the sensor, the uv/ir cut glass, just need a box cables, cap and lens.   would this work for a lens?

was thinking for a box this : http://www.ebay.co.uk/itm/Arduino-Enclosure-Case-Box-UNO-MEGA-R3-Ethernet-Shield-many-colours-/181418044847?pt=UK_BOI_Electrical_Components_Supplies_ET&var=&hash=item2a3d5badaf

as i want to eventually put an ethernet sheild to output to an online weatherstation eventually.

Link to comment
Share on other sites

Hello guys

so im going to be buying the sensor on friday (2 days from now) if any one would like to go in shares send me a pm with how many. 

http://uk.mouser.com/ProductDetail/ams/TSL237S-LF/?qs=sGAEpiMZZMuhmhJ32%2fprP004vccwnQtD is the sensor. please make sure you check that it is the correct one as i cant be held if its not. 

also just going to the previous post would http://www.ebay.co.uk/itm/16mm-CCTV-Board-Lens-for-CCTV-Cameras-Security-Cameras-/121342651755?pt=UK_CCTV&hash=item1c4095ed6b work as a lens?  (i forgot to post it above)

Link to comment
Share on other sites

I have some lenses if anyones interested, I had to buy a bag of 20. Happy to give a few away

Hi OneEyedsam,

I've seen your offer but I'm in Portugal. Is there any chance to obtain one from you by mail?

I'm thinking in build the SQM with arduino.

Thank you

Jose Fernandes

Link to comment
Share on other sites

Happy to post a couple if you pay postage, but to be honest, it's probably easier and cheaper to buy locally

Thank you very much for your reply, i'll try to obtain them locally.

Regards

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...
  • 5 months later...

Couldn't resist joining in this noble venture! Still at the uber-prototype stage

but a few observations and measurements... which might help someone? :)

To make the postage (vaguely) worthwhile, I bought three TSL237s from:

http://uk.mouser.com/ProductDetail/ams/TSL237SM-LF/?qs=sGAEpiMZZMsyU%2fnwJUBBymzArwXg1g6S

Since they were in stock, I bought the surface mounted variety. Same spec.

- The pins slightly shorter and spaced slightly less than 0.1", but whatever! :p

So, ONE of the above was duly soldered to a small square of Veroboard...

I decide to give Arduino lib routine: "FreqCount" a whirl (see Per above etc.) 

Doiwnloaded from: https://www.pjrc.com/teensy/td_libs_FreqCount.html

The basic functionality demonstrated by:

#include <FreqCount.h>#include <Math.h>void setup() {  Serial.begin(9600);  FreqCount.begin(1000); // Sampling period (ms)}void loop() {  if(FreqCount.available()) {    unsigned long count = FreqCount.read();    Serial.println(count); // Number of Counts!  }}

Just connect output of TL237 to Pin 5 of the Arduino and it WORKED!  :cool:

(With short leads, it didn't even have a 0.1 micro farad decoupling cap) 

I initialised the sampling period at 1000 (ms) for a start. First observations.

1. With 16MHz Arduino UNO R3 it gave a count around 60,000 on my desk

    (Ergo a frequency of 60kHz!) 

2. If I shone a BRIGHT LED light on the sensor it maxed out at 540kHz.

    (With this setup, count rate saturates, but the code doesn't bomb!) :)

3. The minimum frequency is "pretty low" (less than 1Hz)  

    so clearly a practical App needed a little more thought...

To simulate dark skies, I covered the sensor with a small lens cap and

covered the whole Arduino setup with a black plastic microwave tray! :p

To try to get a bit more accuracy at low count rate, I increased the

value of the FreqCount.begin(ms) parameter. It seemed to get "good"

(same) results for 10000 (10 sec) etc. but went "weird" above 60 sec?

I found value of 30000 (30 sec) worked and about the most useful?  ;)

A reasonably consistent value (Freq ~10Hz) at typical sky brightness.

NSec: 30 Count:292 Freq: 9.73 Msqm 19.53 Nelm: 5.17 

(Hopefully this will be about right for my approximately Mag +5 skies!)

NO PRIZES for code! I just arbitrarily used constant A = 22.0 above.

So, in the spirit of sometime Fortran Programmers of my vintage:  :D

/************************************** Sqm - Prototype Sky Quality Meter! **************************************/#include <FreqCount.h>#include <Math.h>float Msqm;float Nelm;float freq;const int nsec = 30;const float A = 22.0; void setup() {  Serial.begin(9600);  FreqCount.begin(nsec * 1000);}void loop() {  if(FreqCount.available()) {    unsigned long count = FreqCount.read();    freq = float(count) / float(nsec);    Msqm = A - 2.5 * log10 (freq);    Nelm = 7.93 - 5.0*log10((pow(10,(4.316 - (Msqm / 5.0))) + 1));    Serial.print("N Sec: ");    Serial.print(nsec);        Serial.print(" Count: ");    Serial.print(count);    Serial.print(" Freq: ");    Serial.print(freq);      Serial.print (" Msqm: ");    Serial.print(Msqm);    Serial.print (" Nelm: ");    Serial.println(Nelm);  }}

Aside: I hope to improve on the "Hardware" too! I intend to try a miniature 

M12 CCTV camera lens of about f=3.5mm. Should give about 20 deg field

across the 1mm sensor? Might usefully increase count rates? Who knows!

Some useful bits and bobs available at: http://www.stockoptics.com/

Have Fun.  :)

Link to comment
Share on other sites

This is certainly something on my future project list but still a good way off.  I shall want it when I've completed my ROR automation.   Everything seems to take such a long time these days! :eek:  I already have the sensor (somwewhere :D)

Link to comment
Share on other sites

This is certainly something on my future project list but still a good way off.  I shall want it when I've completed my ROR automation.   Everything seems to take such a long time these days! :eek:  I already have the sensor (somwewhere :D)

Well, there are other things I could do (spend on) ... replacing... upgrading. :o

But something NEW (relatively simple!) Impetus... "Desiderata" and all that? :D

Link to comment
Share on other sites

I've made some progress now, the light sensing part seems to work pretty well. I've got a serial interface so I can send it commands, at the moment limited to sending a calibration adjustments (going to calibrate with a friends unihedron SQM)

I also have mobile phone module and thinking of having it send me text messages when the sq reaches a certain threshold. I have it sending me fixed texts at the moment, I just need to integrate the two projects/code bases. Will probably get it to take text message commands , eg for setting the threshold value.

All prototyped on a breadboard at the moment. I'm a software developer not a sparky, so it's been a fun learning experience, well it's been cloudy recently !!

Link to comment
Share on other sites

  • 8 months later...

Hello,

just finished my SQM (in fact - have new name SLM = Sky Luminance Meter - to not mess with original SQM from Unihedron :) )

- 16mm lens + UV/IR-cut filter

- LCD with backlight and contrast regulation

- USB - for program and data transfer to PC (working with APT as original)

- Real Time Clock with batery backup (CR3025) and EEPROM for storage.

- temperature and humidity.

Powered by 9V or UPS when connected.

Calibrated to original SQM.

Software is beta version - will be upgraded soon (more features planned)

On pictures - few units with engraved logo of Polish Astro Forum for members . More available.... (PM or e-mail me)

Marek

post-43596-0-65426200-1448346847.jpg

post-43596-0-51530500-1448346849.jpg

post-43596-0-54459700-1448346850.jpg

post-43596-0-33909000-1448346851.jpg

post-43596-0-23203800-1448346852.jpg

Link to comment
Share on other sites

  • 4 months later...

Just shows how long it takes me to finish some projects? :D

Herewith, the now boxed version of my SQM:
(Stuck to backing board for observatory use!)

SQM.JPG

Will resist "teaching grannies / grandads / etc. " - But for anyone interested:
I soldered the TL237 sensor to a square of veroboard and placed it inside a
small "lightproof" Maplin box (Above the Arduino R3). I drilled a hole in the
side (to allow light the in!) and added an M12 lens holder (for future use?).

With the sensor CAPPED, I get down to a count rate of less than 0.1Hz ... :)
Local skies (Surface Brightness +18 to +19?) give count rates ~20-60 Hz.
The rest is, as they say, all down to (your) software (I'll spare MY blushes)!

I decided to use an LED display. For under a Tenner, these are rather nice:
https://proto-pic.co.uk/7-segment-serial-display-red/  :cool:
(Integrated proc, Libraries for Serial, I2C, SPI etc.)

The switch on the left changes the display between Mag/sq.arc.sec and
Limiting Vis. Mag. I analog-read the "pot" (at right) for display dimming.

I think will make a second sensor box and fit an "external" socket. I am
rather interested in the variation of sky brightness across my sky. I may
even record this in the region where the telescope is actually imaging...

An interesting article in Feb 2016 "Astronomy Now" by John Rowland.
He concludes (like me) "Msqm" varies quite a lot, once you depart from
the zenith. And raises the interesting question... What figure to use. :p

Link to comment
Share on other sites

17 hours ago, Gina said:

Takes me a very long time to finish projects too - if I ever do and that's rather rare :D

Ain't that the truth! :D

If everyone is not completely bored yet, I do have a couple of "hot tips" 
based on what I have found out (and not without some minor effort!) ;)

There are two commonly used Arduino Libraries to measure frequency:

Freqcount: https://www.pjrc.com/teensy/td_libs_FreqCount.html

Freqmeasure: https://www.pjrc.com/teensy/td_libs_FreqMeasure.html#compare

Despite the above, I find that I can use *Freqcount* to measure the
signal from the sensor over a WIDE(!) range. In this application, the 
accuracy is mostly limited by the sample time argument (in millisec) 
to Freqcount_begin being an Arduino unsigned integer...  

#include <FreqCount.h>

void setup() {
  Serial.begin(57600);
  FreqCount.begin(1000);
}

void loop() {
  if (FreqCount.available()) {
    unsigned long count = FreqCount.read();
    Serial.println(count);
  }
}

Thus you can happily measure the count up for upto 60s 
(or 65.535s to be exact?) before things go rather awry. :p
And this confirmed by Experiment!

THE GOOD thing about FreqCount is that it can work to
*high*  frequencies too. The counter will work in daylight!
Of course it then delivers negative magnitudes too. Thus
proving that Venus might be seen during daylight etc.  ;)

The essence of MY program - to deliver mag per sq.sec.
and limiting magnitude is contained (explicitly) within:

    if(FreqCount.available()) {
      unsigned long count = FreqCount.read();
      freq = float(count) / float(nsec);
      Msqm = A - 2.5 * log10 (freq);
      Nelm = 7.93 - 5.0*log10((pow(10,(4.316 - (Msqm / 5.0))) + 1));
    }

Of course "A" (22.0) is the constant you will have to define? ;)

The other thing I had to revisit was  the thorny question of
converting floating point to integer! (for the display)...

Opinion is divided on WHICH routines work on the Arduino.
But I can personally vouch for *sprintf* in the following:


char tempString[10]; // Large enough for digits

...

if (modeVal == 0) // Swithc to Msqm or Nelm?
	sprintf(tempString, "%4d", int(Msqm*100.0));
else
    sprintf(tempString, "%4d", int(Nelm*100.0));
s7s.print(tempString); // Serial Write etc.

Anyway enough... enough... I might preserve some of this for
posterity? My website is mostly "Lorem Ipses" at the moment"!

IF only life were based on having great plans... :D

Link to comment
Share on other sites

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.