Analog to Serial

Hi all,

I have a tricky one I was hoping for some pointers on..
I have a 0-30V DC signal which contains a bi-directional serial stream.
15V for '0' (no comms either direction)
Then for one direction, the voltage is pulled towards 0V to signify '1' and the other direction is pulled towards 30V to signify the '1'

I have an Op-amp circuit so I can analog read these voltages successfully and split the directional data stream

Ideally the next step is performing native serial available & read to get the data but as it has come from an analog input I can't set serial.begin against pin numbers because it isn't traditional Tx/Rx

Edit: at this stage the intention is to read the stream only, no need to write back
I also expect it to be a pretty low baud rate

Any suggestions?

What might turn out to be the easiest might be to drive two optocoupler inputs with your signal, arranged such that each produces an output only for one direction(extra circuitry likely required). That would separate your two data streams, and additionally allow you to drop the signal level to either 3.3 or 5V levels for the receiving device.

As for what receiving device, it depends. If the baud rate is 9600 or lower, you might be able to use Serial RX for one stream, and software serial for the second, but I've no SS experience, so others would need to advise.

If it was up to me, I'd use an ATMEGA328PB, or other device with two hardware serial ports, like a Mega2560 or Every. Removes a whole layer of uncertainty about software Serial implementation gotchas.

Use a LM393 comparator and set the threshold to 15V.
Pullup the output to 5V. You will get a digital signal that you can read as LOW/HIGH
That will give you the direction.
You another LM393 window comparator to detect if it is above say 28V or below 2V

Use level shifter circuitry instead.

Classic RS232 signals range from -15 to 15 V in the extreme cases, but it is no problem to convert that signal to 0-5V TTL serial. For example, using this module.

Maybe all you need is a capacitor to remove the DC offset in the signal. If you will take a moment to describe that signal more completely, people can help.

Sounds like some sort of mechanical switching arrangement. How much NOISE is on your signal line and how often, per second, does the switching occur?

Thanks for the input, maybe a picture will help from the scope of the voltage levels

Thanks for your input, I did consider software serial - I wouldn't need any pins, If it would accept byte inputs from memory

Looks like a typical bipolar data signal, except you have one probe connected to ground.

What sort of device generates that signal, and what information is being transmitted?

It isn't classic RS-232, which looks like this:

AC units - indoor to outdoor comms
I'm not sure how it's generated, it's a proprietary board and I'm purely wanting to decode the data between the units

Not enough information. You won't be able to read that three-level signal as UART serial, no matter how you process it.

Yeah I completely understand that, please refer back to the original post or first few answers on how signal transformation can take place into 0-3.3/5V UART

I did -- not enough information. Have fun!

I would use a circuit with 2 comparators to convert the 30V/15V/0V signal to 0V/5V.

  • Have a 10:1 potential divider to reduce the incoming signal to 3V maximum.

  • Feed this signal to both comparators.

  • Have reference voltages of around 2.25V and 0.75V going to the other comparator inputs.

  • This will cause the outputs to switch at around 22.5V and 7.5V respectively.

  • The signal between 15V and 0V looks as though it is like a normal RS232 signal that idles high, and so needs inverting to go to the Arduino.

  • The signal between 15V and 30V looks like an inverted RS3232 signal as it idles low.
    This does not need inverting to go to the Arduino.

  • The inputs to the comparators are arranged so that one inverts, the other doesn't.

Here is my suggested circuit:

Capture the 15V -> 30V bits with this trivial circuit (1200 baud signal shown):