First Serial Comunication!

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

Quick for you maybe

"PHREADZ (rhymes with ‘threads’) is still in invite-only mode. we hope to open up for all very soon!"

How does the inviting? If it’s you, pm me an invitation!

Hey, good news CTC! After

Hey, good news CTC! After playing around with my bluesmirf this eve, I got two way come with it and the comp via processing.

I’m using a bs2 homework board with the smirf as I had been testing this setup.

I have the bs2 connected to a ds1620 temp sensor as well

The scheme of how it works is press a button on the bs2 board which causes the bs2 to read the temp sensor data. this is then sent out via serial data to the bt serial device(blue smirf) . This is sent to an app(drawn in the “processing” display box) on my computer which displays the temp data. I then have five seconds to send a string back to the bs2 which if it’s what I expected it gets an okay, if not, it sends an error message. if it gets nothing by the time it reaches the timeout, it states a timeout error.

pretty cool :smiley:

I think you’ll be able to create some cool stuff with this CTC.

I tried several different sources to see what worked and how things worked with serial com. The easiest thing I found so far was using the serialEvent handler source found here worked well for getting things going.

I modified it for allowing input using the following code:

void keyPressed() {
// Send the keystroke out:
myPort.write(key);
//whichKey = key;
}

 

also change the font to use:

PFont myFont = createFont(PFont.list()[2], 14);

I had to use this as the font line from the orginial source didn’t work for my setup.

I really want to learn the language but this was a quick test to see if I could get the serial bt stuff going…so hopefully this weekend I’ll be able to do a bit more learning of the language and go through the tutorial.

 

Edit:

I plan to do a test tomorrow with the ir beacon. I’ll rig up the receiver and have it output to the bt device. so I have a constant stream of data coming in(from ir beacon outputting several bytes of data) and going out(via bt smirf on serial com6). since it also goes through the hardwired serial via com1 from debug statements, I’ll verify the data that way and the speed of things…

Awesome!

Hi Chris,

This is awesome! Congratulations on you venturing into big boy programming land :-). Still what impresses me the most is your skill in creating great and enthusiastic broadcasts - keep’em coming!

Great work!

you so funny :DCTC’s the

you so funny :smiley:

CTC’s the party!

It works ^2

It works! I can watch the phreadz film. Don’t understand what’s different from yesterday, but it’s cool.

It works! You totally blinked an LED on you big boy programmed screen! Congrats! At least that kind of miracle I can understand.

Is it still a miracle then?

 

Did you say sending a zero and then a one? Guess you overcame your fear of those? :wink:

The Link…

Yeah, I grabbed the wrong embed link at first. The first link was the regular “logged in” one I forgot to use the “external” one.

Word.

Hell Yeah!!

Awesome work, voodoo! Do us all a favor, would ya? --Keep us apprised of all your work… I.e. be sure all your code is all open sourcy so I (we) can keep an eye on it so we might learn something here!

By the way, thanks for the blue smirf reference, I just took a look over a sparkfun. I was actually eyeing the RS-232 model (the blue one with the serial style plug) I had no idea there was a unit with the “adapter (TTL)” built in. --I like things that are simple data-in, data-out. and at 60 bucks, not bad!

word.

Hey chris, thanks, yeah all

Hey chris, thanks, yeah all my stuff is open source, and as I mentioned in my post, it’s pulled right from the ref manual. I was just being lazy and not putting in a file attachment . :smiley: The only stuff I didn’t post was the very dirty bs2 code that I wrote nearly a year ago. again, this was just a test to see if it would work with the processing serial interface.

I’ll see about coding something(short and simple) up for the 18x that I have with the test I had mentioned in the above post. That way we will have some pbasic code that will be a bit cleaner and not a year old. :smiley:

