Pages: 1 [2] 3 4 ... 6   Go Down
Author Topic: Messenger library  (Read 21356 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
I Love Arduino!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Thomas Ouellet Fredericks

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
I Love Arduino!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Serial.print(Seria1.read());
So how are you sending data to Serial1?
Logged

Thomas Ouellet Fredericks

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
I Love Arduino!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thomas Ouellet Fredericks

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
I Love Arduino!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thomas Ouellet Fredericks

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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."
Logged

Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
I Love Arduino!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thomas Ouellet Fredericks

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i might be missing something there, the comment of the example im refering to is
Code:
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:
r a -> read analog pins
 r d -> read digital pins
 w d [pin] [value] -> write digital pin
 w a [pin] [value] -> write analog pin
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
« Last Edit: December 06, 2009, 06:25:38 pm by yair » Logged

Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
I Love Arduino!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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: 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)

Also check this post out.
Logged

Thomas Ouellet Fredericks

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: 1 [2] 3 4 ... 6   Go Up
Jump to: