RS-232 to TTL Converter into Rx and Tx pins on Arduino Uno for control of LEDs

I'm trying to control an LED banner via RS-232 to TTL Converter into Rx and Tx pins on the Arduino Uno. I can control the display using the Arduino software serial monitor and a variation of the MD_Parola/MD_MAX72XX Message Serial sample code but when sending commands to the Rx pins I get nothing.

I suspect I have to designate which serial port to use and include certain libraries, and possible modify the code a wee bit but I could use an example to work off of. Any help would be appreciated

Message_Serial_KBGTEST.ino (6.86 KB)

MattyV:
I'm trying to control an LED banner via RS-232 to TTL Converter into Rx and Tx pins on the Arduino Uno.

We need to know exactly how it's connected.

I guess Rx on the Uno means connect to Tx of other device and
Tx on the Uno means connect to Rx of other device.

pert:
We need to know exactly how it's connected.

RS-232 to TTL Tx is connected to pin 1 on Arduino - Uno
RS-232 to TTL Rx is connected to pin 0 on Arduino - Uno

Code:

#include <MD_MAX72xx.h>
#include <SPI.h>
#include <SoftwareSerial.h>

int led3 = 5; // the PWM pin the LED is attached to
int led2 = 6; // the PWM pin the LED is attached to
int led = 9; // the PWM pin the LED is attached to
int inputpin = 2;
int brightness3 = 0; // how bright the LED is
int brightness2 = 0; // how bright the LED is
int brightness = 0; // how bright the LED is
int fadeAmount3 = 3; // how many points to fade the LED by
int fadeAmount2 = 2; // how many points to fade the LED by
int fadeAmount = 2.5; // how many points to fade the LED by
int buttonstate1 = 0;

const byte rxPin = 0;
const byte txPin = 1;

SoftwareSerial mySerial (rxPin, txPin);

#define USE_POT_CONTROL 1
#define PRINT_CALLBACK 0

#define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 8

#define CLK_PIN 13 // or SCK
#define DATA_PIN 11 // or MOSI
#define CS_PIN 10 // or SS

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Scrolling parameters
#if USE_POT_CONTROL
#define SPEED_IN A5
#else
#define SCROLL_DELAY 200 // in milliseconds
#endif // USE_POT_CONTROL

#define CHAR_SPACING 1 // pixels between characters

// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE 75
char curMessage[BUF_SIZE];
char newMessage[BUF_SIZE];
bool newMessageAvailable = false;

uint16_t scrollDelay; // in milliseconds

void readmySerial(void)
{
static uint8_t putIndex = 0;

while (mySerial.available())
{
newMessage[putIndex] = (char)mySerial.read();
if ((newMessage[putIndex] == '\n') || (putIndex >= BUF_SIZE-3)) // end of message character or full buffer
{
// put in a message separator and end the string
newMessage[putIndex++] = ' ';
newMessage[putIndex] = '\0';
// restart the index for next filling spree and flag we have a message waiting
putIndex = 0;
newMessageAvailable = true;
}
else if (newMessage[putIndex] != '\r')
// Just save the next char in next location
putIndex++;
}
}

void scrollDataSink(uint8_t dev, MD_MAX72XX::transformType_t t, uint8_t col)
// Callback function for data that is being scrolled off the display
{
#if PRINT_CALLBACK
Serial.print("\n cb ");
Serial.print(dev);
Serial.print(' ');
Serial.print(t);
Serial.print(' ');
Serial.println(col);
#endif
}

