We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › sending text from processing to ardiuno
Page Index Toggle Pages: 1
sending text from processing to ardiuno (Read 1505 times)
sending text from processing to ardiuno
Jun 1st, 2009, 3:06am
 
Hi,
I taking an rss feed from the internet, breaking it down into individual characters and sending it from processing to the arduino to be displayed on an led matrix. I have got it working ok, its just that the entire feed is sent to the led matrix in a split second. How is this slowed down, is it using a buffer? Here is th code I am curently using for processing and arduino.

PROCESSING:


import processing.serial.*;
Serial port;
String buffer = ""; // Accumulates characters coming from Arduino
int twit = 0;

void setup(){
 size(500,150);
 println(Serial.list());
 String arduinoPort = Serial.list()[1];
 port = new Serial(this, arduinoPort, 9600); // connect to Arduino
//download cable com5 - 1
//data cable com8 - 4
}

void draw(){
int startingPoint = 0;
Twitter twitter;
int myFriendsCount;
User[] friends;
String username = "********";
String password = "*********";
twitter = new Twitter(username,password);
String myTimeline;
int tlLength; // string length of the timeline passed from twitter
PFont font;



 // Setup font
 font = loadFont("CourierNew36.vlw");
 textFont(font, 18);

try
{
java.util.List statuses = twitter.getUserTimeline();
 //List statuses = twitter.getUserTimeline();
   
         Status status = (Status)statuses.get(0);
         println(status.getUser().getName() + ":" + status.getText());
                         
         size (500,150);
         background (0);
         text((status.getText()), 20, 25);
         //tlLength = status.getText().length();
        //println (tlLength);
        myTimeline = new String(status.getText());
       // println(myTimeline);
        // send to pic LED display
        charToSerial(myTimeline);
}
catch( TwitterException e)
{
// catch error here
}

//println("more?");
//exit();
delay(10000);
loop();

//println("more again");
}

void charToSerial(String str1)
{
 int strLen;
 strLen = str1.length();
 for (int i = 0; i < strLen; i++)
 {
   println(str1.charAt(i));
  port.write(str1.charAt(i)); // send data to Arduino




 if (port.available() > 0) { // check if there is data waiting
   int inByte = port.read(); // read one byte
   if (inByte != 10) { // if byte is not newline
     buffer = buffer + char(inByte); // just add it to the buffer
   }
   else {

     if (buffer.length() > 1) {


       buffer = buffer.substring(0,buffer.length() -1);
delay (1000);
              twit = int(buffer);

       buffer = "";

       port.clear();
     }

 }
 }
 }
}



ARDUINO:

//I'll save you raking through all my sprites and just give you the imprtant bit.....


void setup() {
 // initialize serial communication:
 Serial.begin(9600);

}

void loop() {
 // see if there's incoming serial data:
 if (Serial.available() > 0) {
   // read the oldest byte in the serial buffer:
   incomingByte = Serial.read();
      if (incomingByte == 'a'){
        while(pointer<6){
          buffer[pointer]= Serial.read();
          delay (500);
          pointer++;
        }}


Does anyone hve any suggestions?
Re: sending text from processing to ardiuno
Reply #1 - Jun 17th, 2009, 2:30pm
 
Isn't it enough to just add another delay in Processing?

Code:
void charToSerial(String str1) {
int strLen;
strLen = str1.length();
for (int i = 0; i < strLen; i++) {
println(str1.charAt(i));
delay(500);
port.write(str1.charAt(i)); // send data to Arduino


I guess the issue might be whether this pause in the program has an effect on serial communication...
Page Index Toggle Pages: 1