Hi, I am working with TSL235 light to frequency converter sensors using an Arduino MEGA ADK. When working with one sensor at a time there is no problem with sensing. When two sensors are simultaneously connected they interfere with each other. How can i fix this problem ?, I am attaching the code being used for the simultaneous reading of two TSL235 sensors. Regards. Alejandro.
define TSL235Three 20 // Out of TSL235 connected to Digital pin 21
define TSL235One 3 // Out of TSL237 connected to Digital pin 3
int period = 1000; // Miliseconds of each light frecuency measurement
unsigned long counterThree = 0; // Counter of measurements during the test
unsigned long counterOne = 0; // Counter of measurements during the test
unsigned long currentTime = millis();
unsigned long startTime = currentTime;
volatile long pulsesThree = 0; // Counter of measurements of the TSL235R
volatile long pulsesOne = 0; // Counter of measurements of the TSL235R
unsigned long frequencyThree; // Read the frequency from the digital pin (pulses/second)
unsigned long frequencyOne; // Read the frequency from the digital pin (pulses/second)
void setup()
{
Serial.begin(115200); // Start and configure the serial port
attachInterrupt(3, PulseCountThree, RISING);
attachInterrupt(1, PulseCountOne, RISING);
pinMode(TSL235Three, INPUT); // Declare the pin such as an input of data
pinMode(TSL235One, INPUT); // Declare the pin such as an input of data
setup_parallax();
}
void loop()
{
counterOne++; // Increase the number of measurement
getfrequencyOne(); // Request to measure the frequency
pulsesOne = 0; // reset the pulses counter
//delay(.000025); // delay for measurements between the two for 1/250/16
counterThree++; // Increase the number of measurement
getfrequencyThree(); // Request to measure the frequency
pulsesThree = 0; // reset the pulses counter
parallax_output();
}
void PulseCountThree()
{
pulsesThree++;
}
void PulseCountOne()
{
pulsesOne++;
}
void parallax_output()
{
Serial.print("DATA,DATE,TIME,");
Serial.print(frequencyOne); Serial.print(","); Serial.println(frequencyThree);
}
void setup_parallax()
{
Serial.println("LABEL,Date,Time,Frequency One (Pin 3), Frequency Three (Pin 20)");
}
unsigned long getfrequencyOne ()
{
noInterrupts();
frequencyOne = pulsesOne *1000 / period; // Calculate the frequency (pulses/second)
interrupts();
return (frequencyOne);
}
unsigned long getfrequencyThree ()
{
noInterrupts();
frequencyThree = pulsesThree *1000 / period; // Calculate the frequency (pulses/second)
interrupts();
return (frequencyThree);
}