Go Down

Topic: Measure nightsky with TSL237 (Read 13713 times) previous topic - next topic

GoForSmoke

Which is why I asked about calibration using known magnitude objects . And the haze from India to China and beyond, 15% less sunlight is just scary IMO.

The naked eye view from over 1 mile alt is just freaking amazing! It's better than Hubble pics. Everyone should have the chance. I wonder how few nowadays have every seen the Milky Way as a solid band?

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Corpze




Thanks for your very good answer, i will use the meter for my own, to measure different sites where i do my astrophotographing.

For the ZP i have a luxmeter that i can use, it will not be scientific grade, but good enough for me!

It´s just one thing left, does anyone know what kind of "lensmodule" i have marked on the picture?



Oh, and one more question; The code i am gonna start out with is this: http://arduino.cc/forum/index.php/topic,21536.msg160200.html#msg160200

But will that work? it is written for a Arduino duemilanove?


Ok, so iv'e hooked up the sensor but it just recieves 0pulses, 0khz and 0 uw... but in the code, i can´t se that the sensor input pin is initialized? i have hooked it up to pin 5, maybe it is initialized in the freqCounter.h lib?

GoForSmoke

INPUT LOW is the default state for all I/O pins. It makes them safer for one, kind of a NULL state as opposed to starting up as OUTPUT LOW or HIGH.  
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Corpze

I connected the capacitor wrong :P Now it works like a charm...  XD

I wonder how and where i am gonna put the formula for converting uW/cm2 to mag/arcsecond2, (according to minaya, its this formula;
ZP - 2.5*log10(frequency) where ZP is my ZeroPoint i will calculate that after i have revcieved the lens if i could find one  :~ )
in this code:

Code: [Select]
#include <FreqCounter.h>



long irradiance;
long freq;
long  pulses;
const float area = 0.0092;
int cnt;
int pinLed=13;
short period = 100; // 100 ms Gate Time

void setup() {
  pinMode(pinLed, OUTPUT);
  Serial.begin(115200);        // connect to the serial port
  Serial.println("Frequency Counter");
}

void loop() {
light();
Serial.print(cnt++);
Serial.print("  Pulses: ");
Serial.print(pulses);
Serial.print(";  Freq: ");
Serial.print(freq);
Serial.print(" Hz;  Irradiance: ");
Serial.print(irradiance);
Serial.println(" uW/cm2 = KHz");
delay(1000);


void light(){
  digitalWrite(pinLed, HIGH);
  FreqCounter::f_comp=10;   // Cal Value / Calibrate with professional Freq Counter
  FreqCounter::start(period);  // 100 ms Gate Time
  while (FreqCounter::f_ready == 0)
  pulses=FreqCounter::f_freq;
  delay(20);
  digitalWrite(pinLed, LOW);
  freq = (pulses*1000)/(period*area);
  irradiance = (freq/1000);
  return ;
}




minaya

You have the code to measure the frequency, so you need to put the conversion to magnitudes after that ;) . Don't forget to declare the variable in which you want to save the 'mag/arcsec2' value (maybe as global var?). You have an excelent example in how the code you used defines and prints through Serial the variable Irradiance. Just mimic that (change the math expression).

log10 is included in <math.h> library, don't forget to include it in the header of you sketch.

GoForSmoke

I hope that 32-bit floats in the formula won't spoil your accuracy. They'll certainly slow your code down as Arduino has no FPU.

There are alternatives like BCD, fixed-point 64-bit integers and Nick Gammon's big number library.


Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Corpze

Ok, 1st try for the formula, does this look ok to you guys?
I also coded a button witch i want to make the measurements start (not with the button pressed down all the time but once) i am not sure if that is what i asigned in the code?

If i want to make ,say three measurements, and then take the median (freq1 + freq2 + freq3 / 3) ? for increasing the accuracy, where to put a code like that?

Thanks for the help :) i am a total novice on this :P

Code: [Select]
#include <FreqCounter.h>
#include <Math.h>


long irradiance;
long freq;
long pulses;
long magnitude;
const float ZP = 12; // "Zero Point" i just picked a random nr for now, not calibrated)
const float area = 0.0092;
int cnt;
int pinLed=13;
int buttonSQM = A2;
short period = 100; // 100 ms Gate Time

void setup() {
  pinMode(pinLed, OUTPUT);
  pinMode(buttonSQM, INPUT);
  digitalWrite(buttonSQM, HIGH);
  Serial.begin(115200);        // connect to the serial port
  Serial.println("Frequency Counter");
}


