Arduino Forum

Forum 2005-2010 (read only) => General => News => Topic started by: tof on Sep 24, 2008, 02:26 pm

Title: Messenger library
Post by: tof on Sep 24, 2008, 02:26 pm
Messenger is a new library for Arduino. It is a "toolkit" that facilitates the processing of ASCII messages. Messenger processes characters until it receives a carriage return (CR). It then considers the message complete and available. The message is split into many elements as defined by a separator. The default separator is the space character, but can be any character other than NULL, LF or CR.

Messenger is the new SimpleMessageSystem (http://www.arduino.cc/playground/Code/SimpleMessageSystem). SimpleMessageSystem was nice, but not simple enough, so I wanted to switch to Firmata (http://www.arduino.cc/playground/ComponentLib/Firmata), but when I found out Firmata took at least half of my atmega168's memory, I went back to the drawing board and designed Messenger.

Please note that Messenger only provides methods for incoming messages. The internal Serial.print() functions work just fine for outgoing messages.

You can find Messenger here (http://www.arduino.cc/playground/Code/Messenger).
Title: Re: Messenger library
Post by: Syvwlch on Sep 25, 2008, 10:29 am
Hey, thanks!

Can't wait to take it out for spin...
Title: Re: Messenger library
Post by: Xtalker on Dec 30, 2008, 04:38 pm
This will be very useful!  I would love to use this with my new ethernet shield to parse caller ID messages and perhaps scrape web pages but, unfortunately, it doesn't support strings yet.

I would take this on myself but efficient string handling requires more C expertise than I have!

Any hope that string support will be added to the messenger library anytime soon?
Title: Re: Messenger library
Post by: tof on Dec 30, 2008, 06:03 pm
The problem with strings is that they use up a big chunk of memory (1 byte per letter).

I could probably add  string support. Something like:
compareString(String) that would return a true or false.
If the result is false, it stays in the buffer, if the result is true, it would pass to the next element of the message.


p.s.: I am not sure I posted the link before, but Messenger can be found here: http://www.arduino.cc/playground/Code/Messenger
Title: Re: Messenger library
Post by: Xtalker on Dec 30, 2008, 08:31 pm
Yes, strings are memory hogs and are not easily handled in the Arduino environment.  But something like Messenger could sure open a lot of interfacing possibilities!

I'd love to see support that allowed me to pick a string out of a sequence by position perhaps like:

readStr(index)
returns the element at the index as a string (defined by the message separator).

Thanks for all you work on this so far!
Title: Re: Messenger library
Post by: orvtech on Dec 31, 2008, 09:48 pm
nice!
Title: Re: Messenger library
Post by: rasc1234 on Jul 24, 2009, 08:01 am
Hi,

Is it possible to use this library also on Serial1, Serial2 etc. available on the Arduino Mega? (This would be great)

Thank you
Title: Re: Messenger library
Post by: tof on Nov 27, 2009, 03:49 pm
Quote
Is it possible to use this library also on Serial1, Serial2 etc.


Yes. You simply feed byte process(int serialData) with the serial data of the port you wish to parse. Please note that will also need one instance of the Messenger class for every port.
Title: Re: Messenger library
Post by: rasc1234 on Nov 28, 2009, 11:50 am
Hi,
Thank you for indicating what needs to be done - I will answer back if this worked for me
Ralph
Title: Re: Messenger library
Post by: rasc1234 on Nov 28, 2009, 09:27 pm
I see what you mean - this was really not a too clever question of mine...

Thank you for providing this very useful library!
Title: Re: Messenger library
Post by: jeff_witz on Nov 30, 2009, 10:12 pm
Hello,

Could you develop the advantage of your solution compared with the bitlash one ?
Bitlash runs on 168 and allows one to dial with serial term as easily as :

i=3; while i<=8: pinMode(i,1); digitalWrite(i,1); i++

It allows the macro too.

Regards
Title: Re: Messenger library
Post by: tof on Dec 01, 2009, 01:35 am
Quote
Could you develop the advantage of your solution compared with the bitlash one ?


Well it is not a shoving match against messenger and bitlash that's for sure! If you read the start of the thread, you will see I was looking for a [glow]light weight[/glow] communication solution. Bitlash is not lightweight (takes up almost all the memory on a tamega168) and is not a simple communication protocol but a complete shell. Messenger is lightweight and very simple to implement.

Title: Re: Messenger library
Post by: tof on Dec 01, 2009, 03:27 pm
Two string handling functions have been added to Messenger. Check them out here:
http://www.arduino.cc/playground/Code/Messenger
Title: Re: Messenger library
Post by: swalehm on Dec 02, 2009, 04:56 pm
Hi

Excellent library I must say. Thanks for it. I am having some troubles trying to use Serial1 on the Arduino Mega. I basically took the example that is provided and changed Serial to Serial1. Can anyone take a look at my code below and help me please?

Code: [Select]
#include <Messenger.h>
// Instantiate Messenger object with the default separator (the space character)
Messenger message = Messenger();

// Create the callback function
void messageReady() {
   int pin = 10;
      // Loop through all the available elements of the message
      while ( message.available() ) {
     // Set the pin as determined by the message
        digitalWrite( pin, message.readInt() );
        pin=pin+1;
     }
}


void setup() {
 // Initiate Serial Communication
 Serial1.begin(9600);
 Serial.begin(9600);
 // Attach the callback function to the Messenger
 message.attach(messageReady);
}


void loop() {
 // The following line is the most effective way of using Serial and Messenger's callback
 while ( Serial1.available() )  message.process(Serial1.read () );
}

Title: Re: Messenger library
Post by: tof on Dec 02, 2009, 06:02 pm
I can only help you if you describe what are the troubles you are experiencing.
Title: Re: Messenger library
Post by: swalehm on Dec 02, 2009, 06:09 pm
oops sorry I should have explained.. Well really it just doesn't work. when i used the default Serial it did light up the LED on pin 13 upon entering the following text
"1 1 1 1 1 1 1 1 1 1 1 1 1" followed by Enter. However as soon as i switch the Serial to Serial1. nothing happens. I can enter a million "1 1 1" followed by enter but the LED does not light up. I hope i have explained myself well. if you need any further details please do let me know

Thanks
Swalehm
Title: Re: Messenger library
Post by: tof on Dec 02, 2009, 06:13 pm
Well, the way you set up your code, Messenger processes messages comming in through Serial1. You therefore have to send the messages to Serial1 instead of Serial. What external circuitry are you using to do so?
Title: Re: Messenger library
Post by: swalehm on Dec 02, 2009, 06:26 pm
When i change my code to serial then it uses the on board FTDI chip and it works. however on the other port i have a MAX233 chip which works fine because when I run the monitor I can see what the Arduino Mega is sending out(Serial.println). it just doesn't seem to pick up what I send to it through the serial monitor

I appreciate your assistance.
Title: Re: Messenger library
Post by: tof on Dec 02, 2009, 06:43 pm
I am sorry, I still do not understand your configuration.
The Arduino Mega is plugged into your computer's USB (that is Serial).
You have a MAX233 plugged into RX1, TX1 (Serial1). So you generate RS-232 level communication with the chip and that is plugged where? What is connected on the other side of the MAX233?

Quote
MAX233 chip which works fine because when I run the monitor I can see what the Arduino Mega is sending out(Serial.println)

Which monitor? The Arduino IDE's? Doesn't it only work with RX,TX and Serial? Do you mean you are echoing something like:
Code: [Select]
Serial.print(Seria1.read());
So how are you sending data to Serial1?
Title: Re: Messenger library
Post by: swalehm on Dec 02, 2009, 06:47 pm
The second serial port is connected to the Serial port of a Computer. and I am running tera term pro(as a serial monitor). eventually I would like to have Processing(www.processing.org) send out stuff to the Arduino but that would be at a later stage. so for now I have connected Serial1 to the computer via a MAX233 chip. My apologies for not explaining myself well.
Title: Re: Messenger library
Post by: tof on Dec 02, 2009, 07:14 pm
Ok, so you are sending messages from tera term pro to Serial1.

You know the link works because you have tested it with some code like:
Code: [Select]
while  (Serial1.available() ) Serial.print(Serial1.read());
that lets the Arduino IDE's Serial Monitor echo whatever you send from tera term pro.

Are you sure that tera term pro is sending carriage returns? Carriage returns must be sent to terminate a message.

Please test the following code. Send either a "0" or a "1" followed by a carriage return to either Serial or Serial1. A 1 will turn on the LED at pin 13, a 0 will turn it off. Also, all data received by Serial will be echoed to Serial1, and the opposite is also true.

Code: [Select]
#include <Messenger.h>

Messenger message = Messenger();
Messenger message1 = Messenger();


void messageReady() {
      while ( message.available() ) {
     // Set the pin as determined by the message
        digitalWrite( 13, message.readInt() );
     }
}

void messageReady1() {
      while ( message1.available() ) {
     // Set the pin as determined by the message
        digitalWrite( 13, message1.readInt() );
     }
}


void setup() {
 // Initiate Serial Communication
 Serial1.begin(9600);
 Serial.begin(9600);
 // Attach the callback function to the Messenger
 message.attach(messageReady); // Serial
 message1.attach(messageReady1); //Serial1
}


void loop() {
 int data;
 
 // Serial1
 while ( Serial1.available() ) {
   data = Serial1.read ();
   Serial.print(data,BYTE); // Echo data on other port
   message1.process(data); // Process data
 }
 
 // Serial
 while ( Serial.available() ) {
   data = Serial.read ();
   Serial1.print(data,BYTE); // Echo data on other port
   message.process( data ); // Process data
 }
 
 
}


Please report any and all error messages that this code generates. Please also include what is received by both serial monitors.
Title: Re: Messenger library
Post by: swalehm on Dec 02, 2009, 07:32 pm
I tried the code that you posted. The results were:
- No error message

- So i had 2 monitors open. One was monitoring "Serial"(USB) and the other was monitoring "Serial1". When i type into "Serial" it turned the LED on and off the way it was supposed to. and the "Serial1" monitor would also echo back whatever i typed with absolutely no problems. however when i type into "Serial1" nothing happens to the LED and Nothing is echoed back on the "Serial" monitor

Title: Re: Messenger library
Post by: tof on Dec 02, 2009, 07:39 pm
Hi,

to me this confirms that the problem is not with Messenger but with your input/output of Serial1.

The echo is not part of Messenger and should work without it. Check your connections and make sure that whatever you send to Serial1 is echoed to Serial. Once you have a solid bi-directional communication between both (that both monitors echo the other), you can try to add Messenger.
Title: Re: Messenger library
Post by: swalehm on Dec 02, 2009, 10:39 pm
Hi.. TOF!!!!!!!

Thanks a lot for your help.. it turns out that the MAX233 was just working one way the other direction was faulty.. i replaced the chip and it works awesomeee!!!

Thanks again for the help and thanks to whoever made the library..

Regards,
Maysam
Title: Re: Messenger library
Post by: yair on Dec 06, 2009, 05:31 pm
thanks for the lib,
the example supplied with ver 1.4 is for outputing values from the arduino which if i understand not what messanger is about, right?

"Messenger only provides methods for incoming messages. The internal Serial.print() functions work just fine for outgoing messages."
Title: Re: Messenger library
Post by: tof on Dec 06, 2009, 06:25 pm
You are right.
Messenger only provides methods for incomming messages. The examples demonstrates how to receive messages with Messenger's messageCompleted() callback function but also demonstrates how to send messages so they can be parsed with the matching Messenger libraries for Max or Processing.
Title: Re: Messenger library
Post by: yair on Dec 06, 2009, 06:47 pm
i might be missing something there, the comment of the example im refering to is
Code: [Select]
This example parses a message that contains the values
of an Arduino's analog inputs and displays them as rectangles.
The message must be composed of the readings of the 6 inputs.
Each readingis separated by a space (' ') and terminated
by a carriage return and line feed


is there somehwere an example with processing>arduino communication. i tried using the simpleMessage examples but that didnt work. those messanger support the simpleMess protocol
Code: [Select]
r a -> read analog pins
r d -> read digital pins
w d [pin] [value] -> write digital pin
w a [pin] [value] -> write analog pin

Title: Re: Messenger library
Post by: yair on Dec 06, 2009, 10:15 pm
as a matter of fact i thinkn all this software protocols between arduino and the computer are bad education. i searched for serial.flush() and was directed to http://todbot.com/blog/2009/07/30/arduino-serial-protocol-design-patterns/, i think this is the direction should go.
tommorow i have to explain conditions to a seeduino mega and a processingxp

this looks so shinny, waht does it do?
Code: [Select]

Beside the 2 following improvements:

 1. define the variables as unsigned char

    unsigned char rx_buffer_head = 0;
    unsigned char rx_buffer_tail = 0;

 2. use the following code to wrap the values

    rx_buffer_tail = rx_buffer_tail + 1;
    rx_buffer_tail %= RX_BUFFER_SIZE;

 3. Tweak buffer size for your application.

what else can be done to improved the performance of Hardware Serial?  I am stuck using 4800 baud

thanx

Mart
Title: Re: Messenger library
Post by: tof on Dec 07, 2009, 05:55 pm
Hi Yair,

I will try to understand your posts as best as I can.
The Processing example supplied with the Messenger library works very with the Arduino example provided.

Quote
I might be missing something there, the comment of the example im refering to is [...] is there somehwere an example with processing>arduino communication. i tried using the simpleMessage examples but that didnt work. those messanger support the simpleMess protocol


As stated in Messenger's documentation (http://www.arduino.cc/playground/Code/Messenger): All of your host software code that you designed for SimpleMessageSystem should still be compatible with Messenger. You will simply have to modify your Arduino code.

So you need to modify the Arduino code to match the software code.

I think the simplest solution for you would be to use Firmata (try my version here (http://132.208.118.245/~vitamin/tof/pmwiki/uploads/Arduino/firmata.zip))

Also check this  post out.
(http:// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1260203792/0#0)
Title: Re: Messenger library
Post by: yair on Dec 07, 2009, 06:17 pm
im using a mega, which is unsupported (the changelog tells it does, everyone else it doesnt).
thanks for your support, i will have to warp my head around bytes eventually. i think its for the best.
i used some code from the previous link i mentioned and from this megaServo example (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1247570790/6#6).
Title: Re: Messenger library
Post by: tof on Dec 07, 2009, 07:26 pm
Hi,

you can try the following code (I can not test it):

Code: [Select]
#include <MegaServo.h>
#include <Messenger.h>

#define NBR_SERVOS     12        // the number of servos, up to 48 for Mega, 12 for other boards
#define FIRST_SERVO_PIN 2

MegaServo myServos[NBR_SERVOS] ; // max servos is 48 for mega, 12 for other boards

Messenger message = Messenger();


// Define messenger function
void messageCompleted() {
 
  int i = 0;
 while ( message.available() && i < NBR_SERVOS ) {
  myServos[i].write(message.readInt());
  i++;
 }
 
}

void setup()
{
 Serial.begin(115200);
 message.attach(messageCompleted);
 
 
 for(int i=0; i < NBR_SERVOS; i++)
   myServos[i].attach(FIRST_SERVO_PIN +i);  
}


void loop()
{
 
 while ( Serial.available( ) ) message.process(Serial.read( ) );
 
 
}  
 


From you host software, send something like the following ascii message (they are not bytes but string representations of the numbers):
"123 84 39 128 274 50 100 543 83 43 100 101"

Where each number corresponds to the position for the servo at that index (first number for first servo, etc). Do not forget to terminate the message with a carriage return!
Title: Re: Messenger library
Post by: swalehm on Dec 10, 2009, 11:34 pm
Hi..

its me again.. i mhaving a different problem this time.. I am trying to control a couple servos through processing.. i send an ascii string as follows to the arduino "int1 int2 int3 int4 int5 int6" and then a carriage return. i receive them and store them in an array i display the array on the LCD.. the trouble is that every so often the first elements and other elements get mixed up and that cause my servos to twitch.. do you know of a fool proof method of receivin an array of integers that would guarantee that the first number received is stored in the first element in the array.??

Thanks
Swalehm
Title: Re: Messenger library
Post by: yair on Dec 11, 2009, 10:27 am
Swamlehm, i suggest you take a look at this code here (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1247570790/6#6).
its not using any lib for communication but rather let you take care of protocol.
it might seem a bit to "cody" at first but it lets you set a value to an array index with a simple
"90a will write a value of 90 to the first servo,   180b will write 180 to the second servo"
i guess you can also adapt messanger to use this.

if you want to continue sending an array its best not to swamp the buffer with to many calls (slow the pace, simple) or devise a start/stop bit rutine to handle only valid packets (hardish).
Title: Re: Messenger library
Post by: tof on Dec 11, 2009, 03:11 pm
swalehm, please post your code. There can be many reasons for this behavior and there are many ways you can implement a simple integrity check. Please aslo post the software and OS you are using.
Title: Re: Messenger library
Post by: matteo.malosio on Jan 05, 2010, 09:00 am
Fantastic library! I'm using it to exchange data with a servocontroller class. In order to set encoder ratio, from impulses to real world coordinates, I added this simple extension method to the class.


in messenger.cpp
Code: [Select]

double Messenger::readDouble() {
     if (next()) {
           dumped = 1;
           return atof(current); // atof for double instead of atoi for int variables
     }
     return 0;
}



in messenger.h
Code: [Select]

 double readDouble();


Thanks for your great job!
Title: Re: Messenger library
Post by: jermsv1 on Jan 09, 2010, 06:58 pm
hello,

just wondering if you could tell me the paths for the files in the zip into my Processing sketchbook library and any other?

would like to switch to this

thanks
jeremy
Title: Re: Messenger library
Post by: ndudman on Jan 12, 2010, 06:55 pm
Great library, thanks very much for sharing this...

I've added a few things in my own class CmdMessenger which extend from Messenger. Had to make a few small changes to the origional Messenger which I've included here along with my CmdMessenger class if its useful to anyone else.

Basicly with CmdMessenger sub class you can attach more than 1 messenger handler, which get called according to the first string (cmd) in a message. If a valid message for the command hasn't been attached then the single default message handler of Messenger is called.

http://www.arduino.cc/playground/uploads/Code/CmdMessenger.zip

The zip file contains the orgional Messenger with my small changes, the new CmdMessenger class and two sample programs (one runs on Arduino the other on a TouchShieldSlide) connected via hardware Serial1. If your using softwareSerial, which dosn't have the Serial.available() method then you will need to change the feedinSerialData() mehod.



Neil
Title: Re: Messenger library name parsing
Post by: Christopher Overstreet on Jan 21, 2010, 11:57 pm
Not very experienced with Java.  I am a maxmsp whiz.  This library seems like what I want (firmata is too bloated), but maybe it can't do this?

I just want to route messages, like in the example but parse numbers that follow the message name.  ie  send a value over max-messanger like this:

dimmer1 $1
dimmer2 $1

Sorry if this is obvious.
Title: Re: Messenger library
Post by: thijs.koerselman on Jan 24, 2010, 02:13 pm
I started using the library with the message callback function similar to the one from the examples (CheckString):

Code: [Select]
void messageCompleted() {
 // This loop will echo each element of the message separately
 while ( message.available() ) {
   if ( message.checkString("on") ) {
     digitalWrite(13,HIGH);
   } else if ( message.checkString("off") ) {
     digitalWrite(13,LOW);
   }
 }
}


I found out that there is one danger with this. It you sent any message that doesn't match the strings which you are checking against, you get stuck in an endless while loop, because the message is never removed from the stack.

This problem became apparent when i was using 2 modules communicating with XBee on the same network. They both listen to different messages and so every message would get either one of hem to hang.

I solved this by simply adding an
Code: [Select]

else{
message.readInt();
}

at the end of the function. This way if the message doesn't match with any of the strings, it is removed and the loop continues with the next.

It would be helpful if this caveat is mentioned in the examples. Maybe  it would be elegant to have an explicit method for skipping an element in the message stack?





Title: Re: Messenger library
Post by: thijs.koerselman on Jan 30, 2010, 01:52 am
I'm trying to use the Messenger library in Processing.

First of all I'm missing the string functions, I guess they're just not implemented yet?

So I want to match strings, or at least combinations of ascii characters manually. It seems so simple but I cannot figure it out.

I want to match something like "BFOO". The only way to access these characters seems to be readChar(). The first call returns 'B', but then the rest seems to be thrown away, and I don't know how to get to the remaining characters.

The reference says:
Quote

char readChar()

Returns the element as a character. If the character is part of a word, the whole word is removed from the completed message.


So this seems to be correct, but I don't understand the idea behind it. How is that useful, and how can I access those other characters?

Title: Re: Messenger library
Post by: steven-b on Mar 08, 2010, 04:09 am
I'm having trouble sending out a array of values from Processing to Arduino. Can anyone guide on how to do this?

Can this library even do this?

Thanks!
Title: Re: Messenger library
Post by: tof on Mar 08, 2010, 02:07 pm
As usual, could you be more specific and provide an example?
What are the specifics or the array sent? Size, update speed, data size, etc...
Title: Re: Messenger library
Post by: basuraman on Mar 24, 2010, 12:45 am
hello!

i am trying to use Messenger to receive a 2d array from my PC. the message looks like this:

2,3,4 32,0,0, 3,16,16....<<60 more sets like this>>...32,32,32 [crg rtrn]

Messenger reads this in copyString seems to work, but when i try to access the stored Message as an array, i can only seem to access it as one long character string.

i thought the [space] character broke the incoming string into Elements (of an array) - is this not the case?

if it IS the case...how do i go about finding the individual space-separated groups once i copy the incoming message?

or am i missing something? maybe i have to build my own array of character arrays?

any thoughts? i can post an example if it would help..

thanks!
-josh
Title: Re: Messenger library
Post by: tof on Mar 24, 2010, 02:49 am
Quote
i thought the [space] character broke the incoming string into Elements (of an array) - is this not the case?


The space character does break the string into elements... but your example "2,3,4 32,0,0, 3,16,16.." shows commas and not strings as separators. You can configure Messenger to work with commas instead if you wish.

Even if you sent  "2 3 4 32 0 0 3 16 16...", you could not use copyString to retrieve the individual elements (because copyString copies everything as a string as its name implies). You would  use readInt instead to read each integer separately.
Title: Re: Messenger library
Post by: basuraman on Mar 24, 2010, 03:00 am
ah! yes - sorry for the confusion ...

i suppose some background of my larger project would be helpful...

i've built an RGB LED Matrix and found some code to write colors to each of 64 LEDs. it works great, but now i would like to send constantly updated color values from my PC to display on the matrix LEDs. i though it would be best to send them as a group of 64 at a time - a whole '64 pixel frame' if you will..

SO, my message actually contains spaces AND commas:
2,3,4  -space-  32,0,0 -space-  etc.  

so each element is supposed to be a 3 value set of integers. once i have these sets in an array, i want to parse them using the commas and probably strtok_r.  so, basically i am hoping to store a 2 dimensional array from Messenger. still possible?

thanks!
Title: Re: Messenger library
Post by: tof on Mar 24, 2010, 04:14 pm
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];
 */
 
}
Title: Re: Messenger library
Post by: basuraman on Mar 24, 2010, 10:59 pm
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!
Title: Re: Messenger library
Post by: diode on Mar 25, 2010, 03:51 pm
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!
Title: Re: Messenger library
Post by: firestormxvii on Apr 19, 2010, 06:03 pm
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.
Title: Re: Messenger library
Post by: tof on Apr 19, 2010, 09:18 pm
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');
 

 
}
Title: Re: Messenger library
Post by: sts on May 05, 2010, 04:01 am
Hi!

I am communicating between PC and Arduino using your messenger protocol and so far it is great. But now I am trying to send a whole text-array and found something strange:
Whenever I send a message from PC to Arduino that has 64 or more characters the message gets lost. Just so you can have some fun looking at my 'totally awesome' coding skills, here is what I'm using:

Code: [Select]

void messageCompleted() {
 // This loop will echo each element of the message separately
 byte i;
 byte j;
 while ( message.available() ) {
   message.copyString(MsgrString,MAXSIZE);
   // Serial.print(MsgrString); // Echo the string
   // Serial.println(); // Terminate the message with a carriage return
   
   if (!strcmp(MsgrString,"?")) {            // Somebody wants us to SEND data
     while ( message.available() ) {
       message.copyString(MsgrString,MAXSIZE);
       // Serial.print(MsgrString); // Echo the string
       // Serial.println(); // Terminate the message with a carriage return
     
       if (!strcmp(MsgrString,"RoomName")) {            // We need to send the RoomName array
         //Serial.println("Sending RoomName array");
         for (i=0; i<8; i++){
           //Serial.print(i, DEC);
           Serial.print(RoomName[i]);
           Serial.print(" ");
           
         }
         Serial.println();
       }
       if (!strcmp(MsgrString,"Mode")) {            // We need to send the Mode byte
         //Serial.println("Sending Mode");
         Serial.print("Mode=");
         Serial.println(Mode, DEC);
       }        
     }
   }
   
   if (!strcmp(MsgrString,"!")) {            // Somebody wants us to RECEIVE data
     while ( message.available() ) {
       message.copyString(MsgrString,MAXSIZE);
       //Serial.print(MsgrString); // Echo the string
       //Serial.println(); // Terminate the message with a carriage return
     
       if (!strcmp(MsgrString,"RoomName")) {            // We need to receive the RoomName array
         //Serial.println("Receiving RoomName array");
         i=0;
         while ( message.available() ) {
           message.copyString(MsgrString,MAXSIZE);
           //Serial.print(MsgrString); // Echo the string
           //Serial.println(); // Terminate the message with a carriage return
           for (j=0; j<10; j++){
             RoomName[i][j] = MsgrString[j];
           }
           Serial.print(i, DEC);
           //Serial.println(RoomName[i]);
           i++;
         }
         Serial.println("RoomName array:");
         for (i=0; i<8; i++){
           Serial.print(i, DEC);
           Serial.print(" ");
           //Serial.println(RoomName[i]);
         }
       }
       else if (!strcmp(MsgrString,"Mode")) {            // We need to receive the Mode byte
         while ( message.available() ) {
           Serial.println("receiving Mode");
           Mode = message.readInt();
           Serial.print("I received: ");
           Serial.println(Mode, DEC);
         }
       }
     }
   }        
 }


Is there a 64 character limitation? Or is the problem somehow on my side?

BTW: MAXSIZE is 255.

Thanks for a great library!

Stefan
Title: Re: Messenger library
Post by: Beankyu on May 05, 2010, 04:53 am
I find find it really helpful :)
Title: Re: Messenger library
Post by: sts on May 05, 2010, 10:49 pm
Never mind about the 64 character limit. I found the offending code after all of about 30 seconds search. Sometimes using your own eyes is perfectly sufficient!

Code: [Select]
#define MESSENGERBUFFERSIZE 64

changed to

Code: [Select]
#define MESSENGERBUFFERSIZE 128

duh!
Title: Re: Messenger library
Post by: kasperkamperman.com on May 14, 2010, 12:13 am
Hi, just for your information.

I've made a description in how to send serial data from and to Flash with the Messenger library. The file can be used with the basic_communication sketch in the Messenger library examples folder.
http://
http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/.

Title: Re: Messenger library
Post by: mikemikemike on May 14, 2010, 03:15 am
Im new to arduino and loving it!
Title: Re: Messenger library
Post by: luke123 on Jul 19, 2010, 10:02 pm
Hey thanks for posting this library !  Im having a problem though ..


Using the example checkstring  I can turn the led on and off fine :)  but if i type some random letters ect it will confuse it and will stop it working totally the next time i type "on" ect.

I need this to ignore anything other than "on" or "off" ect ?







Code: [Select]
// This example demonstrates Messenger's checkString method
// It turns on the LED attached to pin 13 if it receives "on"
// It turns it off if it receives "off"


#include <Messenger.h>


// Instantiate Messenger object with the message function and the default separator
// (the space character)
Messenger message = Messenger();


// Define messenger function
void messageCompleted() {
 // This loop will echo each element of the message separately
 while ( message.available() ) {
 
 
   
 
 
   if ( message.checkString("on") ) {
     digitalWrite(13,HIGH);
   } else if ( message.checkString("off") ) {
     digitalWrite(13,LOW);
   }
 }
 
 
}

void setup() {
 // Initiate Serial Communication
 Serial.begin(115200);
 message.attach(messageCompleted);
 
 pinMode(13,OUTPUT);
 
}

void loop() {
 
 // The following line is the most effective way of
 // feeding the serial data to Messenger
 while ( Serial.available() ) message.process( Serial.read() );


}// This example demonstrates Messenger's checkString method
// It turns on the LED attached to pin 13 if it receives "on"
// It turns it off if it receives "off"


#include <Messenger.h>


// Instantiate Messenger object with the message function and the default separator
// (the space character)
Messenger message = Messenger();


// Define messenger function
void messageCompleted() {
 // This loop will echo each element of the message separately
 while ( message.available() ) {
 
 
   
 
 
   if ( message.checkString("on") ) {
     digitalWrite(13,HIGH);
   } else if ( message.checkString("off") ) {
     digitalWrite(13,LOW);
   }
 }
 
 
}

void setup() {
 // Initiate Serial Communication
 Serial.begin(115200);
 message.attach(messageCompleted);
 
 pinMode(13,OUTPUT);
 
}

void loop() {
 
 // The following line is the most effective way of
 // feeding the serial data to Messenger
 while ( Serial.available() ) message.process( Serial.read() );


}
Title: Re: Messenger library
Post by: LAVco on Jul 22, 2010, 06:25 pm
This library came in handy for me and thought that I would share a nifty function addition (checkSubString).

In this project's case the serial port is used to send data and to receive poll and configuration settings commands.

For example;

Poll Commands (e.g. send a poll command to Arduino to receive data from a client computer over serial):
M0!
where:
- M0 is message type 0

M1!
where:
- M1 is message type 1


Configuration Settings:
SET01nn
where:
- nn set the sample interval in seconds (01-60)
.
.
.
SET08nn
where:
- nn = 96 sets the serial port's baud-rate to 9600
- nn = 38 sets the serial port's baud-rate to 38400

Code: [Select]

Messenger.h (Public)
uint8_t checkSubString(char *subString, char *string, uint8_t length);

Messenger.cpp
// alpha implementation, may be a more efficient method
// instead of calling strncpy
uint8_t Messenger::checkSubString(char *subString, char *string, uint8_t length) {
     if (next()) {
           if ( strcasestr(subString,current) == 0 ) {
                 // return remaining chars after subString
                 int nChars = strlen(current) - strlen(subString);
                 strncpy(string, current + strlen(subString), nChars);
                 string[nChars] = '\0';
                       if ( strlen(string) > length ) return 0;
                 dumped = 1;
                 return 1;
           } else {
                 return 0;
           }
     }
}


Here is a usage example - simply add the following snippet example to the checkString example.

Code: [Select]

char buffer[32]; // global buffer


   } else if ( message.checkString("M0!") ) {
      // send message 0 data
   } else if ( message.checkSubString("SET01", buffer, 2) ) {
     Serial.print("Sample Interval: ");
     Serial.println(buffer);
    //
    // store sample interval...
   } else if ( message.checkSubString("SET08", buffer, 2) ) {
     Serial.print("Baud-Rate: ");
     Serial.println(buffer);
    //
    // store serial port baud-rate..
   } else {
     return;
   }


Enjoy!

Eric




Title: Re: Messenger library
Post by: LAVco on Jul 22, 2010, 06:31 pm
Hey luke123

Take a look at my post.  Simply add an "else" statement to return if no matches are found.

Cheers..

Eric
Title: Re: Messenger library
Post by: LAVco on Aug 01, 2010, 05:17 pm
Update to my previous post for checkSubString.

Code: [Select]

uint8_t Messenger::checkSubString(char *subString, char *string, uint8_t length) {
     if (next()) {
           //if ( strcasestr(subString,current) == 0 ) {
           if ( strstr(current, subString) != NULL ) {
                 // return remaining chars after subString
                 int nChars = strlen(current) - strlen(subString);
                 strncpy(string, current + strlen(subString), nChars);
                 string[nChars] = '\0';
                 if ( strlen(string) > length ) return 0;
                 dumped = 1;
                 return 1;
           } else {
                 return 0;
           }
     }
}


Cheers,

Eric
Title: Re: Messenger library
Post by: lorenzop on Aug 02, 2010, 08:44 am
I'm having some trouble with bad commands. the correct commands for my project work great, but if I enter a command wrong it seems to lock up and the pin 13 led comes on. my code is still pretty simple and I don't see how it could cause this, and I don't see how the library could do it directly either. could it be an overflow someplace?

here's my code
http://download.growcontrol.com/arduino/usbmessenger.pde
Title: Re: Messenger library
Post by: novice on Aug 02, 2010, 12:51 pm
Hi tof,

I can see a lot of potential for this library.
Thanks for your efforts.
Title: Re: Messenger library
Post by: david.vondle on Aug 02, 2010, 08:48 pm
in the examples you may consider changing:
#include <Messenger.h>
to
#include "Messenger.h"

to enable people to simply place the .h file in the sketch's directory
Title: Re: Messenger library
Post by: lorenzop on Aug 03, 2010, 08:05 pm
is there a proper way to handle command errors or a proper way to reset or clear?
Title: Re: Messenger library
Post by: lorenzop on Aug 04, 2010, 05:07 am
I think I fixed the problem. it took me forever to trace down the actual root, and it turns out pretty simple.

in the example basic_communication, I change line 21:
 while ( message.available() ) {
to this:
 if(messenger.available()){

this seems to fix my problems. no more lock ups caused by an endless loop. the incoming serial data is sent to the messenger class one character at a time anyway, so it can never have 2 separate commands in buffer at the same time. so no need to use a "while" loop.
Title: Re: Messenger library
Post by: tangle78 on Aug 13, 2010, 05:31 am
many many many ......millions of thianks.
this library have help me to solve a big trouble.
Title: add readDouble and readFloat functions
Post by: auger-f on Aug 26, 2010, 12:15 pm
Dear all,

I have added a readDouble function inside the Messenger library, for my own needs. For this, I have added the following line
double readDouble();
in Messenger.h, right after the int readInt();
Then I added the following function in Messenger.cpp
double Messenger::readDouble() {

   if (next()) {
         dumped = 1;
         return atof(current);
    }
 return 0;
}

The same thing could be done for floats.
Best regards,

Title: Re: Messenger library
Post by: lorenzop on Aug 28, 2010, 11:47 pm
I have a question. can I include the library in the zip I'm posting for my project? I'd like to package the .h and .cpp files with my code. I'd like to do this to make it easier for people to use my project, and in case there are any changes to the library that might break my code, so I can fix it before releasing a new package. is this ok to do?
Title: Re: Messenger library
Post by: pharaohamps on Aug 29, 2010, 02:27 am
I would also like to thank the author for this library - I have been able to implement a much more sophisticated command handling protocol to my project with this library.  I was using a switch case before and it was murder.

Thanks!
Title: Re: Messenger library
Post by: nofxx on Aug 30, 2010, 12:17 am
Great stuff... to make it lil better for my needs I created a fork on github:

http://github.com/nofxx/Messenger

Dunno if the author is still around but you create yours there I'll dump mine and fork.  Thank you.
Title: Re: Messenger library
Post by: supertwang on Oct 21, 2010, 05:31 am
Hi everyone.

Can anyone point me at a url, or other source, showing Messenger being used in a Max patch?  I am new to Max and can't figure out what kind of message it is expecting at its input.  Thanks!

ST
Title: Re: Messenger library
Post by: agdemars on Oct 28, 2010, 04:42 pm
I added this line to the Messenger.cpp file so that I could use the serial port monitor to enter commands:

     case 13: // CR
     case ';':  // to enable serial port monitor use
         buffer[bufferIndex]=0;

It also allows you to enter multiple commands separated by a ';' on the same line.

You must end each command and each line with a ';' when using the Arduino serial port monitor.

It is NOT necessary to append a ';' if you are sending a CR (ie using a standard terminal emulator or from a Processing sketch).

Adding this line implies that your Messenger commands can't have ';' in them...
Title: Re: Messenger library
Post by: lyncos on Nov 07, 2010, 10:10 pm
Hi,
   I'm having trouble to compile your code with my Makefile, it's working fine with the Arduino IDE but not with my command line Makefile, I'm unable to find out why and would like little help.

Here's the error message I got

Code: [Select]
/usr/bin/avr-gcc -Os -lm -lgcc -Wl,--gc-sections -mmcu=atmega1280 -o applet/test.elf applet/test.o applet/core.a
/usr/lib/gcc/avr/4.3.5/../../../avr/lib/avr51/libc.a(cmpsf2.o):../../../libm/fplib/cmpsf2.S:58: multiple definition of `__ltsf2'
/usr/lib/gcc/avr/4.3.5/avr51/libgcc.a(_lt_sf.o):(.text+0x0): first defined here
make: *** [applet/test.elf] Error 1



And here is my Makefile

Code: [Select]
# $Id$

TARGET = $(notdir $(CURDIR))
INSTALL_DIR = $(HOME)/Desktop/arduino-0018
PORT = /dev/ttyUSB0
UPLOAD_RATE = 57600
#UPLOAD_RATE = 19200

AVRDUDE_PROGRAMMER = stk500v1
#MCU = atmega328p
#MCU = atmega168
MCU = atmega1280

F_CPU = 16000000

############################################################################
# Below here nothing should be changed...

VERSION=18
ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
#AVR_TOOLS_PATH = $(INSTALL_DIR)/hardware/tools/avr/bin
AVR_TOOLS_PATH = /usr/bin
AVRDUDE_PATH = $(INSTALL_DIR)/hardware/tools
C_MODULES =  \
$(ARDUINO)/wiring_pulse.c \
$(ARDUINO)/wiring_analog.c \
$(ARDUINO)/pins_arduino.c \
$(ARDUINO)/wiring.c \
$(ARDUINO)/wiring_digital.c \
$(ARDUINO)/WInterrupts.c \
$(ARDUINO)/wiring_shift.c \
$(INSTALL_DIR)/libraries/Wire/utility/twi.c \
$(INSTALL_DIR)/libraries/etherShield/ip_arp_udp_tcp.c \
$(INSTALL_DIR)/libraries/etherShield/enc28j60.c
# end of C_MODULES

CXX_MODULES = \
$(ARDUINO)/main.cpp \
$(ARDUINO)/WMath.cpp \
$(ARDUINO)/Print.cpp \
$(ARDUINO)/HardwareSerial.cpp \
$(INSTALL_DIR)/libraries/OneWire/OneWire.cpp \
$(INSTALL_DIR)/libraries/Wire/Wire.cpp \
$(INSTALL_DIR)/libraries/EEPROM/EEPROM.cpp \
$(INSTALL_DIR)/libraries/LiquidCrystal/LiquidCrystal.cpp \
$(INSTALL_DIR)/libraries/Spi/Spi.cpp \
$(INSTALL_DIR)/libraries/Mirf/mirf.cpp \
$(INSTALL_DIR)/libraries/Time/Time.cpp \
$(INSTALL_DIR)/libraries/TimeAlarms/TimeAlarms.cpp \
$(INSTALL_DIR)/libraries/DS1307RTC/DS1307RTC.cpp \
$(INSTALL_DIR)/libraries/Tone/Tone.cpp \
$(INSTALL_DIR)/libraries/etherShield/etherShield.cpp \
$(INSTALL_DIR)/libraries/Messenger/Messenger.cpp \


# end of CXX_MODULES

CXX_APP = applet/$(TARGET).cpp
MODULES = $(C_MODULES) $(CXX_MODULES)
SRC = $(C_MODULES)
CXXSRC = $(CXX_MODULES) $(CXX_APP)
FORMAT = ihex


# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile

# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
#DEBUG = stabs
DEBUG =

OPT = s

# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(VERSION)
CXXDEFS = -DF_CPU=$(F_CPU)L -DARDUINO=$(VERSION)

# Place -I options here
CINCS = -I$(ARDUINO) -I$(INSTALL_DIR)/libraries/Wire -I$(INSTALL_DIR)/libraries/Wire/utility -I$(INSTALL_DIR)/libraries/OneWire -I$(INSTALL_DIR)/libraries/DS1307 -I$(INSTALL_DIR)/libraries/EEPROM -I$(INSTALL_DIR)/libraries/LiquidCrystal -I$(INSTALL_DIR)/libraries/Spi -I$(INSTALL_DIR)/libraries/Mirf -I../ -I$(INSTALL_DIR)/libraries/Time -I$(INSTALL_DIR)/libraries/DS1307RTC -I$(INSTALL_DIR)/libraries/TimeAlarms -I$(INSTALL_DIR)/libraries/Tone -I$(INSTALL_DIR)/libraries/etherShield -I$(INSTALL_DIR)/libraries/Messenger

CXXINCS = -I$(ARDUINO)

# Compiler flag to set the C Standard level.
# c89   - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99   - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
#CSTANDARD = -std=gnu99
CDEBUG = -g$(DEBUG)
#CWARN = -Wall -Wstrict-prototypes
#CWARN = -Wall   # show all warnings
CWARN = -w      # suppress all warnings
####CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CTUNING = -ffunction-sections -fdata-sections
CXXTUNING = -fno-exceptions -ffunction-sections -fdata-sections
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)

CFLAGS = $(CDEBUG) -O$(OPT) $(CWARN) $(CTUNING) $(CDEFS) $(CINCS) $(CSTANDARD) $(CEXTRA)
CXXFLAGS = $(CDEBUG) -O$(OPT) $(CWARN) $(CXXTUNING) $(CDEFS) $(CINCS)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS = -O$(OPT) -lm -lgcc -Wl,--gc-sections


# Programming support using avrdude. Settings and variables.
AVRDUDE_PORT = $(PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex

#AVRDUDE_FLAGS = -V -F -C $(INSTALL_DIR)/hardware/tools/avr/etc/avrdude.conf \

AVRDUDE_FLAGS = -V -F -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \
-p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
-b $(UPLOAD_RATE)

# Program settings
CC = $(AVR_TOOLS_PATH)/avr-gcc
CXX = $(AVR_TOOLS_PATH)/avr-g++
LD = $(AVR_TOOLS_PATH)/avr-gcc
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
AR  = $(AVR_TOOLS_PATH)/avr-ar
SIZE = $(AVR_TOOLS_PATH)/avr-size
NM = $(AVR_TOOLS_PATH)/avr-nm
AVRDUDE = $(AVRDUDE_PATH)/avrdude
REMOVE = rm -f
MV = mv -f

# Define all object files.
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
OBJ_MODULES = $(C_MODULES:.c=.o) $(CXX_MODULES:.cpp=.o)

# Define all listing files.
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)

# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = $(CFLAGS) -mmcu=$(MCU)
ALL_CXXFLAGS = $(CXXFLAGS) -mmcu=$(MCU)
ALL_ASFLAGS = -x assembler-with-cpp $(ASFLAGS) -mmcu=$(MCU)
ALL_LDFLAGS = $(LDFLAGS) -mmcu=$(MCU)

# Default target.
all: applet_files build sizeafter

build: elf hex

#applet_files: $(TARGET).pde
applet/$(TARGET).cpp: $(TARGET).pde
     # Here is the "preprocessing".
     # It creates a .cpp file based with the same name as the .pde file.
     # On top of the new .cpp file comes the WProgram.h header.
     # and prototypes for setup() and Loop()
     # Then the .cpp file will be compiled. Errors during compile will
     # refer to this new, automatically generated, file.
     # Not the original .pde file you actually edit...
     test -d applet || mkdir applet
     echo '#include "WProgram.h"' > applet/$(TARGET).cpp
     echo 'void setup();' >> applet/$(TARGET).cpp
     echo 'void loop();' >> applet/$(TARGET).cpp
     cat $(TARGET).pde >> applet/$(TARGET).cpp

elf: applet/$(TARGET).elf
hex: applet/$(TARGET).hex
eep: applet/$(TARGET).eep
lss: applet/$(TARGET).lss
sym: applet/$(TARGET).sym

# Program the device.  
upload: applet/$(TARGET).hex
     python ~/test.py $(PORT)
     $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)


     # Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
ELFSIZE = $(SIZE)  applet/$(TARGET).elf
sizebefore:
     @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi

sizeafter:
     @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi


# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000


coff: applet/$(TARGET).elf
     $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof


extcoff: $(TARGET).elf
     $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof


.SUFFIXES: .elf .hex .eep .lss .sym

.elf.hex:
     $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@

.elf.eep:
     $(OBJCOPY) -O $(FORMAT) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
     --no-change-warnings \
     --change-section-lma .eeprom=0 $< $@

# Create extended listing file from ELF output file.
.elf.lss:
     $(OBJDUMP) -h -S $< > $@

# Create a symbol table from ELF output file.
.elf.sym:
     $(NM) -n $< > $@

     # Link: create ELF output file from library.
#applet/$(TARGET).elf: $(TARGET).pde applet/core.a
applet/$(TARGET).elf: applet/$(TARGET).o applet/core.a
     $(LD) $(ALL_LDFLAGS) -o $@ applet/$(TARGET).o applet/core.a

applet/core.a: $(OBJ_MODULES)
     @for i in $(OBJ_MODULES); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done



# Compile: create object files from C++ source files.
.cpp.o:
     $(CXX) -c $(ALL_CXXFLAGS) $< -o $@

# Compile: create object files from C source files.
.c.o:
     $(CC) -c $(ALL_CFLAGS) $< -o $@


# Compile: create assembler files from C source files.
.c.s:
     $(CC) -S $(ALL_CFLAGS) $< -o $@


# Assemble: create object files from assembler source files.
.S.o:
     $(CC) -c $(ALL_ASFLAGS) $< -o $@


# Automatic dependencies
%.d: %.c
     $(CC) -lm -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@

%.d: %.cpp
     $(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@


# Target: clean project.
clean:
     $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
     applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/core.a \
     $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)

.PHONY:      all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter

#include $(SRC:.c=.d)
#include $(CXXSRC:.cpp=.d)



If anyone can help me it will be greatly appreciated because I'm always coding remotely in console and Arduino IDE is not an option for me.
Title: 4 integers error
Post by: prax on Nov 13, 2010, 07:17 pm


hey, i have a simple question:

Im using processing to send to arduino with messenger.
4 integers (from 0 to 1023) should be transmitted in one block in order to drive two servos.
Therefore I need the most possible speed. But the first test showed, that the communication doesn't clearly get the integers right. Using the Arduinos SerialMonitor to print the received numbers out, I get something like this (from time to time):

1000
1001
1002
100310
10
0
1002
1003

but it should look like this:
1000
1001
1002
1003
1000
1001
1002
1003

so is the transmitting-speed to fast? Or cant i use Arduinos SerialMonitor while receiving from Processing?

Any other idea how to send 4 integers very fast to arduino without any mistakes.  

big thx!
Title: Re: Messenger library
Post by: onejgordon on Nov 21, 2010, 10:38 pm
Has anyone had any success with this library and parsing larger data strings from the duino buffer?

I'm using it with the Libelium GPRS shield and it's working perfectly for short AT commands and responses, but when I try to request a data block via TCP (e.g. trying to download something like (note < 128 bytes):

CONNECT
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Expires: Fri, 01 Jan 1990 00--EOF--Pattern--
OK
+KTCP_DATA: 1,99

It seems to make arbitrary message breaks.  I'm using a rare separator like 6 (ACK) because i want to download each line of response as a separate message, and deal with them as full strings.

I wonder if the problem is my data is getting sent back with LF's instead of CRs so the library doesn't know where to break it?

Is this a totally inappropriate use of the library?

Cheers for any thoughts
Title: Re: Messenger library
Post by: redtop-arduino on Dec 10, 2010, 10:23 am
Hi,

i have an easy question. How to Install Messanger ?

Normaly i put the Folder from the Zip to libraries but when i do it with the Messanger there many subfolders an Process cant find the new Lib ?

Sorry for my bad english.

Stefan
Title: Re: Messenger library
Post by: liangnv on Dec 23, 2010, 07:22 am
it's not a shoving match against messenger and bitlash that's for sure


_____________________________

(http://www.torontothumbs.com/wp-content/uploads/2008/11/rabbid1.jpg)
ps3 wireless controller (http://www.r4king.com/dualshock-3-wireless-controller-with-bluetooth-for-ps3.html)
PS3 Game HDD (http://www.r4king.com/ps3-games-hdd.html)
PS3 Jailbreak (http://www.r4king.com/ps3-jailbreak.html)
Title: Re: Messenger library
Post by: sparker on Dec 30, 2010, 07:14 pm
I love this library, and I can see how it will make many projects easier.

I saw somewhere that you advised against using the Arduino IDE's "Serial Monitor" to test the library as it does not send a carriage return and therefore never "completes" messages.

I'm using Arduino 0021 at the moment and it allows you to choose between no line ending, Newline, Carriage return and 'Both NL and CR'. The last option seems to be OK for testing Messenger.
Title: Re: Messenger library
Post by: Boffin1 on Jan 01, 2011, 04:48 am
Hi Thomas,  this library looks very interesting, I am pretty much a  newbie.
I am soon going to try making a wireless link to send a  16 character ascii message via a celphone sms.
Each message would have a space separator, and there would be a CR at the end of the SMS transmission

Can I just run my initial idea through the forum to see if I am on the right track before I start studying the celphone protocols. ( its not a "write me the program"  request )

If I can get a celphone module to output a string of ascii characters representing the text message, could the message library output 16 bytes at a time for me to send on to a bank of 328 chip decoders ( each with its own address and processing ) ?

Or I could have each chip decode the messenger if there are enough resources - the chip has quite a large lookup table to contend with..