Communication with smart meter using software serial 7E1 issue

Hi Guys,

I am currently trying to read my smart meter for my Hons uni project. I have already been able to read it using the RS-232 on a pc. I am now trying to code the ardunio to communicate with it.

I am initially just transmitting the sign on request message, which is 2F 3F 21 0D 0A and monitoring the output from my probe on the scope to see if the meter is responding.

The problem seems to be that i am using the UNO and hence have to use software serial in order to use pins 2 and 4 for tx and rx.

in my code i have

void setup()
{

serial_flag.begin(300, SERIAL_7E1); //initialize the software serial port for 300 baud

}

Though the SERIAL_7E1 returns me with the error C:\Program Files (x86)\Arduino\libraries\SoftwareSerial/SoftwareSerial.h:85: note: candidates are: void SoftwareSerial::begin(long int)

I have don some research before posting here and note that someone else has been trying this from september 2013 though it was not clear if they eventually got it to work.

It seems that the problem is setting the parity within the software serial. Would i be quicker and more effective using hardware serial. If so would

Serial.begin(300, SERIAL_7E1);

be the correct way of setting up baud rate and parity etc ?

This is my first time using the ardunio and have note coded anything for years, so apologizes if this was a drawn out post

Thanks

Fraser

I have don some research before posting here and note that someone else has been trying this from september 2013 though it was not clear if they eventually got it to work.

I believe to remember that solution was suggested by me. 7E1 is the same as 8N1 (the setting that is coded hard into SoftwareSerial) if you calculate the parity bit yourself and set it as the topmost bit in your sent byte. You can even subclass SoftwareSerial to have this done automatically for you.

Using the hardware serial is the easier and more reliable version though but only if you don't have to communicate with the PC over USB. In that case you might get better results with SoftwareSerial although a SoftwareSerial instance with a speed of 300 baud noticeably slows down your Arduino because during data transfer the Arduino is blocked completely.

Hey,

thanks for the reply. I decided after looking into it more to use the Mega hardware serial1 instead,

Have that now sending the information i need. Just need to figure out best way to send 5 hex numbers one after another with a delay in between so there is no clash.

so there is no clash.

What clash? Why would you need a delay? Or is the receiving device not up to the job?


Rob

frazzybell:
thanks for the reply. I decided after looking into it more to use the Mega hardware serial1 instead,

If the Mega is overkill, you might want to look into the Micro. It's got two Serial ports. Serial1 would work for your task, I think.

The clash issue was me being daft, thought sending each hex character one after another would not be right

My code below is what i have put together so far. I am still monitoring the response of the meter with the scope. Though nothing is coming back. It is the correct sign on message and it is def 7 data bits, even parity with 1 stop bit.

It is starting to get really annoying as i have sent this code via the pc and my rs-232 interface, i have even got the meter to say hi back. Feel like i am going round in circles

****some parts of code and commented out as i have been trying different things ****

Can anyone help please ???

Code:

#define rxPin 19
#define txPin 18
#include <LiquidCrystal.h>

char rx_byte;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Pins defined to use with LCD Shield http://www.hobbytronics.co.uk/arduino-lcd-keypad-shield

//--------------------------------------------------------------------------
byte pinState = 0;
void setup()
{
// define pin modes for tx, rx,
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(300); // Set up serial monitor to watch output on screen first
Serial1.begin(300, SERIAL_7E1); // set the data rate for the serial port & define parameters

lcd.begin(16, 2); // set up the LCD’s number of columns and rows

//-------------------------------------------------------------------------

}
void loop () // Start of loop to send sign on request code
{
byte message = {0x2F, 0x3F, 0x21, 0x0D, 0x0A,};
Serial1.write(message, sizeof(message));
//Serial1.write(0x2F);
//Serial1.write(0x3F);
//Serial1.write(0x21);
//Serial1.write(0x0D);
//Serial1.write(0x0A);

delay(10000); // 10 sec delay before sign on is sent again
{
if (Serial1.available ()> 0) { // Check if any serial data is being received
rx_byte = Serial1.read();

}

while (Serial1.available() > 0 ) { // whiles serial read is not doing anything
Serial1.read (); // read serial port 1
lcd.write(rx_byte); // write the information recieved to the lcd
//Serial.print(rx_byte); // Print the information received to the serial monitor
}
}

}

