We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey folks!
I have something that used to work when it was running inside of a serial event _(mostly not my code, I think it was on Adafruit):
void serialEvent( Serial myPort) {
//put the incoming data into a String -
//the '\n' is our end delimiter indicating the end of a complete packet
val = myPort.readStringUntil('\n');
//make sure our data isn't empty before continuing
if (val != null) {
//trim whitespace and formatting characters (like carriage return)
val = trim(val);
println(val);
//look for our 'A' string to start the handshake
//if it's there, clear the buffer, and send a request for data
if (firstContact == false) {
if (val.equals("A")) {
myPort.clear();
firstContact = true;
myPort.write("A");
println("contact");
fetchTweets();
}
} else { //if we've already established contact, keep getting and parsing data
println(val);
// ***These four lines are the only lines I added***
// newNumber ensures that we don’t parse a tweet until we have one
if (newNumber == true) {
drawTweets();
}
// when you've parsed the data you have, ask for more:
myPort.write("A");
}
}
}
....but Processing would occasionally throw Serial errors, and it was pointed out to me that I was sending AND receiving to/from my Arduino, but all I really needed to do was send. I found some code from Dana Moser (http://www.curiousart.org/electronic2/code/34_Serial_Send_Arduino.html) which works a treat for sending.... but now I can’t put drawTweets(); in a Serial event and it seems that if I put it in the draw loop I get a blank screen (presumably because it’s working on sending all of the data I have to the Arduino until it draws the screen.
Even when I wrap it in the 'if' statement -- and immediately set newNumber to false -- no luck.
Any thoughts? Thanks!
Answers
Lotsa examples on serialEvent() + bufferUntil():
https://forum.Processing.org/two/discussions/tagged?Tag=bufferuntil()
Thanks GTL: that explains why it would throw errors -- but the problem is actually worse now that I’m not using serial event to do the drawing. Now I don’t even get a window at all UNLESS I comment out the fetchTweets() line:
Obviously I’m leaving out a bunch of variables and functions, but as I say, everything works (println, adruino) except getting a draw window.
Any more thoughts?
I hope you haven't actually removed serialEvent(). :-S
The idea is we just notify that the event happened in some variable.
And in turn, draw() checks out for that variable in some
if () {...}
block.Turn it off by assigning
false
to it and then act upon it.I miss this line:
draw a box so that the type doesn’t continually draw over itself
---> use
GTL, I think I understand (and yes, I DID remove SerialEvent() entirely!) but I’m obviously still doing something wrong because even after moving the code out I still can’t get a draw window to show up (although everything else with the Arduino chugs along fine)...
Here’s the code that works (it HAS a draw window and it accepts a new hashtag) ...until it throws a SerialEvent error. Maybe you can tell me how to remove it?
/* * * ControlP5 Textfield * FROM https://forum.processing.org/two/discussion/1576/controlp5-basic-example-text-input-field * by Andreas Schlegel, 2013 * www.sojamo.de/libraries/controlp5 */
I tried just moving it out like so, but that didn’t quite work -- I get a window but nothing drawn in it:
Thanks for all the help!
And Chrisir -- I accidentally deleted setup when I was cutting my code, but it IS in the real stuff; and it doesn’t matter what color the background is, if you put type in the draw window without covering it each time it comes around it draws over itself until there’s no anti-aliasing and it’s just crummy jagged type. At least, in my experience.