Skip to main content
Thank you for your help with the last one, I have corrected that error (you were right!!) but I am now having trouble with the processing side of the code! Any comments would be amazingly helpful.
Source Link

Data received from LDR is printing with a letter UPDATE: Fault in frontprocessing code (e.g Q309, R305). How can I stop this?- doesn't receive correct data from Arduino

I am receiving data from an LDR which I am inputting into processing. The data seems to be received to Arduino correctly however when I try to constrain and mapI have looked at the values into data processing can computebeing sent via the serial monitor and it prints a series of values with lettersall seems correct. However, the data that is being received in front rather than values betweenprocessing doesn't reflect the rangedata received by the LDR so I think I have specifieddone something wrong here but not sure what as I am fairly new to this all. (Please see image for what is printing in the processing serial monitor). 

Any help identifying where I have gone wrong would be so so helpful!

int rval=0;
int lightval;

//Recorded minimum and maximum values
int minval=0;
int maxval=950;

void setup() 
{
  Serial.begin(9600); 
}

void loop() 
{
  rval = analogRead(1);
  //Serial.println(rval);
  rval=constrain(rval,minval,maxval); //constrain the 
 value lightval=map(rval,minval,maxval,0,255); between 
 0 and//Serial.println(lightval);
 950 Serial.write(lightval);
}

PROCESSING CODE

import processing.serial.*;

Splash paintsplash;
Serial port;

float lightval=mapvalue=0;

void setup(rval,minval)
{
  size(600,maxval600);
  smooth();
  background(255);
  paintsplash= new Splash();
  port=new Serial(this,0 Serial.list()[6],2559600);
  //convertsprintArray(Serial.list());
}

void thedraw()
{
 range ofpaintsplash.display();
 rval paintsplash.splash();
 Mapped fromdelay(200);
 0-950 to 
 0-255 if(0<port.available())
 now stored{
 as lightval  value=port.read();
  Serial.}
  
  println(lightvalvalue);
  Serial.write
  if(lightvalvalue<=75)
  {
    fill(255,137,132);
  }
  
  else if(value>75 && value<=125)
  {
    fill(32,78,95);
  }
  
  else
  {
    fill(183,215,216);
  }
}

SERIAL MONITORPROCESSING CLASS - PAINT_SPLASH

class Splash
{ 
  float x;
  float y;
  float size;
  
  Splash()
  {
    x=0;
    y=0;
    size=int(random(35));
  }
  
  void display()
  { 
    //fill(255,137,132);
    noStroke(); 
    ellipse(x,y,size,size); 
  } 
  
  void splash()
  { 
  float xcord=int(random(600));
  float ycord=int(random(600)); 
  pushMatrix();
  translate(xcord,ycord);
  
     for ( float i =3; i < 29; i ++)
     {
       float splashX = x + random(100); 
       float splashY = y + random(100);
       
       ellipse(splashX,splashY,size-i,(size-i+random(3)));
     }
     
   popMatrix();
  } 
}

enter image description here

Data received from LDR is printing with a letter in front (e.g Q309, R305). How can I stop this?

I am receiving data from an LDR which I am inputting into processing. The data seems to be received to Arduino correctly however when I try to constrain and map the values into data processing can compute it prints a series of values with letters in front rather than values between the range I have specified. Any help identifying where I have gone wrong would be so so helpful!

int rval=0;
int lightval;

//Recorded minimum and maximum values
int minval=0;
int maxval=950;

void setup() 
{
  Serial.begin(9600); 
}

void loop() 
{
  rval = analogRead(1);
  Serial.println(rval);
  rval=constrain(rval,minval,maxval); //constrain the value rval between 0 and 950. 
  lightval=map(rval,minval,maxval,0,255); //converts the range of rval. Mapped from 0-950 to 0-255. now stored as lightval.
  Serial.println(lightval);
  Serial.write(lightval);
}

SERIAL MONITOR

UPDATE: Fault in processing code - doesn't receive correct data from Arduino

I am receiving data from an LDR which I am inputting into processing. The data seems to be received to Arduino correctly and I have looked at the data being sent via the serial monitor and it all seems correct. However, the data that is being received in processing doesn't reflect the data received by the LDR so I think I have done something wrong here but not sure what as I am fairly new to this all. (Please see image for what is printing in the processing serial monitor). 

Any help identifying where I have gone wrong would be so so helpful!

int rval=0;
int lightval;

//Recorded minimum and maximum values
int minval=0;
int maxval=950;

void setup() 
{
  Serial.begin(9600); 
}

void loop() 
{
  rval = analogRead(1);
  //Serial.println(rval);
  rval=constrain(rval,minval,maxval);  
  lightval=map(rval,minval,maxval,0,255);  
  //Serial.println(lightval);
  Serial.write(lightval);
}

PROCESSING CODE

import processing.serial.*;

Splash paintsplash;
Serial port;

float value=0;

void setup()
{
  size(600,600);
  smooth();
  background(255);
  paintsplash= new Splash();
  port=new Serial(this, Serial.list()[6],9600);
  //printArray(Serial.list());
}

