SoftwareSerial with manual control of TX (HIGH, LOW) line?

I am using an Arduino and an RS-232 to TTL adapter to interface with my Tandy/Radio Shack TRS-80 Color Computer. My project, SirSound, is a sound chip controlled via the serial printer port.

Microsoft COLOR BASIC has build in commands to send output to the printer, such as:

PRINT #-2,"This will go to the printer"

To prevent sending data when the printer is not ready, it uses the RX pin of the serial printer port for flow control. When the printer is ready, that line goes LOW letting the computer know it can send data. When the printer is not ready, or offline, the line is HIGH, and BASIC will hang/pause until it is ready.

I planned to do this in my project as well, so BASIC can't send data when the buffer is full.

It seems that SoftwareSerial does not let me hijack that RX pin. I have something like this:

#define TX_PIN_COCO     A4
#define RX_PIN_COCO     A5

SoftwareSerial CoCoSerial(RX_PIN_COCO, TX_PIN_COCO); // RX, TX

In order to control the TX pin, I need to do:

pinMode(TX_PIN_COCO, OUTPUT);
digitalWrite(TX_PIN_COCO, LOW); // Ready!

...and then I toggle it LOW or HIGH depending on if I am ready for more data from the computer.

I am doing this just fine using a "ReceiveOnlySofwareSerial" modification Nick Gammon did:

http://forum.arduino.cc/index.php?topic=112013.msg1919710#msg1919710

These modifications were done by folks who wanted to save a pin. In my case, I still want to be able to send and receive in an interactive mode, but the normal mode would be receive-only with the flow control.

I thought I'd ask here if there might be a way to do what I want with the stock SoftwareSerial library. I've glanced at the source a bit, and it didn't look like it would be doing anything if nothing was being sent, so I thought it would work.

Suggestions appreciated.

Post your complete program.

Draw a simple diagram showing the connections and post a photo of the drawing.

Is this thing you call "SirSound" a program that is running on the Tandy computer or on the Arduino?

What are you referring to when you say "serial printer port"?

This

it uses the RX pin of the serial printer port for flow control. When the printer is ready, that line goes LOW letting the computer know it can send data.

seems very strange. Normally the Rx pin is an input rather than an output.

And to be honest, I'm not sure whether you mean the Rx pin that SoftwareSerial uses to listen or the Rx pin on the other device to which the SoftwareSerial Tx pin sends data.

...R

Robin2:
Post your complete program.

:slight_smile: Unnecessary since I'm just wondering if there is a way to hijack the TX pin for SoftwareSerial to manually set it HIGH or LOW, when not sending data out it. I have no code issues. Using an alternate software serial implementation works just fine. I'm just wondering if there's a way to do it with the stock library.

Robin2:
Draw a simple diagram showing the connections and post a photo of the drawing.

Well, the connections would simple be a pin on Arduino (being used as TX) going to another device's RX :slight_smile:

Robin2:
Is this thing you call "SirSound" a program that is running on the Tandy computer or on the Arduino?

SirSound is my Arduino program. It drives an old Texas Instruments SN76489 sound chip, and has a parser that handles the old Microsoft BASIC "PLAY" command strings. In Microsoft BASIC, you would do something like:

PLAY "C D E F G A B"

...to play music. My parser replicates that, so you can do things like:

play(F("C D E F G A B"))

...and play music using the Arduino tone() command, or via a multitrack sequencer I wrote which uses the polyphonic Texas Instruments chip. It's great fun.

All SirSound does is read input from a serial port, and play the string it receives.

You hook it up to any computer with an RS-232 port, and then send data out that port and the Arduino plays it as music. It's great for old computers that didn't have sound chips, or if they did, there was no easy way to program them in BASIC.

You can see two demo videos of it here:

Robin2:
What are you referring to when you say "serial printer port"?

RS-232C. "When I was a kid" it was used to hook computers up to modems, or printers (that had serial interfaces), or by NULL modem cables to link two computers together. The Color Computer port I am using is a bitbanger (i.e. software serial port) that has TX, RX, CD and GND only. I have it hooked via an RS-232 to TTL adapter to two pins of the Arduino for TX and RX (plus power and ground).

Robin2:
Thisseems very strange. Normally the Rx pin is an input rather than an output.

And to be honest, I'm not sure whether you mean the Rx pin that SoftwareSerial uses to listen or the Rx pin on the other device to which the SoftwareSerial Tx pin sends data.

The RX is on the Color Computer. On the Arduino, I set the TX pin LOW to tell the computer it is okay to send, and set it HIGH to make it stop sending.

From searching, I do find a number of other folks who have asked for ways to "send only" or "receive only" on the Arduino. Most of them seem to not want to waste two pins if they are just sending or receiving data only. Since the responses I have seen have all been pointers to hacked versions of SoftwareSerial that contain just the Send or Receive portion, they don't really work for my purposes since I still do want to be able to go into a mode where I send data back... But when not in that mode, I just want to toggle the pin HIGH or LOW.

If you want to be sure, a look into your SoftwareSerial library is required. Libraries can be updated every now and then, with slightly different behaviour across versions.

You can try to force the TX output into the desired state, and check whether that's possible at all (should be), or whether the library resets it immediately.

allenhuffman:
Unnecessary

[....]

Well, the connections would simple be a pin on Arduino (being used as TX) going to another device's RX :slight_smile:

As you don't seem to want to help me to help you I will look at some other Threads

...R

A non-standard RX state is often used for broken wire detection. Check the library for something like a break() function, that sets TX to that level.

DrDiettrich:
A non-standard RX state is often used for broken wire detection. Check the library for something like a break() function, that sets TX to that level.

Thanks. I found out early on that the Arduino documentation was a bit tricky to figure out. For instance, I thought this was the docs for Serial:

...then (at the time) I discovered there were more functions available than listed there. That started me digging into library source code.

I did some modifications to the Ethernet library a few years ago to allow multiple incoming connections, but it seems it's quite the ordeal for most users to go in and make my changes to their libraries. I already have multiple alternate libraries that do what I need, but it would be nice to do it with a default library.

I was unable to manually toggle the pin myself, so unless there's some missing parameter I did not see, I guess I'll be hacking a library again :slight_smile:

Robin2:
As you don't seem to want to help me to help you I will look at some other Threads

...R

No worries! All responses are appreciated, as long as they are not "why would you want to do that?" (i.e., anything ever posted to Stack Exchange.)

If you haven't worked with SoftwareSerial, it's literally just using two pins going to TX and RX of a serial adapter (with power and ground, of course). It's not much different than hooking up an LED. Super simple.

Though my project has a wee bit more wires :smiley:

(Only TX and RX are connected in that image, with power coming from breadboard rails.)

It looks like manually asserting a line is not common enough to be part of stock behavior. (Though, as another reply mentioned, there are other uses for this.)

Cheers!

If the library is assumed to change the pin state when required, such a change requires the call of a library function. If you don't call it, you have full control over the pin, without touching the library.