[SOLVED] Particle Electron Serial Connection

Hi all,

I’ve been interfacing with a Texecom alarm panel recently. I’ve been using an Arduino Uno, minus the Atmega chip, as a Serial to USB adapter. With the following settings, I can read data coming from this alarm panel:

Baud Rate = 4800
Parity = None
Start Bits = 1
Stop Bits = 2
Data Bits = 8
Flow Control = None

This works great, and I can see the data coming through, on a serial terminal with putty.

However, I want to be able to read this data with the Particle Electron. I’ve setup a simple script that should forward data the Electron receives, on Serial1 to the USB Serial, to allow me to view it.

I’m using the Particle CLI to open the serial port to my Electron, but I get no data.

I’ve checked connections etc and they are exactly the same as the RX and TX connections I used on the Arduino - any advice?

Test code:

#include "Particle.h"
#include "application.h"

SYSTEM_MODE(SEMI_AUTOMATIC);


// Constants
const unsigned long SEND_INTERVAL_MS = 2000;
const size_t READ_BUF_SIZE = 64;

// Forward declarations
void processBuffer();

// Global variables
char readBuf[READ_BUF_SIZE];
size_t readBufOffset = 0;


void setup() {
  Serial1.begin(4800, SERIAL_8N2); //setup on RX and TX pins
  Serial.begin(9600); //USB serial
}

void loop() {


	// Read data from serial
	while(Serial1.available()) {
		if (readBufOffset < READ_BUF_SIZE) {
			char c = Serial1.read();
			if (c != '\n') {
				// Add character to buffer
				readBuf[readBufOffset++] = c;
			}
			else {
				// End of line character found, process line
				readBuf[readBufOffset] = 0;
				processBuffer();
				readBufOffset = 0;
			}
		}
		else {
			Serial.println("readBuf overflow, emptying buffer");
			readBufOffset = 0;
		}
	}

}

void processBuffer() {
	Serial.printlnf("Received from Texecom Panel: %s", readBuf);
}

Thanks

As an update, I tried forcing some of the Serial config:

  Serial1.begin(4800, SERIAL_DATA_BITS_8 | SERIAL_STOP_BITS_2 | SERIAL_PARITY_NO);

However, this didn’t seem to change much.

Thanks

Interestingly, I’ve put this in setup() and I still get nothing from the CLI Serial monitor…

void setup() {
  Serial1.begin(4800, SERIAL_DATA_BITS_8 | SERIAL_STOP_BITS_2 | SERIAL_PARITY_NO); //setup on RX and TX pins
  Serial.begin(9600); //USB serial
  Serial.println("Software serial initialised:");
}

@joearkay, try a different terminal program like Putty or Teraterm.

You could just try to directly forward anything you get without any interpretation to check if and what you get

void loop() {
  while(Serial1.available()) {
    Serial.write(Serial1.read());
  }
}
2 Likes

Are the lines really terminated by \n (LF)? If they’re terminated by \r (CF) the processBuffer would never be called and it wouldn’t be logged to USB serial.

1 Like

@peekay123 I uploaded a simple sketch that prints to Serial constantly, and opened in Putty, and all is good. I’ve saved the settings in putty so I know that works now :slight_smile:

I was tired last night, I’m not going to see the Serial.println("Software serial initialised:"); in my terminal, because it happens before I connect to the serial bus!

Thanks
Joe

I’ve done this, and still nothing. I noticed yesterday, using the Arduino as a serial converter (no chip populated), that removing the ‘transmit’ (from Arduino) lead stopped communication (not sure whether this expected behaviour).

It also makes me wonder, as the pins from the alarm panel are 5v and the Particle is 3.3v (5v tollerant) whether it’s reading info fine, but the panel isn’t detecting a serial device (this not sending) as the tx is spitting out 3.3v signals from the panel. I have a shifter somewhere, I’ll dig it out!

Only different I can think of between the Arduino board (as a serial to usb) and the Particle, currently.

Not sure @rickkas7 - Whenever I have read data through putty it ‘just works’. But with the Arduino IDE, I’ve set it to ‘Both NL and CR’, so yes, maybe I need to check for more. Thanks

Hi all,

Thanks for your help - it was a level conversion issue! Doh!

Thanks
Joe

2 Likes

@joearkay, to help other members, can you explain how you did the level conversion? :relaxed:

1 Like

Of course @peekay123

I used a sparkfun level converter chip, wired in a similar fashion as below (note odd RX -> RX labelling)

1 Like

How could you use two different baud rate on a single serial ? I want to use two device with the same baud rate on a photon particle (which have only one Rx and Tx pins), is it possible? Thanks in advance! joearkay