Messenger library

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!

nice!

Hi,

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

Thank you

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.

Hi,
Thank you for indicating what needs to be done - I will answer back if this worked for me
Ralph

I see what you mean - this was really not a too clever question of mine...

Thank you for providing this very useful library!

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

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 light weight 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.

Two string handling functions have been added to Messenger. Check them out here:
http://www.arduino.cc/playground/Code/Messenger

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?

#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 () );
}

I can only help you if you describe what are the troubles you are experiencing.

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

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?

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.

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?

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:

Serial.print(Seria1.read());

So how are you sending data to Serial1?

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.

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:

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.

#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.

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

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.

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