Alright guys, I have my first serial conection comunication going!! Picaxe to Processing via serial/USB. I don't have this up to youtube, instead I did a quick post to Phreadz. Here is the link:
http://phreadz.com/v/2Q0FFVH6IGAI/
***Update****
Just like Voodoo, I got some code working as well. The first video has the picaxe spitting out 4 bytes (randomly picked by me when I wrote the code) as I hit one of the 3 buttons. Processing then takes these numbers and draws 1 of 3 lines.
Having this working, I moved on to changing data. I grabbed walters remote and used the joystick to send 2 bytes coresponding to the cordinates I wanted the line to end on -the start cordinates were always 0,0. Although I was using the remote, it was hardwired and used sertxd and serrxd commands. (this is the second video)
I will attach the code soon --for now, I am off to go fly planes with my boys.
Code: (second video, processing side)
import processing.serial.*;
int bgcolor; // Background color
int fgcolor; // Fill color
Serial myPort; // The serial port
int[] serialInArray = new int[4]; // Where we'll put what we receive
int serialCount = 0; // A count of how many bytes we receive
int xpos, ypos;
int expos, eypos; // Starting position of the ball
boolean firstContact = false; // Whether we've heard from the microcontroller
void setup() {
size(400, 400); // Stage size
noStroke(); // No border on the next thing drawn
// Set the starting position of the ball (middle of the stage)
xpos = width/2;
ypos = height/2;
expos = width/2;
eypos = height/2;
// Print a list of the serial ports, for debugging purposes:
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, "COM15", 4800);
}
void draw() {
background(200);
fill(fgcolor);
stroke (0);
strokeWeight(4);
// Draw the shape
line(xpos, ypos, expos, eypos);
}
void serialEvent(Serial myPort) {
// read a byte from the serial port:
int inByte = myPort.read();
// if this is the first byte received, and it's an A,
// clear the serial buffer and note that you've
// had first contact from the microcontroller.
// Otherwise, add the incoming byte to the array:
if (firstContact == false) {
if (inByte == 'A') {
println (inByte);
myPort.clear(); // clear the serial port buffer
firstContact = true; // you've had first contact from the microcontroller
myPort.write('A'); // ask for more
}
}
else {
// Add the latest byte from the serial port to array:
serialInArray[serialCount] = inByte;
serialCount++;
// If we have 3 bytes:
if (serialCount > 3 ) {
xpos = serialInArray[0];
ypos = serialInArray[1];
expos = serialInArray[2];
eypos = serialInArray[3];
// print the values (for debugging purposes only):
println(xpos + "\t" + ypos + "\t" + expos +"\t" + eypos);
// Send a capital A to request new sensor readings:
delay (100);
myPort.write('A');
// Reset serialCount:
serialCount = 0;
}
}
}
Code: (for the second video)
pause 1000
sertxd (65)
main:
serrxd b0
if b0 > 0 then main2
goto main
main2:
readadc 0,b3
readadc 1,b4
let b3=b3
let b4=b4
let b1=0
let b2=0
sertxd (b1)
pause 10
sertxd (b2)
pause 10
sertxd (b4)
pause 10
sertxd (b3)
goto main
https://www.youtube.com/watch?v=EjG41PfQBQA