Trying to read ascii data from energy system

Hi all,

I am trying to read ASCII data from my off-grid power system using the SoftwareSerial library. I am able to read data, but it seems to be well out of range from what I would expect.

Here is the sketch I'm working with.

#include <SoftwareSerial.h>

#define rxPin 3    //white pin2 on mate
#define txPin 2    //green pin3 on mate
#define dtrPin 4   //blue pin4 on mate
#define rtsPin 7   //orange pin7 on mate

// set up a new serial port
SoftwareSerial outback =  SoftwareSerial(rxPin, txPin);

int value;

void setup()  {

  Serial.begin(19200);
  // define pin modes for tx, rx:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  
  pinMode(dtrPin, OUTPUT);
  digitalWrite(dtrPin, HIGH);
  
  pinMode(rtsPin, OUTPUT);
  digitalWrite(rtsPin, LOW);
  
  // set the data rate for the SoftwareSerial port
  outback.begin(19200);
}

int i = 1;

void loop() {
  
  if (outback.available()){
    value = outback.read();    
    Serial.print("Byte ");
    Serial.print(i);
    Serial.print(": ");
    Serial.print(value);
    Serial.print(", ");
    Serial.write(value);
    Serial.println("");
    i++;
  }
}

Here is a sample of the output:

Byte 1: 189, ½
Byte 2: 179, ³
Byte 3: 218, Ú
Byte 4: 214, Ö
Byte 5: 118, v
Byte 6: 246, ö
Byte 7: 246, ö
Byte 8: 118, v
Byte 9: 246, ö
etc.....

I am connected to an Outback Mate (http://www.outbackpower.com/pdf/manuals/mate_guide.pdf). Based on the communication protocol, the first byte of transmission should be an ASCII code 10.

At first, I thought I might have a baud rate problem, but I don't think so anymore.

Any thoughts or suggestions?

Thanks, Bill

Which version of the Arduino software are you using? 0022? 1.0?

Version 1.0
Uno R3

This is interesting :slight_smile:

post more of the output

Im not seeing all the "44"'s either (the comma seperators) Ive got an FM60 that needs a good talkin to :wink:

Alright, im really a noob, but, looking at your code, i wonder if it needs some sort of interrupt -and- "get next byte" type of function to sync up the datastream the mate broadcasts every second or so.

I am also a noob. I tend to fumble through until I get the result I was hoping for. I'm hoping to parse some of the raw data so I can post my stats online -- I mostly want piece of mind when I'm away. I will post some more output in a few days. Got to head out of town for a couple if days. I'm not sure about the interrupt function. Maybe someone else will chime in.

ill keep tuned, im curious as all.. i was working on sniffing my FM60 without the mate (i would need to figure out what the mate sends to the FM60 to get it to spill its stats over the port), still may try it, but, also bought a Midnite Classic150 that uses modbus and is net ready. Working on a arduino based comprehensive SD logger for local sensors and RE equipment stats.

OutBack Mate provides an isolated RS232 port for PC communication

What are you using to convert that to inverted TTL?

Uhm...nothing. I have a Max3232 chip on the way - will keep you posted. Thanks.

OK, I finally got back to this project. I've got the Max232 installed and now I can read data, but I can't seem to get all of the data back. I think I may be running into a buffer problem. The data I'm trying to read comes from my energy system. The main controller, the Mate, communicates with 3 other components and returns a status page for each component each second. Each status page is 49 bytes, so the total length should be about 147 bytes. Unfortunately I only get data from the first component and half of the data from the second component.

Here is a sample script:

#include <SoftwareSerial.h>

#define rxPin 4   
#define txPin 5    

// set up a serial port for the outback mate
SoftwareSerial outback =  SoftwareSerial(rxPin, txPin);
int buffer = 0;

void setup()  {
  
  //set the data rate for communication with the Arduino
  Serial.begin(19200);
  
  // set the data rate for the outback port
  outback.begin(19200);
}

void loop() {
  buffer = 0;
  while (outback.available()){
    Serial.write(outback.read());
    buffer++;   
  }
  Serial.println();  
  Serial.print("Buffer must be full: ");
  Serial.println(buffer);

  delay(1000);
}

And here is what it returns.

1,01,00,00,000,120,00,02,000,00,246,008,000,027
b,0000,0000,0
Buffer must be full: 63

1,01,00,00,000,120,00,02,000,00,246,008,000,027
b,0000,0000,0
Buffer must be full: 63

There should be three lines of ascii data, one for each component. For some reason it seems to kick out of the while loop half way through the second status page.

Any ideas?

Cut-n-paste to see if this produces a different result:

#include <SoftwareSerial.h>

#define rxPin 4   
#define txPin 5    

SoftwareSerial outback =  SoftwareSerial(rxPin,txPin);

unsigned char buffer[256];
unsigned char *p,i;
unsigned x[3];

unsigned char gchr(void)
{  while (!outback.available());
   return outback.read();
}

void pstr(unsigned char *s)
{  unsigned char c;
   while (c = *s++) Serial.write(c);
}


void setup(void)
{  Serial.begin(19200);
   outback.begin(19200);
}

void loop(void)
{  x[0] = x[1] = x[2] = 0;
   p = buffer;
   for (i = 0; i < 3; i++)
   {  while ('\n' != (c = gchr())) ++x[i];
      *p++ = c;
      do
      {  *p++ = c = gchr();
      }  while ('\r' != c);
   }
   *p = '\0';
   Serial.print("Discarded: ");
   Serial.print(x[0]);
   Serial.print(", ");
   Serial.print(x[1]);
   Serial.print(", ");
   Serial.println(x[2]);
   pstr(buffer);
   Serial.println("");
}

Notice that I got rid of the delay() call in loop()...

int buffer = 0;

Are you going to store the data in an array called index, then?

    Serial.write(outback.read());

You are reading ASCII data and sending binary data. Why?

  delay(1000);

Why? If the device(s) you are listening to seem to be sending data faster than you can read it, how does this "help"?

Brilliant. Thanks a ton Morris. That's exactly what I was looking for.