Hello,

I am trying to read 5 light sensors data using the following code. The following code works if I use Arduino Uno board using corresponding digital pin number. However, if I try to use same code for APM2 with corresponding digital pin which is from 0 to 5, it does not work. I am pretty sure that my problem is on the choice of pin number.

Could anyone know what digital pin number should I use? Or, does anyone has a schematic for the APM2 board?

--------------------------------------------------------------------------------------------------------------------

int TSL230_Pin = 0; //sensor output pin
float TSL230_samples = 0.2; //s, higher = slower but more stable and accurate

void setup()
{
Serial.begin(19200);
setupTSL230();
}

void loop()
{
int frequency = readTSL230(TSL230_samples);
Serial.println(frequency);
}

void setupTSL230(){
pinMode(TSL230_Pin,INPUT);
}

int readTSL230(float samples){
//sample light, return reading in frequency //higher number means brighter

int readings = 0;
float time_difference=0;
float current_start= micros(); //Return the number of microseconds since the program started

while(time_difference < 1000000*samples)
{
pulseIn(TSL230_Pin, HIGH); //waits for the pin to go HIGH, return the length of the pulse (in microseconds)
time_difference=micros()-current_start;
readings++;
}

int freq = readings;
return freq;
}

IMG_0213.JPG

IMG_0214.JPG

IMG_0215.JPG

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • You can find the schematic on the website.  Right off the store page for the board IIRC.

This reply was deleted.

Activity