Go Down

Topic: Messenger library (Read 26 times) previous topic - next topic

tof

Messenger is probably not the best solution if you are sending all that data at a high interval. For 64 leds, each controlled through three numbers separated by commas, you are looking at at least 384 bytes of data! This should definitely cause some Messenger overflows. Even without the overflow, you would expect an update speed between 15 and 5 "images" per second.

The best solution is to simply send a bunch of bytes without the help of Messenger. Here is partial code (I did not test it):

Code: [Select]
#define VALUES 192 //64*3
byte leds[VALUES];

unsigned long lastTime;
int writeindex;

void setup() {
 
 Serial.begin(57600);
 lastTime = millis();
 writeindex = 0;
}

void loop() {

// Read serial data
 while ( Serial.available() ) {
   // if ever there is more than 10ms between two bytes,
   // this indicates the start of a new series
    if( millis() - lastTime > 10) {
     writeindex = 0;  
   }
   lastTime= millis();
   leds[writeindex] = (byte) Serial.read();
   writeindex = (writeindex + 1) % VALUES;

 }
 
 /*
 For example, you want to retrieve the value of led i
 red = leds[i*3];
 green = leds[(i*3)+1];
 blue = leds[(i*3)+2];
 */
 
}
Thomas Ouellet Fredericks

basuraman

oh right...well i was just trying to see if it would work at all - then was going to try to optimize it or use other techniques to get it going faster. but you have a great point - keeping the data stream lean from the get go will save alot of overhead and make everything faster for sure.

i guess i started with Messenger because my host software sending from the PC easily spits out strings, but i had a harder time getting it to send raw ascii bytes - as strange as that may sound. i'll try retooling it and give it a go with your code as an example.

thanks so much!

diode

Hi Tof,
This looks really interesting. Could you perhaps outline what the best method and format of sending a combined message from Processing would be, to match your Arduino receiving example at http://www.arduino.cc/playground/Code/Messenger?
For example to send an array or string like (114,134,144,116,84,126,143)
Thanks!

bigRed

Quote
Hi Tof,
This looks really interesting. Could you perhaps outline what the best method and format of sending a combined message from Processing would be, to match your Arduino receiving example at http://www.arduino.cc/playground/Code/Messenger?
For example to send an array or string like (114,134,144,116,84,126,143)
Thanks!


I also have this question, I've tried writing to the serial port that the arduino is hooked up to, but that doesn't work very well.

tof

Hi diode and bigRed,

Quote
Could you perhaps outline what the best method and format of sending a combined message from Processing would be, to match your Arduino receiving example at http://www.arduino.cc/playground/Code/Messenger


Well, the simplest solution would be to instantiate a Serial object and then write the data as ASCII ints to it.

For example, this is the Processing code that would send the array {114,134,144,116,84,126,143} to the Messenger enabled Arduino:

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

Serial serial;  // Create object from Serial class

int[] data = {114,134,144,116,84,126,143};

void setup()
{
 size(200, 200);
 // 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.

 for ( int i=0; i < Serial.list().length ; i ++ ) {
     println("Port: \t"+Serial.list()[i]);
 }
 String portName = Serial.list()[0];
 serial = new Serial(this, portName, 115200);
 frameRate(20);
}

void draw() {
 
 // Send the data.
 // The data can not be formed of more than 64 ASCII characters.
 
 for (int i=0; i < data.length ; i++ ) {
    serial.write(str(data[i])); // Write the data as an ASCII character
    serial.write(' '); // Write the word separator: an ASCII space character
 }
 // Write the message terminator: an ASCII carriage return.
 serial.write('\r');
 

 
}
Thomas Ouellet Fredericks

Go Up