Graph analog signal

Hi to everyone…

Below you will see that with these codes (Arduino+Processing) i convert an analog signal to digital with delta modulation and then i graph the bits which accept Arduino. I would like to know if i can in processing code to create the bits graph and also the analol signal graph together.(code?)(not to ‘‘paint’’ the bits only which i do already, but to create and the line of the signal)

HERE Are The Codes

ARDUINO

int currReading;
int prevReading = 0;
int val = 0; 
void setup() 
{Serial.begin(9600); }
void loop() 
{val = analogRead(0); 
Serial.print(0xff, BYTE); 
Serial.print((val >> 8) & 0xff, BYTE);
Serial.print(val & 0xff, BYTE); 
currReading = analogRead(0);
int delta = currReading - prevReading;
Serial.println(delta);
prevReading = currReading;
delay(10); }

Processing

import processing.serial.*;
Serial myPort;      
int val;            
int valx;           
int xd = 1;        
int stxr;           
int stxg;           
int stxb;           
int xdd;            
int xdc;           
void setup() 
{size(700, 256);
  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 9600);
  background(0);}
void draw()
{while (myPort.available() >= 3) {
if (myPort.read() == 0xff)
val = (myPort.read() << 8) | (myPort.read());
valx = val / 4 ;      } 
xdd = xd / 2 ;
xdc =xd - xdd * 2 ;
if (xdc == 0 ) 
{stxr = 204 ; stxg = 233 ; stxb = 248;} 
else {stxr = 0 ; stxg = 146 ; stxb = 218;} ;
println (xdc) ;      
stroke(stxr, stxg, stxb);
line(xd, height, xd, height - valx);
if (xd >= width) 
{xd = 0;
background(0); } 
else 
{xd++;}}
val = analogRead(0); 
Serial.print(0xff, BYTE); 
Serial.print((val >> 8) & 0xff, BYTE);
Serial.print(val & 0xff, BYTE); 
currReading = analogRead(0);

(you're allowed to indent C, you know) You read the analogue input, waste 3ms, then read the analogue input again - why not just use the value you read at the start? The value you read the second time could have changed significantly from the first.

int prevReading;

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

void loop() 
{
  int val = analogRead(0); 
  Serial.print(0xff, BYTE); 
  Serial.print((val >> 8) & 0xff, BYTE);
  Serial.print(val & 0xff, BYTE); 
  int delta = val - prevReading;
  Serial.println(delta);
  prevReading = val;
  delay(10); 
}

Edit:Thinking about it, you probably waste about 2ms, but the argument still holds.

Ok about this.. For the graph do you have any idea?

Maybe you could format your Processing better?

tas: For the graph do you have any idea?

For a one-off graph/chart, use MS Excel. If you need to automated graph generation then gnuplot is a good choice. Gnuplot can be fussy to get the chart to come out the way you want, but once you have all the parameters right, you can script it up easily to generate charts on the fly or what have you.

This might be useful:

http://www.instructables.com/id/Arduino-Analog-Signal-Graphing-on-a-TFT-Touch-Scre/

There are source code examples of analog signal graphing that could help.