Go Down

Topic: adding a Processing program to the main program on arduino (Read 693 times) previous topic - next topic

Abdelali

I went through that process but I couldn't get any results . pleaaaase if somebody could help I'll be so greatful

liudr

What you can do is to write a Processing sketch to read Serial input and parse the numbers that Arduino prints out and then displays the numbers on screen. Do you know how to parse numbers from a serial text stream? That is the key here.

Abdelali

#7
Apr 08, 2013, 11:27 pm Last Edit: Apr 08, 2013, 11:30 pm by Abdelali Reason: 1
Hi Dear liudr
Sincerly I really don't know how to parse numbers from a serial text stream, I'm greatful if you could help me out here

liudr

This is how you print the data out from Arduino:

Code: [Select]

  Serial.print(accXangle);Serial.print("\t");
  Serial.print(accYangle);Serial.print("\t");
   
  Serial.print(gyroXangle);Serial.print("\t");
  Serial.print(gyroYangle);Serial.print("\t");
 
  Serial.print(compAngleX);Serial.print("\t");
  Serial.print(compAngleY); Serial.print("\t");
 
  Serial.print(kalAngleX);Serial.print("\t");
  Serial.print(kalAngleY);Serial.print("\t");
 
  Serial.print("\n");


You should be able to get data from Processing using this format. I have not used Processing since shortly after they rolled out 1.0
Here is a sample program I wrote:

Code: [Select]

import processing.serial.*;

Serial myPort;  // The serial port

void setup()
{
  size(220, 220);
  Object[] possibilities = Serial.list();
  myPort = new Serial(this, (String)possibilities[possibilities.length-1], 115200);   
}

void draw()
{

  char [] inBuffer=new char[256];
  char write_pointer=0;
  while (true)
  {
    if (myPort.available() > 0)
    {
      inBuffer[write_pointer]=myPort.readChar();
      if (inBuffer[write_pointer]=='\n')
      {
        inBuffer[write_pointer]='\0';
        break;
      }
      write_pointer++;
    }
  }
  //Interpret the buffer content with an sscanf
  String inString=new String(inBuffer);
  float[] inNums = float(split(inString,'\t'));
  for (int i=0;i<8;i++)
  {
    print(inNums[i]);
    print('\t');
  }
 
  while(true){}

}


Give this a try.

Go Up