Cheers

The code has one problem at least

	if (Serial1.available ()> 0) {    
			rx_byte = Serial1.read();  // read the first byte

		}

		while (Serial1.available() > 0 ) {    
			Serial1.read ();                    // read byte and discard it
			lcd.write(rx_byte);          // constantly write the first byte
		}

~~Also, does the data in the array already have the E parity calculated?~~Sorry, you've used the 7E1 option.


Rob

The part at the end about reading the incoming data back from the meter i wasn't working on the now greatly. This is my first time coding in 2 years and i'm struggling to even get the sign on request 2F,3F,21,0D,0A To even be transmitted correctly at 7E1

Not sure what you mean when you are asking does the data in array have even parity calculated, are you referring to the incoming data from the meter ?, as there is none at the present :frowning:

edit, yeah i am using the option though i am not convinced it is working correctly ?

i have sent this code via the pc and my rs-232 interface,

Does the device really use RS-232, if so you can't connect an Arduino directly to it.

i am not convinced it is working correctly

You have a scope, look at the data and find out.


Rob

No the device which reads the meter is a ttl logic circuit. I made a rs-232 board up to i could connect it to the pc and test the function of the probe to sign on to the meter before moving over to the arduino.

Can you provide some more specifics on the meter you have?

I am new at this type of support so I hope I’m not interfering. I am currently working on a project that requires communicating with eight none addressable devices from a ninth serial port. My eight devices use 7E1. I am keeping Serial0 my usb monitoring,
Serial1 my main com, and Serial 2,3 and SoftSerial 4-9 for my devices. Of course setting up Serial2,3 worked without an issue.

I too, need to figure out how to set the softSerial to 7E1.

I haven’t seen the solution yet. Am I missing something?
Tom

I too, need to figure out how to set the softSerial to 7E1.

This is not possible (without changing the SoftwareSerial code) but 7E1 is 8N1 if you calculate the parity bit yourself before writing and set the 8th bit accordingly.

How would I set that 8th bit to a one or zero?
I believe I can set my device to be ether a 1 or 0.

How would I set that 8th bit to a one or zero?

byte x = somevalue;
x |= 0x80; // set bit 7
x &= ~0x80; // clear bit 7

or

byte x = somevalue;
x |= (1 << 7); // set bit 7
x &= ~(1 << 7); // clear bit 7

Rob

I am using a BS 62056-21:2002 standard meter

I have built a flag probe and successfully communicated with the meter via rs232. I built a board with the maxrs232 in order to change the levels down to ttl.

I am now trying to send the hex code

2F 3F 21 0D 0A to the mega, i am using hardware serial now

I have an inverter circuit set up to invert the signal, so when the meter receives it, it is correct. When the IR LED is ON, on the probe the photo transistor in the meter gives 0,hence the inversion.

I used hardware inversion before as it was easier. I am simply monitor the output back from my flag probe to see if the IR LED within the meter is communicating back. It is not though.

My thoughts are, the baud rate is set wrong. IT can only be 300 to sign on to start with, OR the config is incorrect. I am leaning more towards this.

Also if the signal out of the arduino is not TTL then this is my problem. I am hoping it is my code as i am not at a dead end. I chose to use the arduino for the TTL levels to make things easier, maybe not ??? :frowning:

The picture included shows the sign on request sent and message back from the meter on the PC

Were you using the same inverter circuit when you got it working with the PC?

Yep sure was. See my confusion about it

It should be simple yet something is a miss or wrong somewhere somehow

It should be simple yet something is a miss or wrong somewhere somehow

Yup. I'd try without the inverter as a first easy test. After that I'd send it 8N1 and hand calculate the parity bit just to see if I could persuade the meter to send something. After that, since it works with the PC, I'd want to compare what's going on with a scope.

already tried without the inverter.

the meter just will not talk back unless it is 7E1, i tried farting about on the pc before to see and nothing

how would i go about setting it to 8N1 and manually changing the code so it transmits 7E1 ?

Im just asking before i go away and spend ages trying to figure it out. Time is running out and i need this to work

Oh the scope shows clearly the meter talking back on the PC, just heehaw using the arduino

attached code in case there is still something a miss

TEST_MEGA2.ino (2.44 KB)