Some other notes on my testing.

  • all tests had been done using hyperterm initally.
  • when using processing, make sure to stop the app (use te stop button next to play even if you close the window that it opens) I noted some oddites if I didn’t do this(connection would lock out the com port and I couldn’t use it.)
  • If the above occures, reset the power on your Uproc setup would usually work.
  • I initially set up the bt device a while back and didn’t take notes on it…this was a pita if I recall and there are very limited notes on how to do this.

The device that you are talking about looks very nice, and gives you complete wireless interaction with the bot, both in programming and debugging. I still actually prefer the hardline for doing this but I could see this being a cool thing to do. only issue would be making sure you had a serial cable for each device.

I acutally liked the setup that I had where I could program and debug on the main serial out and have the data stream out of a seperate channel going to the bt device.

 

Here is the setup that I had used last night in my test.

 

 

 

ctc

we’re proud of you and you’re awesome!

The language is called “processing”? The serial is recieved by the OS on the laptop?

Alrighty, ctc, got the rig

Alrighty, ctc, got the rig working. The setup is the following:

<ir beacon> transmitting byte sequence from 1-9

<relay station> picaxe 8m with ir receiver showing correct data in the debug window.

Transmitting the byte sequence received from ir beacon via bt to my desktop running the processing code.

I’ll post source code for all three components(irb, picaxe relay station, processing code) in a bit. how can I post the source as files?

edit: nm, I added it to a blog post of my own that links to this post.

Just a note, the shot below was active and transmitting the number sequence(from the beacon) out through the bt(note green connect led on the bt device) :smiley:

pa8M_bluetooth.jpg

 

Processing Processing

Got my “hello_serial” all Processed now.

import processing.serial.*;

Serial PicPort;

void setup() {
// parent comport baud parity databits stopbits
PicPort = new Serial(this, Serial.list()[0], 4800, ‘N’, 8, 1.0);
}

void draw() {
while (PicPort.available() > 0) {
int PicSaid = PicPort.read();
println(PicSaid);
}
}
This will read in values that my picaxe sends me over the serial (programming) cable. Text is also println’d as values.

Goodnight

See what you think of this
http://processing.org/learning/libraries/serialcallresponse.html

Thanks rik and have a good
Thanks rik and have a good night!

Hey CTC, this was very

Hey CTC, this was very helpful, I managed to get my code working ang gathering 4 bytes of data, with a start and stop byte. drawing shouldn’t be an issue at this point.

Edit: Hey Chris, I got the code working(even better than before) this eve. The processing code takes in the start and stop byte, reads the data. As far as using this for mapping I think it’ll work, but i did find an issue with what I would use the code for and need to figure out how to resolve it. Basically things get out of sync if I start droping bytes(block the ir transmission). The bytes come in correctly but they don’t get displayed correctly. I think it’s with the processing code, but I got a bit complex in the data transmission code(you’ll see when I post it). It’s making my brain hurt so I’m going to take a break…

I’m finding a lot of the syncing issues have to do with very subtle ms delays…like around 20ms…

This is where I think the issue is in the code. This is my modified version of the serial event function. This is making my brain hurt as well…

void serialEvent(Serial myPort) {
// read a byte from the serial port:
int inByte = myPort.read();
// look for the start byte
if (firstContact == false) {
if (inByte == ‘S’) {
println(inByte);
myPort.clear(); // clear the serial port buffer
firstContact = true;
}
}
else {
// Add the latest byte from the serial port to array:
serialInArray[serialCount] = inByte;
println(inByte);
if (inByte == ‘E’) {
//look for the end byte

// myPort.clear(); // clear the serial port buffer
firstContact = false; }
else {
serialCount++;
// If we have 4 bytes:
if (serialCount > 3 ) {
xpos = serialInArray[0];
ypos = serialInArray[1];
upos = serialInArray[2];
vpos = serialInArray[3];

// Reset serialCount:
serialCount = 0;
}
}
}

}

Got mine working too!
why did I write this responce before I updated the post?

I think all this progress
I think all this progress should be saved as a Tip!