uint8_t scrollDataSource(uint8_t dev, MD_MAX72XX::transformType_t t)
// Callback function for data that is required for scrolling into the display
{
static char *p = curMessage;
static uint8_t state = 0;
static uint8_t curLen, showLen;
static uint8_t cBuf[8];
uint8_t colData;

// finite state machine to control what we do on the callback
switch(state)
{
case 0: // Load the next character from the font table
showLen = mx.getChar(*p++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
curLen = 0;
state++;

// if we reached end of message, reset the message pointer
if (*p == '\0')
{
p = curMessage; // reset the pointer to start of message
if (newMessageAvailable) // there is a new message waiting
{
strcpy(curMessage, newMessage); // copy it in
newMessageAvailable = false;
}
}
// !! deliberately fall through to next state to start displaying

case 1: // display the next part of the character
colData = cBuf[curLen++];
if (curLen == showLen)
{
showLen = CHAR_SPACING;
curLen = 0;
state = 2;
}
break;

case 2: // display inter-character spacing (blank column)
colData = 0;
curLen++;
if (curLen == showLen)
state = 0;
break;

default:
state = 0;
}

return(colData);
}

void scrollText(void)
{
static uint32_t prevTime = 0;

// Is it time to scroll the text?
if (millis()-prevTime >= scrollDelay)
{
mx.transform(MD_MAX72XX::TSL); // scroll along - the callback will load all the data
prevTime = millis(); // starting point for next time
}
}

uint16_t getScrollDelay(void)
{
#if USE_POT_CONTROL
uint16_t t;

t = analogRead(SPEED_IN);
t = map(t, 0, 1023, 25, 250);

return(t);
#else
return(SCROLL_DELAY);
#endif
}

void setup()
{
mx.begin();
mx.setShiftDataInCallback(scrollDataSource);
mx.setShiftDataOutCallback(scrollDataSink);

#if USE_POT_CONTROL
pinMode(SPEED_IN, INPUT);
#else
scrollDelay = SCROLL_DELAY;
#endif

strcpy(curMessage, "WELCOME TO THE NOV CTES ORION VI! hello world! ");
newMessage[0] = '\0';

mySerial.begin(57600);
mySerial.print("What Up!");
//Serial.begin(57600);
//Serial.print("What Up!");
//\n[MD_MAX72XX Message Display]\nType a message for the scrolling display\nEnd message line with a newline
// declare pin 9 to be an output:
pinMode(led3, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led, OUTPUT);
pinMode(inputpin, INPUT);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
}

void (*resetFunc)(void) = 0;

void loop()
{
scrollDelay = getScrollDelay();
//readSerial();
mySerial.read();
scrollText();

buttonstate1 = digitalRead(inputpin);

if (buttonstate1 == LOW)
{
// set the brightness of pin 9:
analogWrite(led3, brightness3);
analogWrite(led2, brightness2);
analogWrite(led, brightness);

//change the brightness for next time through the loop:
brightness3 = brightness3 + fadeAmount3;
brightness2 = brightness2 + fadeAmount2;
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness3 <= 0 || brightness3 >= 100)
{
fadeAmount3 = -fadeAmount3;
}
if (brightness2 <= 0 || brightness2 >= 100)
{
fadeAmount2 = -fadeAmount2;
}
if (brightness <= 0 || brightness >= 100)
{
fadeAmount = -fadeAmount;
}

// wait for 30 milliseconds to see the dimming effect
delay(10);
}

if (buttonstate1 == HIGH)
{
brightness3 = 0;
brightness2 = 0;
brightness = 0;
analogWrite(led3, brightness3);
analogWrite(led2, brightness2);
analogWrite(led, brightness);
resetFunc();
}

}

MattyV:
RS-232 to TTL Tx is connected to pin 1 on Arduino - Uno
RS-232 to TTL Rx is connected to pin 0 on Arduino - Uno

Arduino Pin1 is Tx - it should connect to the Rx of the converter so the Arduino can send and the converter can receive. And Pin0 is Rx which should connect to the Tx of the converter so it can receive what the converter is sending.

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

...R

Yes, I apologize:

Tx on the TTL converter is connected to Rx on Arduino
Rx on the TTL converter is connected to Tx on Arduino

If the code is working for PC > USB cable to Arduino serial monitor to work, should I have to modify it at all for pins 0 and 1 to work...or do I just need to disconnect USB cable and send serial data to pins 0 and 1?

MattyV:
If the code is working for PC > USB cable to Arduino serial monitor to work, should I have to modify it at all for pins 0 and 1 to work...or do I just need to disconnect USB cable and send serial data to pins 0 and 1?

I'm sorry, but I don't understand. Please explain in more detail. A diagram showing how things are connected may help.

...R

There's no reason to use SoftwareSerial on pins 0 and 1. Those pins have hardware serial capability.

Abandoned SoftwareSerial. Went back to Serial object. Everything is working just fine. Turns out my RS-232 converter converted the Tx and Rx internally...so by chance I connected the converters Tx pin to the Tx pin on the Arduino and ditto for the Rx pin and serial communication began. Thanks for the help!.

Nice to hear its working.
I altered my previous post.
But sometimes it is pretty confusing how connections are marked.