RS232 Output to display on OLED 2828 Display

Hi

I have the follwoing hardware

arduino nano
rs232-tll converter
oled 2828 display

the display and nano work with my sketches where my output is hard coded in the sketch
but now I want to use dynamically generated ascii output from an external device that outputs in rs232 format

so I introduce the rs232/tll board and attaching the tx/rx to the pins indicated in the sketch below.

to test the output ( below incorporating it into the code for 2828 display) I connect the nano to the arduino Ide via and ran the serial monitor however the only output I get id -1 or else if I disconnect the rs232 feed the output is 0

Can anyone shed some light on why I am not getting the ascii data being sent to appear in the serial monitor instead it outputs -1.

Is there an issue with my code, do I need to use a different lib ???
one of your support staff commented I should be using spi.h and hardware serial ??

I welcome all advise that can be provided.

Thanks in advance

// include the SoftwareSerial library so you can use its functions:
#include <SoftwareSerial.h>

#define rxPin 9
#define txPin 8

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

void setup()  {
  // define pin modes for tx, rx:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop()
{
 Serial.println("this is a test"); // making code is working
 Serial.println(mySerial.read());
 delay(1000); 

Hi Claude,

RS232 is usually UART, but RS232 doesn’t actually specify an encoding protocol - it could be you’re unlucky and have something that’s not using UART. Have a bit of a read on the wiki article: https://en.wikipedia.org/wiki/RS-232

I would suggest wrapping your read() statement in an if as per the SoftwareSerialExample:
https://www.arduino.cc/en/Tutorial/SoftwareSerialExample
SoftwareSerial.read() returns -1 if there’s no data available, so it could be you’re just flooding your serial monitor with -1 and missing the data.

You should also check the baud rate of your transmitting device is indeed 9600.

Your display has an SPI interface, which is why I suggested you look into SPI.h to output data to your screen.

Let us know how you get on!

Regards,
Oliver
Support | Core Electronics

Hi

The device sending the data ASCII data to the arduino that I want use UART compliant I have to even set uart to be active in the firmware of the device so that the device knows to send the data the tx output uart enabled

Here are 2 screen shots from the firmware manager of the device that’s sending the data

Activating uart in firmware of device sending data


Sending the data in this example 55 out via serial port

Claude Raiola
0414 228 948

Why not check to see if data is available before trying to read it with serial.available?

Refer to this link:

https://www.arduino.cc/reference/en/language/functions/communication/serial/available?from=Reference.SerialAvailable

Full reference to the software serial library here:

https://www.arduino.cc/en/Reference/softwareSerial

1 Like

Note this from the reference: the use of delay() in a sketch has significant drawbacks. No other reading of sensors, mathematical calculations, or pin manipulation can go on during the delay function, so in effect, it brings most other activity to a halt.
So quite likely softwareserial() gets locked out by delay().
You need
if (mySerial.available())
before
mySerial.read()
instead
Also I note you’ve set odd parity on the sending device. The softwareserial probably needs 8 data bits no parity.
Reading further, softwareserial relies on an interrupt on every bit in a character, any other interrupts while processing a character may corrupt the character.
maybe
void loop()
{
if (mySerial.available())
Serial.println(mySerial.read());
}
[I know heaps about RS232 but not much about Arduino C]

2 Likes