Quantcast
Channel: Processing Forum
Viewing all 1768 articles
Browse latest View live

Re : ArrayIndexOutofBoundsException ERROR

$
0
0
I think I fixed it. 

The reason is that line of code is only usable when any COM port is connected and is new.

Re : Check if Serial port is connected

$
0
0
Im resurrecting this thread because I am having the exact same issue and was wondering if maybe now here is a workaround.
 
my sketch interacts with two com ports on my pc.  I need to let the user know that there is a USB cable unplugged in a user friendly way rather than having them deal with the RED exception text at the bottom of the processing window.
Ultimately I want to be able to make an executable out of this so Id rather handle the error "inhouse" and have the sketch notify them of the unplugged cable and wait for them to connect it or even just tell them to connect it and start the application over again.
 
Any Idea how to do this????

Simple Serial send receive question

$
0
0

Im having a very hard time understanding serial communication... hopefully one of you can help me out.

I need to write a function to check communication between processing and my arduino via serial.

I am sending the a stream of character "A" from processing to arduino
when Arduino sees an 'A' then it sends a character 'B' back to processing
when processing sees that 'B' then it sends the character 'C' back to arduino

this is done for this reason:

stream of A's sent 1/4 sec apart to allow arduino time in case its not yet ready to receive
once the arduino is receiving data it gets that A and replies with a B to let processing know its online and receiving

processing reads that B then sends arduino a C to let it know it can now proceed to the void loop() function and start streaming the actual sensor data

BTW im using an arduino micro so like Leonardo it uses Serial and Serial1....Serial1 is used to receive data from elsewhere but doesn't apply to this section of the sketch.  likewise on the processing end there are two serial connections established but only myport is used to communicate to this arduino  so myport2 is not applicable either...the robot() class is used elsewhere also but since it has a delay feature I dropped it into this part of the sketch to only send data every 1/4 second so it doesn't fill up the buffer too fast waiting for arduino to respond....If besides the solution you have a better approach to achieve this please let me know...  I am making this stuff up as I go ad don't really know the most efficient way to accomplish this....thnkx


My programs look like this:

Arduino:

[code]
char ch;
int R;
int L;
int comFlag=0;  //0=waiting for initial request to connect from PC
//1= request received...sending confirmation to PC
//2=confirmation acknowledged by PC ready to proceed into main loop()

void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(19200);
  Serial1.begin(19200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  //ESTABLISH COMMUNICATION LINK WITH PC
  while(comFlag!=2){
    if (Serial.available()) {// wait for data from pc
      ch=(char)Serial.read();      //if data is available read it
      if(ch=='A' && comFlag==0){    
        Serial.println("B");//Send 'A' character back to pc to acknowledge that it received the data
        comFlag=1;//flag to let us know that we are ready for stage two of connection verification process
      }
      if (ch=='C' && comFlag==1){         //check to see if data  in = 'C'
        comFlag=2;
      }

    }
  }
}

void loop() // run over and over
{
.
.
.
}
 [/code]

 

The processing end looks like this:

[code]
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.event.InputEvent;
import processing.serial.*;
import guicomponents.*;

Serial myPort;
Serial myPort2;
Robot robby;

char message;

void setup() { 
  size(267, 366);
  try
  {
    robby = new Robot();
  }
  catch (AWTException e)
  {
    println("Robot class not supported by your system!");
    exit();
  } 

  println(Serial.list());
  println("  Connecting to -> " + Serial.list()[portIndex]);
  myPort = new Serial(this, Serial.list()[portIndex], 19200);
  String portName = Serial.list()[1];
  myPort2 = new Serial(this, portName, 9600);
  robby.mouseMove(xx, yy);
  String[] files;

  //ESTABLISH SRIAL COMMUNICATION WITH HEADSET

  while (message!='B') {//Write 'A' to serial port until a reply is received
    int message = myPort.read();
    println(message);
    myPort.write('A');
    println("Waiting for connection");
    robby.delay(25);
  }
  myPort.write('C');
  println("CONNECTION ESTABLISHED!!!");
  //robby.delay(1000);
}


void draw(){
.
.
.
}
[/code]
 
 
Its just not working....  if I use the Serial monitor in arduino to test and it seems fine.
nothing happening on the monitor
I type an A
it returns a B
I type a C
Sensor data starts to stream....

But when I try to do it through another sketch (in processing)
I see  on the processing monitor area:

Waiting for connection
-1
Waiting for connection 
-1
Waiting for connection
-1
Waiting for connection
-1
Waiting for connection


So its probably not being received the right way
I don't think its a processing issue but I am pretty sure its just my basic understanding of serial communication that's off...

When I send data through a println("A");
am I sending a character
When I receive using ch=(char)Serial.read() do I get a character to compare (if(ch=='A'))

I might be comparing apples to oranges....

DXF export for beginRaw and PGraphics buffer

$
0
0
Hi, quick question, I think:
Is there a syntax to get beginRaw(DXF, "output.dxf") working with a PGraphics off-screen buffer?

(I was expecting something like pg.beginRaw(DXF, "output.dxf") to work, but no go....)

Appreciate any suggestions!

Matthew

Minim- "Unexpected token: \"

$
0
0
I am so ticked off. I'm trying to add audio into my game, and I was getting nothing but errors, so I made a new document and copied the text WORD FOR WORD from this website (adding my own song in) and I keep getting, first of all, "unexpected token: [" then it tells me "Java" is unexpected.
AND, it just keeps telling me "unexpected token: \" and that's not even in this script. I give up. 

