Go Down

Topic: processing forum sucks, please help! (Read 603 times) previous topic - next topic

big93

hi, i tried posting for help on the processing forum, but nobody is answering!
processing looks cool, and i just want to be able to use it!

so if somebody could show me the barebones of what i need in my coding screen, and  include anything the processing program needs to connect to the arduino, becuase im having problems.

please include

begining, void setup, void draw or loop, whichever i need, and if you need an actual script to use, im tryng to make it so when i press b on my keyboard, the arduino understands and turns an led on, and the led is on pin 13.

thanks to anybody who helps me!
happy new years!
-big93

trialex

OK it's not that hard. It took maybe 3 hours for me to get this stage from nothing, i.e. downloading processing, looking at the examples, trying code, writing the complimentary arduino code.

Code: [Select]
import processing.serial.*;     // Import the serial communication package
Serial port;          // This came from all the example sketches

void setup()
{
  println(Serial.list());      // What serial ports are avaialble?

   port = new Serial(this, Serial.list()[0], 9600); // 0 = RS-232, 4 = USB
 
   port.write(hour());  //Send the hours as a two digit number
     delay(100);
   port.write(minute());  //Send the minutes as a two digit number
     delay(100);
   port.write(second());   //Send the seconds as a two digit number
}

void draw()
{
 // I just needed to send the time once, didn't need to do anything after that so draw() is empty
}


You'll need to change a few things - you'll want to move the port.write calls to the draw() function for example.

It should have everything you need to send stuff to arduino from processing though. You can get all of this stuff from the Serial Library page http://processing.org/reference/libraries/serial/index.html and the example is on the serial.write page http://processing.org/reference/libraries/serial/Serial_write_.html

You'll probably also want to use the keyTyped() function

Code: [Select]
void keyTyped() {
 println("typed " + int(key) + " " + keyCode);
}


http://processing.org/reference/keyTyped_.html

big93

but i cant even make a succesful sketch to make an led turn on the baord, i dont know what barebones code i need to write!
and how do i tell it my port is com 3?
and what do i use instead of "digitalWrite" and instead of "pinMode"
and instead of "HIGH" and instead of "OUTPUT" becuase for all those things it sais it's not located in some temporary folder on my comp...

i'm also trying to edit your code to work with, but its not working either, are those port. commands neccasery, or do i just get rid of them?

thnks for the quick reply btw!!

trialex

Quote
but i cant even make a succesful sketch to make an led turn on the baord, i dont know what barebones code i need to write!
and how do i tell it my port is com 3?
and what do i use instead of "digitalWrite" and instead of "pinMode"
and instead of "HIGH" and instead of "OUTPUT" becuase for all those things it sais it's not located in some temporary folder on my comp...

i'm also trying to edit your code to work with, but its not working either, are those port. commands neccasery, or do i just get rid of them?

thnks for the quick reply btw!!



OK - first of all, you know that processing and arduino are two different programs, and each has a specific and totally different purpose?

To make and Arduino board respond to processing commands, you need to write TWO DIFFERENT sketches - one in the Arduino IDE, compiled and then uploaded to the Arduino board, and another written in the Processing IDE, and then run on your PC.

To do what you are trying to do, the framework of the processing sketch will look  like what I posted.  The arduino sketch will look like a typical Arduino sketch that you are used to - it will have the digitalWrite() and pinMode() calls.

In regards to your specific question about the processing sketch, the line

Code: [Select]
println(Serial.list());      // What serial ports are avaialble?

will output the available serial ports to the black area at the bottom of the Processig IDE. You use the number corresponding to COM3 in the list in the next line. Also, the number will be the same as the position (zero indexed) COM3 appears in the TOOLS -> Serial Port list in the Arduino IDE, i.e. if it's the third on the list, you should use [2].

In general, it sounds like you are trying to jump into things too quickly, and then getting frustrated when it doesn't work. I used to do excactly the same thing, and I don't know whether it's getting older, doing more projects, or doing engineering work as a job that has made me realise that knowing what you are doing first makes the job a lot easier.

Start with reading ALL the reference sections of the Arduino website - it really is a valuable resource. Equally (or perhaps more) valuable are the example sketches, and I think you are lucky, beacuse there is an example which has both an Arduino sketch and Processing sketch which does almost exactly what you are trying to do, although rather than lighting and LED when a certain key is pressed on the computer, it lights up when the mouse rolls over an area on the screen.

You can find the example (at least on Arduino 0008 - might change for other versions, I'm not sure) in the Arduino IDE by going

FILE -> Sketchbook - > Examples -> Communication -> Physical Pixel

Note the Arduino code is at the top, the Processing code is below, and commented out. You can copy out the processing code into a new processing sketch, or you can simply open it as an example in processing by going

FILE -> Examples -> Libraries -> Serial -> SimpleWrite

See how easy they have made it for you!

So play around with the example, then do a FILE -> Save As for both, and modifiy the Processing skecth so that it sends out the key you press, and modify the Arduino sketch to listen to what it receives over the serial line, and lights up an LED according to what key it was.

Feel free to ask questions, but it makes it easier on everyone if it's obvious you've read all the help, reference and examples.

big93

OH!!!!
i need to send the arduino 2 sketches! one on arduino program, and one on processing, now it makes sense why it wouldent work...

edit, here i got it working. On the software interface page, it gives a quick sketch and i edited it a bit to make it finally work, and heres the result:

Code: [Select]
import processing.serial.*;
import cc.arduino.*;

Arduino arduino;
int ledPin = 12bb;

void setup()
{
 //println(Arduino.list());
 arduino = new Arduino(this, Arduino.list()[1], 57600);
 arduino.pinMode(ledPin, Arduino.OUTPUT);
}

void draw()
{

 if(keyPressed) {
   if (key == 'b' || key == 'B') {
     arduino.digitalWrite(ledPin, Arduino.HIGH);
   }
 } else {
   arduino.digitalWrite(ledPin, Arduino.LOW);
 }
 rect(25, 25, 50, 50);
}



and then i programmed glovepie (with a code thats shorter then my name lol ) and now when i press A on my wiimote, and led lights up on the arduino!
IT WORKED!!!
awsome, thanks for the help, i wouldent have been able to do it without your help, and now i could move onto more complex things, i could even make a wiimote controlled robot
thanks again!
-big93

Go Up