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 TSL235Two 21 // Out of TSL235 connected to Digital pin 21
define TSL235One 3 // Out of TSL237 connected to Digital pin 3
int period = 101; // Miliseconds of each light frecuency measurement
unsigned long counterTwo = 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 pulsesTwo = 0; // Counter of measurements of the TSL235R
volatile long pulsesOne = 0; // Counter of measurements of the TSL235R
unsigned long frequencyTwo; // 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(2, PulseCountTwo, RISING);
attachInterrupt(1, PulseCountOne, RISING);
pinMode(TSL235Two, 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()
{
counterTwo++; // Increase the number of measurement
counterOne++; // Increase the number of measurement
getfrequencyTwo(); // Request to measure the frequency
getfrequencyOne(); // Request to measure the frequency
pulsesTwo = 0; // reset the pulses counter
pulsesOne = 0; // reset the pulses counter
parallax_output();
}
void PulseCountTwo()
{
pulsesTwo++;
}
void PulseCountOne()
{
pulsesOne++;
}
void parallax_output()
{
Serial.print("DATA,DATE,TIME,");
Serial.print(frequencyTwo); Serial.print(","); Serial.println(frequencyOne);
}
void setup_parallax()
{
Serial.println("LABEL,Date,Time,Frequency Two, Frequency One");
}
unsigned long getfrequencyOne ()
{
noInterrupts();
frequencyOne = pulsesOne *1000 / period; // Calculate the frequency (pulses/second)
interrupts();
return (frequencyOne);
}
unsigned long getfrequencyTwo ()
{
noInterrupts();
frequencyTwo = pulsesTwo *1000 / period; // Calculate the frequency (pulses/second)
interrupts();
return (frequencyTwo);
}