Go Down

Topic: Sending mutiple sets of LDR data from Arduino to Max/MSP (Read 460 times) previous topic - next topic

kieranblyth

Hi,

I'm quite new to Arduino but am currently working on a music project that uses brightness data from multiple LDRs, which then runs through a Max patcher to process sound.

I've previously tested this with a single LDR and it works perfectly, although I'm currently struggling with trying to send two different data sets when using two LDRs. I seem to be able to send two lists to Max, but when these are unpacked in Max, they are very unstable and fluctuate quite significantly despite no physical change in brightness. These two lists also seem to have some sort of mutual dependence (if I shade one of the LDRs, it also affects the data which is outputted by the other LDR, and vice versa). It would be great if anybody has any advice or guidance on how to send two independent sets of data from both LDRs. I have attached the current Arduino code below:



//setup our pins
const int led =  9;      // define the pin the LED connects to (9~ is PWM)
const int sensorPin1 = A0; // define the input pin for LDR (analog in 0)
const int sensorPin2 = A1; // define the input pin for LDR (analog in 1)

//define our variables
int sensorValue = 0;
int sensorValue2 = 0; // variable to store the value coming from the LDR sensor
int brightness = 0;   
int brightness2 = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

//SETUP elements of our system as it starts
void setup() {
Serial.begin(9600); //sets serial port for communication
pinMode(led, OUTPUT); // declare our LED pin (9~) to be an output:
}

//LOOP elements of our system while it runs
void loop() {
sensorValue = map(analogRead(sensorPin1),0,600,0,255);
sensorValue2 = map(analogRead(sensorPin2),0,600,0,255); // map the values to a useful range 0-255
brightness = constrain(sensorValue,0,255);
brightness2 = constrain(sensorValue2,0,255); // our brightness is limited to values between 0 and 255.

Serial.print(sensorValue, DEC);
Serial.print ("\t"); // separate tabs between values
Serial.println (sensorValue2, DEC); //prints the brightness value to the serial MONITOR (check your screen!) Max will read this with [serial port 9600]
delay(20); // wait 20 ms before starting the LOOP{} again!
}


Thanks,

Kieran

Robin2

Code: [Select]
void loop() {
sensorValue = map(analogRead(sensorPin1),0,600,0,255);
sensorValue2 = map(analogRead(sensorPin2),0,600,0,255); // map the values to a useful range 0-255
 ....

}

Your second reading may be picking up the residue from the first one after the ADC is switched to the second pin. Try this

Code: [Select]
sensorValue = analogRead(sensorPin1); // this reading gets discarded
sensorValue = map(analogRead(sensorPin1),0,600,0,255);
sensorValue2 = analogRead(sensorPin2); // this reading gets discarded
sensorValue2 = map(analogRead(sensorPin2),0,600,0,255);


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

kieranblyth

I'm still getting large and unstable fluctuations in the data from the first LDR, whereas the second LDR data seems to be more stable but is sending much smaller amounts of data.

Robin2

I'm still getting large and unstable fluctuations in the data from the first LDR, whereas the second LDR data seems to be more stable but is sending much smaller amounts of data.
Post the latest version of your complete program and please use the code button </>

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up