Help with serial data project, using messenger library

Edited to remove bad code

My problem is that if I send an ASCII text file thru the rig and the code above, it always leaves the last data set in the buffer and does not output it. It always comes out when I send the text file again first before the new data.

How are you sending the data? Perhaps the problem is that the required CR/LF is not being transmitted for the record, so the record is not complete, as far as messenger is concerned.

I numbered them using the last characters and I also repeat the data back to the CoolTerm so I can see what is going on.

Unfortunately, we can't see what you are seeing.

Perhaps the simplest solution is to simply add a blank line to the end of the file.


You are exactly right. I had a CR but no LF because I never hit enter after the string in my text file so this record was never complete.

Works like a dream now!!!

I now have a 100% working project thanks to your help. I optimized the code and cleaned up/added the comments. Also added a splash screen and LED status indicatons. I am using a 4x20 LCD with the LCD117 board to control it. This thing works sweet!

Here is a video of it in action:

Please consider sharing your code as an example for those who find this thread resembling their problem...

Sorry, I had to tweak it and remove some info from it before I could make it public…a few places where you see ??? I have removed references to something I am not at liberty to make public.

#include <NewSoftSerial.h> //Loads the NewSoftSerial Library
#include <Messenger.h> //Loads the Messenger Library
Messenger message = Messenger(44); //Sets the delimiter to a "," but it is not needed in this case becuase there is no delimiter in the data
NewSoftSerial mySerial(15, 14); //Configures the pins used to talk to the LCD board, pin 15 is just an unused pin
#define MAXSIZE 23 //Definces the message buffer array size
char string[MAXSIZE]; //Defines string, creates the message buffer array
String stringA = 0; //Defines stringA, clears the message buffer string

void setup() 
  pinMode(13, OUTPUT); //Initialize the LED port
  delay(2000); //Gives the LCD board time to boot up
  Serial.begin(9600); //Initialize the hardware serial port
  mySerial.begin(9600); //Initialize the software serial port
  mySerial.print("?D00705070000000000"); //Set a custom character in the LCD board
  delay(300); //Delay to allow the LCD board to program
  mySerial.print("?f"); //Clear the LCD screen
  mySerial.print("?x02?y0P-Mag Ignition?x06?y1Monitor?x01?y2By: Brian Chesteen?x04?y3VERSION 1.1"); //Splash screen
  delay(6000); //Delay the splash screen
  mySerial.print("?f"); //Clear the LCD screen
  //The above sets up the fixed characters on the screen, the #'s are just placeholders till the data arrives, no sense printing all this fixed stuff each dataset
  establishContact(); //Run the routine that sends the "???" command out the hardware serial port.  This is required by the external 
  //device to start streaming data

void establishContact() //This routine sends out the "???" command over the hardware serial port until it recieves data back.  It also 
//flashes the LED while waiting for data 
  while (Serial.available() <= 0) 
    digitalWrite(13, HIGH);
    digitalWrite(13, LOW);

void loop() //This routine is what loads the ASCII stream packets into the messenger
  while ( Serial.available() ) message.process( );
  digitalWrite(13, HIGH);

void messageCompleted() 
  while ( message.available() > 0) 
    message.copyString(string,MAXSIZE); //Copies the Messenger Library packet into the string array
    Serial.print(string); //Repeat the serial message on the hardware serial port for diagnostics, comment this line out for normal use
    Serial.println(); //Print NL on hardware serial port, comment this line out for normal use
    stringA = string; //Converts the Messager Library Char array to a string so it is easy to pick what characters to display
    mySerial.print("?x04?y0"); //Position the cursor
    mySerial.print(stringA.charAt(0)); //Print RPM MSD
    mySerial.print(stringA.charAt(1)); //Print RPM
    mySerial.print(stringA.charAt(2)); //Print RPM
    mySerial.print(stringA.charAt(3)); //Print RPM LSD
    mySerial.print("?x04?y1"); //Position the cursor
    mySerial.print(stringA.charAt(4)); //Print ADV MSD
    mySerial.print(stringA.charAt(5)); //Print ADV
    mySerial.print("?x07?y1"); //Position the cursor
    mySerial.print(stringA.charAt(6)); //Print ADV LSD
    mySerial.print("?x04?y2"); //Position the cursor
    mySerial.print(stringA.charAt(7)); //Print MAP MSD
    mySerial.print(stringA.charAt(8)); //Print MAP
    mySerial.print("?x07?y2"); //Position the cursor
    mySerial.print(stringA.charAt(9)); //Print MAP 
    mySerial.print(stringA.charAt(10)); //Print MAP LSD
    mySerial.print("?x05?y3"); //Position the cursor
    mySerial.print(stringA.charAt(11)); //Print MODE MSD
    mySerial.print(stringA.charAt(12)); //Print MODE LSD
    mySerial.print("?x16?y0"); //Position the cursor
    mySerial.print(stringA.charAt(13)); //Print VOLTS MSD
    mySerial.print(stringA.charAt(14)); //Print VOLTS
    mySerial.print("?x19?y0"); //Position the cursor 
    mySerial.print(stringA.charAt(15)); //Print VOLTS LSD
    mySerial.print("?x16?y1"); //Position the cursor
    mySerial.print(stringA.charAt(16)); //Print TEMP MSD
    mySerial.print(stringA.charAt(17)); //Print TEMP LSD
    mySerial.print("?x14?y2"); //Position the cursor
    mySerial.print(stringA.charAt(18)); //Print C1 MSD
    mySerial.print(stringA.charAt(19)); //Print C1 LSD
    mySerial.print("?x14?y3"); //Position the cursor
    mySerial.print(stringA.charAt(20)); //Print C2 MSD
    mySerial.print(stringA.charAt(21)); //Print C2 LSD