question about processing

Hi, i just got my Arduino and i'm learning how to use it, however, i got a little question.

I have to do this project, its about controlling a dc motor using a potenciometer and graph this value on processing, and also measure temperature using a lm35 sensor and graphing it too in the same processing window.

I already did the potenciometer part, but i don't know how to graph the temperature in the same window using Serial.

Can you help me?

Thank you for your attention.

Post the code you are using, and specify the motor control hardware.

this is the Arduino code:

int potPin = 0;                           // Analog pin 0 connected to the potentiometer
int transistorPin = 9;                  // connected from digital pin 9 to the base of the transistor
int potValue = 0;                       // value returned from the potentiometer

void setup() {                          // set  the transistor pin as an output
  pinMode(transistorPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {                           // read the potentiometer, convert it to between 0 - 255 for the value accepted by the digital pin.
  Serial.println(analogRead(A0));
  potValue = analogRead(potPin) / 4;    // potValue alters the supply from pin 9 which in turn controls the power running through the transistor
  analogWrite(9, potValue);
  potValue=Serial.read();
  delay(50);
 
}

and this is the processing code:

import processing.serial.*;
Serial myPort;

float x;
color c;
String cadena;
float valorReal=0;

void setup(){
  size(680,320);
  smooth();
  strokeWeight(2);
  c=color(225,255,255);
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
  myPort.clear();
}

void draw(){
  background(255);
  fill(c);
  rect(0,280,150,-x);
  
  fill(0,0,0);
  line(150,280,150,0);
  line(150,252,135,252);
  line(150,224,120,224);
  line(150,196,135,196);
  line(150,168,120,168);
  line(150,140,135,140);
  line(150,112,120,112);
  line(150,84,135,84);
  line(150,56,120,56);
  line(150,28,135,28);
    
  
  textSize(32);
  fill(0,0,0);
  text("Velocidad",0, 310);
  fill(0,0,0);
  text("0%",150,280);
  fill(0,0,0);
  text("50%",150,140);
  fill(0,0,0);
  text("100%",150,30);
   
  

  }


void serialEvent (Serial myPort) { 
   //Obtener cadena de puerto serial
   cadena = myPort.readString();
   if (cadena != null) {
     //Quitar espacios en blanco
     cadena = trim(cadena);
     //Capturar cadena
     valorReal = float(cadena); 
   }
   x=map(valorReal,0,1023,0,280);
   
}

Some parts are in spanish xD

I'm sending the potenciometer output to the pin A0 of arduino, and sending the signal back from the pin 9.

On the pin A5 i'm sending the signal of the temperature sensor, but i don't know how to graph it.

OK, now please go back to that posting, select "modify" on your message, highlight the code section and click on the "#" icon above the edit window to mark it up as code.

Makes it much easier to read - and to reply to your query.

Done XD

On the Arduino side, I would get rid of Serial.println(analogRead(A0));

You can also delete the line potValue=Serial.read(); since that has no effect.

You will need some code to read the temperature. I assume you can cope with this by following the examples. The end result should be a variable holding the temperature value.

At the bottom of loop immediately before you call delay(), I would print the potValue, followed by a comma, followed by the temperature, followed by a linefeed:

potValue = analogRead(potPin);
analogWrite(9, potValue/4);
tempValue = readTemperature(); // I have assumed you implement this function to return the temperature
Serial.print(potValue);
Serial.print(",");
Serial.println(tempValue);
delay(50);

On the Processing side you would read a line of input from the serial port as before, and then use String.split() to split it into two strings at the comma. Then you would process each of the sub-strings in the same way as previously.