Jump to content

SkySurveyBanner.jpg.21855908fce40597655603b6c9af720d.jpg

Arduino Sky Quality Meter - working!


Corpze

Recommended Posts

  • Replies 119
  • Created
  • Last Reply

I have not yet implemented the SQM in Provence. The code in the FreqMeasure llibrary cannot hande the high frequencies that the sensor delivers during daylight, and the Arduino gets hung on a very low level.

The device I use is the TCS3200. This has a selectable (via 2 logic-level inputs) dividers, so that you can choose an output frequency of 100%, 20% or 2% of the "raw" frequency.

Even better, the device can measure R, G, B and Intensity separately through 2 more logic inputs. So not only can you measure the darkness, but the sky's colour, too! Although in practice this isn't very useful.

The device can also be bought mounted on a breakout board - but it comes with some LEDs that have to be removed.

Link to comment
Share on other sites

you can choose an output frequency of 100%, 20% or 2% of the "raw" frequency.

interesting - which output do you tend to use, or do you vary the input you select durign the day, as light levels change.  This looks like a useful device, as I was thinking TL237R + Ripple counter + muliplexer to select the desired output, your device does it all in one :)

Link to comment
Share on other sites

interesting - which output do you tend to use, or do you vary the input you select durign the day, as light levels change.  This looks like a useful device, as I was thinking TL237R + Ripple counter + muliplexer to select the desired output, your device does it all in one :)

I tend to use the "clear" (the sensor has 4 sets of detectors, one group with red filters, one with blue, one with green and one with no filters - the clear channel) measurements most of the time.

I don't use an Arduino, so I'm not limited by it's frequency input. Instead I have a dedicated PIC 16f887 that handles all my sensors and can accept an input frequency of something over 20MHz - which is much greater than the TCS3200's max. output of about 800kHz.

Link to comment
Share on other sites

yeah, a proper PIC would be the way to go I guess ;)

I will try using a ripple counter to scale down the input frequency.

Might need to selectively do this, e.g above a certain threshold, to retain accuracy. if I can scale the input down by 1024 above a threshold that might keep the range and accuracy... will see  

Link to comment
Share on other sites

Well it works, I put the sensor through an 8 bit ripple counter, then pull off the raw value, or the /32 and /256 outputs of the counter using the multiplexer, which is driven off the arduino. The software then scales the frequency read of the pin by either 1, 32 or 256.

A bit like a gearbox, keeps the revs in a specified range. I just need to tweak the thresholds for gear changing. Currently set to 35khz and 1khz.

I've read mag/as2 using gear 0 of about 21, and at the other end pointing a green laser into the sensor got a reading of about 7.

I'll try to post a video if anyone is interested.

Link to comment
Share on other sites

Pulsein seems to work quite well, you don't need freqcount, freqcounter or freqmeasue. The arduino doesn't seem to lock up at all (I do have my mix and ripple counter working alongside the arduino thoughwhich might help)

So far I've measured between mag 7 and 20

Link to comment
Share on other sites

I'm trying the following code but i get overflowed values in very low light environment

long getFrequency(int pin) {
#define SAMPLES 30
long freq = 0;
for(unsigned int j=0; j<SAMPLES; j++) freq+= 500000/pulseIn(pin, HIGH, 250000);
return freq / SAMPLES;
}

Link to comment
Share on other sites

  • photo-thumb-22530.jpg?_r=1364118933
  • Advanced Members
  • 360 posts
  • Location: Bishops Stortford

When you say low liight levels how low ?  >  Less than 1Hz

I fixed it and i now use the following function.

float freq_measure(){
  float period = 0;
  byte tries = 0;
  do{
    period = 2*pulseIn(TSL237PIN, LOW, 1000000); // uS
  } 
  while(period==0 && ++tries<=5);
  return(1000000.0/period);
}

I checked this site  http://nsbm.darksky.org/tech.php and i read that the  Sky brightness is calculated as:

M = (-2.5 * log10((F-dark frequency)*gain correction))+ZP,

where M is the sky brightness (mag/arcsec2), F is the measured frequency (raw, in Hz), T is the sensor temperature © and ZP is the zero point, defined as the light input that produces an output of 1 Hz.

The gain correction is measured for each detector in the laboratory between -20 C and +50 C and is fit with a 2nd order polynomial which uses 24 C as a reference temperature. The dark frequency is measured over the same temperature range and also fit with a 2nd order polynomial.

The dark current of the sensor is less than 0.1Hz but i think we will have to calculate it end extract it from the measured frequency. Unihedron already does that.

Link to comment
Share on other sites

Are you then averaging several reading, or do you find the readings stable enough without averaging ?

I'm getting a bit of a problem with static on the LCD module on my breadboard, I know it's the LCD, as the arduino carries on sending readings down the serial line even though the LCD goes crazy. Got Isolating caps everywhere

Link to comment
Share on other sites

I recently had a chance to use the Unihedron SQM and SQM-L meters and decided I wanted to build my own. A search led me to this thread, thanks for all this great info!

In researching this project I discovered another Taos sensor which I think might work well for this - the TSL2561. It has 2 sensors, one IR only, the other visible+IR. I'm thinking one could subtract the IR to get visible, so no filter would be needed. The TSL2561 is an I2C device, making it much easier to get data from, no frequency counting needed. More than that, Adafruit sells a really nice breakout board complete with power and voltage conversion, which can be directly connected to an Arduino (or Raspberry Pi). I've got one of the Adafruit boards, and I still have an SQM and an SQM-L on loan, so I thought I'd see what I can do with this.

William

Link to comment
Share on other sites

I tried using the TSL2561 - it's not sensitive enough, unfortunately. I've got another I2C device on order that might be. Meanwhile the TSL237 I ordered arrived, so I'll give that a try.

Link to comment
Share on other sites

I'm going to see if I can get a TSL2591 to try, but I've been having really good success with the TSL237 now.

I found an interesting thing with the FreqMeasure library. The first count after begin() is always short. I modified the code to discard the first reading. PulseIn does not have this problem. I need to peer at the FreqMeasure code to see why, or just not use it...

William

Link to comment
Share on other sites

We really should be moving away from FreqMeasure as it cannot handle the frequencies generated by TSL237 during daylight. Have you tried FreqCount? I will but I have no time right now...

/per

Link to comment
Share on other sites

I don't have problems with FreqMeasure on an Arduino Uno  running at 16 mHz, even at high light levels, but I do on a Teensy running at 8 mHz. I do have problems with pulseIn at very low light levels, but in actual use this is very unlikely to happen since the sky will never be that dark (we can only hope!).

FWIW, I rewrote "freq_measure" to use unsigned long and return the cycle time. Not sure if it really matters, but if you're trying to avoid using float/double to save memory, this might help.

// returns the period in us, not the actual frequencyunsigned long freq_measure(){  unsigned long period = 0;  byte tries = 0;  while (period == 0 && tries<5) {    period = 2*pulseIn(TSL237, HIGH, 5000000); // up to 5 sec pulse time    tries++;  }  Serial.print("tries "); Serial.print(tries);  Serial.print(", period "); Serial.println(period);  return(period);}
Link to comment
Share on other sites

How long does that take to execute? I need to use code that doesn't get hung for more than possibly half a millisecond. CPU is 328 @ 16MHz.

And FreqMeasure really does crash my system when the output frequency of the TSL237 gets too high. It can go up to several MHz with some light shining on it, and it will be placed permanently outside...

/per

Link to comment
Share on other sites

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.