void loop() {
light();
Serial.print(cnt++);
Serial.print("  Pulses: ");
Serial.print(pulses);
Serial.print(";  Freq: ");
Serial.print(freq);
Serial.print(" Hz;  Irradiance: ");
Serial.print(irradiance);
Serial.println(" uW/cm2 = KHz");
Serial.print(magnitude);
Serial.print(" Mag/Arcsecond2 ");

delay(1000);


void light(){
  if (buttonSQM = HIGH)
  digitalWrite(pinLed, HIGH);
  FreqCounter::f_comp=10;   // Cal Value / Calibrate with professional Freq Counter
  FreqCounter::start(period);  // 100 ms Gate Time
  while (FreqCounter::f_ready == 0)
  pulses=FreqCounter::f_freq;
  delay(20);
  digitalWrite(pinLed, LOW);
  freq = (pulses*1000)/(period*area);
  irradiance = (freq/1000);
  magnitude = ZP - 2.5*log10(freq);

  return ;
}

Corpze


Ok, 1st try for the formula, does this look ok to you guys?
I also coded a button witch i want to make the measurements start (not with the button pressed down all the time but once) i am not sure if that is what i asigned in the code?

If i want to make ,say three measurements, and then take the median (freq1 + freq2 + freq3 / 3) ? for increasing the accuracy, where to put a code like that?

Thanks for the help :) i am a total novice on this :P

Code: [Select]
#include <FreqCounter.h>
#include <Math.h>


long irradiance;
long freq;
long pulses;
long magnitude;
const float ZP = 12; // "Zero Point" i just picked a random nr for now, not calibrated)
const float area = 0.0092;
int cnt;
int pinLed=13;
int buttonSQM = A2;
short period = 100; // 100 ms Gate Time

void setup() {
  pinMode(pinLed, OUTPUT);
  pinMode(buttonSQM, INPUT);
  digitalWrite(buttonSQM, HIGH);
  Serial.begin(115200);        // connect to the serial port
  Serial.println("Frequency Counter");
}