Re : Minim- "Unexpected token: \"

$
0
0
Without posting your code, there is no way to help you...
All examples of minim are available in the Processing examples, too, so no need to type them in!

Re : Minim- "Unexpected token: \"

$
0
0
Moved to Core Library Questions (assuming it's about the Minim version shipped with Processing).

Try the Minim examples that come with Processing.

Otherwise just post your code so the forum can help. We're not psychic you know.

Implement movie as background

$
0
0
Hi people,

Im with a problem, i want put a video as background so i used the following code : 



import processing.video.*;
Movie myMovie;


void setup(){
  size(600,1000);
  myMovie = new Movie(this, "video.mov");
  myMovie.loop();
    
}

void draw(){
  tint(500, 300);
  image(myMovie, mouseX, mouseY);
}

void movieEvent(Movie m) {
  m.read();
  
}


Dont give error, however sometimes appears only the audio of video, other dont appear nothing.. and other times appears a part of  video so much lagged and pixelized.. can u help me?
 
I noticed that with mouseX, mouseY coordinates , video its attached with mouse, so for put that as background i have to put the size like window size right?


Re : Implement movie as background

$
0
0
Moved to Core Library Questions.

Try this instead:
  1. void draw() {
  2.    image(myMovie, 0, 0, width, height);
  3. }

Re : Minim- "Unexpected token: \"

$
0
0
It's not the library that shipped with Processing. I looked it up and it said you had to use this program to play sound, so that's what I did. 

[snip java]
import ddf.minim.*;

Minim minim;
AudioPlayer song;

void setup()
{
size(100, 100);

minim = new Minim(this);

// this loads mysong.wav from the data folder
song = minim.loadFile(“music.mp3”);
song.play();
}

void draw()
{
background(0);
}

void stop()
{
song.close();
minim.stop();

super.stop();
}
[/snip]

This is just the basic one I used to see what the heck was going on.

Re : Maximum Number of Items in an Array

$
0
0
If you can not fix this, it may be a solution to just load the next 10 frames arount your current frame in memory.

-------------------------------------------------------------------------------------------------------------
0      5      10      15      20
                  ^
                  |
         currently here
      |                        |
      | load all frames  |
      | within this range|

If the position changes, you can update the bounds of your array (maybe in a different thread) and set the images you don't need at the moment to NULL.
So you have an array of size 1100, filled with null values. When you load your program you can initialise the array to contain real references for the first 10 frames. On frame 2 load the 11. image and so on...

Re : Minim- "Unexpected token: \"

$
0
0
Can you post the complete error message?
I think you have a file called "music.mp3" in your data directory, right!?

Re : Implement movie as background

$
0
0
thanks i puted that, however it worked when i taked off the fuction tint.. but ocurred other problem, audio is not coordinate with movie and just reproduce some part of video , than loop again from the begging

Re : Minim- "Unexpected token: \"

$
0
0
It's not the library that shipped with Processing. I looked it up and it said you had to use this program to play sound, so that's what I did.
Does this mean you have installed a more recent Minim version from it's website? If so, have you removed the Minim version that comes with Processing, as the website you link to instructs? Otherwise multiple versions of Minim may cause problems.

Note by the way, that the (older) Minim library that comes with Processing is perfectly fine for playing sounds and includes the code sample you posted.

Gif / How to Use the pixel of a background image on particle in movement

$
0
0
What i have to do to introduce a gif image associated to one ellipse ?

How to use the pixels of a background imagem on particles in movement. That particles are in particle system..

Sorry but im a noob on processing so its kinda hard 

Cheers

Re : Minim- "Unexpected token: \"

$
0
0
Error message:



processing.app.SketchException: unexpected token: [
at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:326)
at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:197)
at processing.mode.java.JavaBuild.build(JavaBuild.java:156)
at processing.mode.java.JavaBuild.build(JavaBuild.java:135)
at processing.mode.java.JavaMode.handleRun(JavaMode.java:176)
at processing.mode.java.JavaEditor$20.run(JavaEditor.java:481)
at java.lang.Thread.run(Thread.java:662)

Yes, I installed it and deleted from where it told me. 
I didn't know that worked for playing sounds. I'm sorry.

Re : Minim- "Unexpected token: \"

$
0
0
Any thoughts? This is the last thing we need done, and we can't figure it out.

Re : Processing 2.0 - 1,000,000 points in OpenGL using Vertex Arrays

$
0
0
jeff_g, I tried that same code for 2.0b7 on Windows, and it rendered a plain white screen, nothing more. That is not what the 1.5.1 code shows (rotating planes). So there are no errors and it runs, but the output is not the same.

The code that andres posted above runs and produces no errors for me now in the latest version of Processing (2.0b7) for both Windows & Linux. However, it also does not have the desired output. The screen should be full of randomly colored squares, and instead it just outputs a plain, black screen. I am unclear why this is.

Peace.

Re : Maximum Number of Items in an Array

$
0
0
Hey guys. Unfortunately it seems like a known issue that the Serial library doesnt support 64 bit processing, so I cant send the data from my encoder and arduino to processing in 64 bit. Tim, that sounds promising. How would I got about accomplishing that? I confess that I'm a bit of a novice to this.

Re : Minim- "Unexpected token: \"

$
0
0
Just to be sure: the [snip java] and [/snip] parts must NOT be in the PDE... They are just delimiters of the code, not part of the code.
Viewing all 1768 articles
Browse latest View live