void draw()
{
  paintsplash.display();
  paintsplash.splash();
  delay(200);
   
  if(0<port.available())
  {
    value=port.read();
  }
  
  println(value);
  
  if(value<=75)
  {
    fill(255,137,132);
  }
  
  else if(value>75 && value<=125)
  {
    fill(32,78,95);
  }
  
  else
  {
    fill(183,215,216);
  }
}

PROCESSING CLASS - PAINT_SPLASH

class Splash
{ 
  float x;
  float y;
  float size;
  
  Splash()
  {
    x=0;
    y=0;
    size=int(random(35));
  }
  
  void display()
  { 
    //fill(255,137,132);
    noStroke(); 
    ellipse(x,y,size,size); 
  } 
  
  void splash()
  { 
  float xcord=int(random(600));
  float ycord=int(random(600)); 
  pushMatrix();
  translate(xcord,ycord);
  
     for ( float i =3; i < 29; i ++)
     {
       float splashX = x + random(100); 
       float splashY = y + random(100);
       
       ellipse(splashX,splashY,size-i,(size-i+random(3)));
     }
     
   popMatrix();
  } 
}

enter image description here

Code formatting.
Source Link
Edgar Bonet
  • 45.2k
  • 4
  • 42
  • 81

I am receiving data from an LDR which I am inputting into processing. The data seems to be received to Arduino correctly however when I try to constrain and map the values into data processing can compute it prints a series of values with letters in front rather than values between the range I have specified. Any help identifying where I have gone wrong would be so so helpful!

ARDUINO CODE

int rval=0;

int lightval;

//Recorded minimum and maximum values

int minval=0;

int maxval=950;

void setup() { Serial.begin(9600); }

void loop() {

rval = analogRead(1);

Serial.println(rval);

rval=constrain(rval,minval,maxval); //constrain the value rval between 0 and 950.

lightval=map(rval,minval,maxval,0,255); //converts the range of rval. Mapped from 0-950 to 0-255. now stored as lightval.

Serial.println(lightval);

Serial.write(lightval);

}

int rval=0;
int lightval;

//Recorded minimum and maximum values
int minval=0;
int maxval=950;

void setup() 
{
  Serial.begin(9600); 
}

void loop() 
{
  rval = analogRead(1);
  Serial.println(rval);
  rval=constrain(rval,minval,maxval); //constrain the value rval between 0 and 950. 
  lightval=map(rval,minval,maxval,0,255); //converts the range of rval. Mapped from 0-950 to 0-255. now stored as lightval.
  Serial.println(lightval);
  Serial.write(lightval);
}

SERIAL MONITOR

I am receiving data from an LDR which I am inputting into processing. The data seems to be received to Arduino correctly however when I try to constrain and map the values into data processing can compute it prints a series of values with letters in front rather than values between the range I have specified. Any help identifying where I have gone wrong would be so so helpful!

ARDUINO CODE

int rval=0;

int lightval;

//Recorded minimum and maximum values

int minval=0;

int maxval=950;

void setup() { Serial.begin(9600); }

void loop() {

rval = analogRead(1);

Serial.println(rval);

rval=constrain(rval,minval,maxval); //constrain the value rval between 0 and 950.

lightval=map(rval,minval,maxval,0,255); //converts the range of rval. Mapped from 0-950 to 0-255. now stored as lightval.

Serial.println(lightval);

Serial.write(lightval);

}

SERIAL MONITOR

I am receiving data from an LDR which I am inputting into processing. The data seems to be received to Arduino correctly however when I try to constrain and map the values into data processing can compute it prints a series of values with letters in front rather than values between the range I have specified. Any help identifying where I have gone wrong would be so so helpful!

ARDUINO CODE

int rval=0;
int lightval;

//Recorded minimum and maximum values
int minval=0;
int maxval=950;

void setup() 
{
  Serial.begin(9600); 
}

void loop() 
{
  rval = analogRead(1);
  Serial.println(rval);
  rval=constrain(rval,minval,maxval); //constrain the value rval between 0 and 950. 
  lightval=map(rval,minval,maxval,0,255); //converts the range of rval. Mapped from 0-950 to 0-255. now stored as lightval.
  Serial.println(lightval);
  Serial.write(lightval);
}

SERIAL MONITOR

Source Link

Data received from LDR is printing with a letter in front (e.g Q309, R305). How can I stop this?

I am receiving data from an LDR which I am inputting into processing. The data seems to be received to Arduino correctly however when I try to constrain and map the values into data processing can compute it prints a series of values with letters in front rather than values between the range I have specified. Any help identifying where I have gone wrong would be so so helpful!

ARDUINO CODE

int rval=0;

int lightval;

//Recorded minimum and maximum values

int minval=0;

int maxval=950;

void setup() { Serial.begin(9600); }

void loop() {

rval = analogRead(1);

Serial.println(rval);

rval=constrain(rval,minval,maxval); //constrain the value rval between 0 and 950.

lightval=map(rval,minval,maxval,0,255); //converts the range of rval. Mapped from 0-950 to 0-255. now stored as lightval.

Serial.println(lightval);

Serial.write(lightval);

}

SERIAL MONITOR