void loop() {
light();
Serial.print(cnt++);
Serial.print("  Pulses: ");
Serial.print(pulses);
Serial.print(";  Freq: ");
Serial.print(freq);
Serial.print(" Hz;  Irradiance: ");
Serial.print(irradiance);
Serial.println(" uW/cm2 = KHz");
Serial.print(magnitude);
Serial.print(" Mag/Arcsecond2 ");

delay(1000);


void light(){
  if (buttonSQM = HIGH)
  digitalWrite(pinLed, HIGH);
  FreqCounter::f_comp=10;   // Cal Value / Calibrate with professional Freq Counter
  FreqCounter::start(period);  // 100 ms Gate Time
  while (FreqCounter::f_ready == 0)
  pulses=FreqCounter::f_freq;
  delay(20);
  digitalWrite(pinLed, LOW);
  freq = (pulses*1000)/(period*area);
  irradiance = (freq/1000);
  magnitude = ZP - 2.5*log10(freq);

  return ;
}



Ok, this is the result so far, i don´t think it can go lower than 1086hz, but why? And it doesn´t matter if i change the delay to 4000ms either :/


úFrequency Counter
0  Pulses: 0;  Freq: 0 Hz;  Irradiance: 0 uW/cm2 = KHz
-2147483648 Mag/Arcsecond2 1  Pulses: 1736;  Freq: 1886956 Hz;  Irradiance: 1886 uW/cm2 = KHz
-3 Mag/Arcsecond2 2  Pulses: 10;  Freq: 10869 Hz;  Irradiance: 10 uW/cm2 = KHz
1 Mag/Arcsecond2 3  Pulses: 1;  Freq: 1086 Hz;  Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 4  Pulses: 1;  Freq: 1086 Hz;  Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 5  Pulses: 1;  Freq: 1086 Hz;  Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 6  Pulses: 1;  Freq: 1086 Hz;  Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 7  Pulses: 1;  Freq: 1086 Hz;  Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 8  Pulses: 1;  Freq: 1086 Hz;  Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 9  Pulses: 1;  Freq: 1086 Hz;  Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 10  Pulses: 1;  Freq: 1086 Hz;  Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 11  Pulses: 1;  Freq: 1086 Hz;  Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 12  Pulses: 1;  Freq: 1086 Hz;  Irradiance: 1 uW/cm2 = KHz
4 Mag/Arcsecond2 13  Pulses: 1;  Freq: 1086 Hz;  Irradiance: 1 uW/cm2 = KHz

GoForSmoke


If i want to make ,say three measurements, and then take the median (freq1 + freq2 + freq3 / 3) ?


Operation order will screw that up. Only the last will be divided.

((freq1 + freq2 + freq3) / 3) is what you want, if that is really what you want to do **.

Extra parenthesis can't hurt unless they're in the wrong place or not balanced (as many opens as closes). If in doubt, use them. The compiler doesn't add code for extras.

**
Quote
Pulses: 10;  Freq: 10869 Hz

If you averaged the 10 pulses as above, you would lose the last digit, have no rounding....

You could do something like (untested pseudo code alert!) this for rounding
Code: [Select]

samples = 3 // could be 10 for instance
freq = ((freq1 + freq2 + freq3 + samples / 2) / samples)


Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Corpze



If i want to make ,say three measurements, and then take the median (freq1 + freq2 + freq3 / 3) ?


Operation order will screw that up. Only the last will be divided.

((freq1 + freq2 + freq3) / 3) is what you want, if that is really what you want to do **.

Extra parenthesis can't hurt unless they're in the wrong place or not balanced (as many opens as closes). If in doubt, use them. The compiler doesn't add code for extras.

**
Quote
Pulses: 10;  Freq: 10869 Hz

If you averaged the 10 pulses as above, you would lose the last digit, have no rounding....

You could do something like (untested pseudo code alert!) this for rounding
Code: [Select]

samples = 3 // could be 10 for instance
freq = ((freq1 + freq2 + freq3 + samples / 2) / samples)





I will try that, but what about the frequency, why can´t it go any lower than 10869 Hz? I haven´t calibrated the ZP yet, can it be the problem?

GoForSmoke


I will try that, but what about the frequency, why can´t it go any lower than 10869 Hz? I haven´t calibrated the ZP yet, can it be the problem?


For single samples you get 1086. Why? I don't know!

freq = (pulses*1000)/(period*area);

Is it any surprise that 10 pulses gets 10x the freq?

Also you should mix your mixed-types math.
As above you have by types: long = (long * int) / (short * float) <<=== not a good idea

That whole business needs a total going-over.
You can throw in casts (tell the compiler to treat a variable as a different type) but if you're not careful you won't get the equation you think. Without casts, as it is now, you're letting the compiler decide.

Example of casting:
long L;
int I = 1000;
float F = 0.1;

L = (long) ((float I) * F);

And thanks to the floating point math, the result won't likely be 100L. Yes 100L because it's cast as a long to go into a long variable. 100 is a 16-bit signed integer. 100L is a 32-bit signed integer. If the letter U is used, 100U is a 16-bit unsigned integer and 100UL is a 32-bit unsigned integer.
If you use a constant and want it seen as a floating point then put in a decimal point, 100.0 is a 32-bit floating point value.

Give the compiler less room to wiggle and you may get more predictable results.
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Corpze

#26
Mar 01, 2013, 03:55 am Last Edit: Mar 01, 2013, 04:12 am by Corpze Reason: 1


I will try that, but what about the frequency, why can´t it go any lower than 10869 Hz? I haven´t calibrated the ZP yet, can it be the problem?


For single samples you get 1086. Why? I don't know!

freq = (pulses*1000)/(period*area);

Is it any surprise that 10 pulses gets 10x the freq?

Also you should mix your mixed-types math.
As above you have by types: long = (long * int) / (short * float) <<=== not a good idea

That whole business needs a total going-over.
You can throw in casts (tell the compiler to treat a variable as a different type) but if you're not careful you won't get the equation you think. Without casts, as it is now, you're letting the compiler decide.

Example of casting:
long L;
int I = 1000;
float F = 0.1;

L = (long) ((float I) * F);

And thanks to the floating point math, the result won't likely be 100L. Yes 100L because it's cast as a long to go into a long variable. 100 is a 16-bit signed integer. 100L is a 32-bit signed integer. If the letter U is used, 100U is a 16-bit unsigned integer and 100UL is a 32-bit unsigned integer.
If you use a constant and want it seen as a floating point then put in a decimal point, 100.0 is a 32-bit floating point value.

Give the compiler less room to wiggle and you may get more predictable results.



To be honest, i don´t understand anything of what you just wrote :/

Maybe i should just start over with a basic frequency counter and go from there?

Basicly, all i wanna do is translate frequence to mag/arcsecond2, and because the sensor is linear, wouldn´t it be quite easy to do that?

I am fairly new to arduinos and coding, i have just got a steppermotor to work with two buttons and a lcd-display :/

Is this the way to go maybe?:

I have one sensor, capable of sending between 0.00x Hz to 1000kHz
I also have a luxmeter, so i can calibrate the sensorvalue roughly.

if i has a light that shines with 100 lux, and the sensor is sending 20 kHz, can i from there convert to mag/arcsecond2?

I dont need any pulsecounter any else of the data, i am just interested of Mag/AS2

Is this possible?

BR/ Daniel

GoForSmoke

How about get the setup working without converting to frequency and -then- take that step?

Just show the pulses, your raw data, as you point at darker or lighter things right in the house. That will let you test and debug everything but the convert and I and or others will walk you through the conversion to the best of our abilities?

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Corpze

That sounds good :)

But you are talking about pulses, the sensor outputs a frequency, that isn´t the same?

is Pulse the time and freq the hight of the wave? And the dutycycle of the sensor is 50%, is that because it ouputs a square wave or something?

I did all the maths in the sketch last night, just to see how things work together like pulses, frequency an so forth. One thing i i stumbled upon is the "Gate time", what exactly is that, because that one is set to 100ms in the sketch, but somwhere on the internets, i read that the Gatetime should be set to 1000ms to get "the true freq of the sensor"?

//

GoForSmoke

Quote
But you are talking about pulses, the sensor outputs a frequency, that isn´t the same?


I'm just going off your variable names.
How about leaving this part out until you have reliable 'pulses' then?

Code: [Select]

  freq = (pulses*1000)/(period*area);
  irradiance = (freq/1000);
  magnitude = ZP - 2.5*log10(freq);


that's where your mixed-types math is a totally different issue, let's cut that in the attempt to troubleshoot and get back to it when the rest is ready.





Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Go Up