Serial communications specifics

I've been using other microcontrollers in a project which communicate with each other through digital pins. The uCs are too slow, so I need to upgrade to Arduinos. The problem is, I can't find specifics anywhere & I've already apparently blown up one of my Nanos.

First of all, how do I wire them together? Do I pull down to ground on the input, or up to 5v? What size resistor do I use? Do I put a resistor on the output, and what size? Why, when I use resistors, do the other uCs (or the other Arduino) power up with no Vcc hooked up to them?

Second, what is the exact protocol? Data bits, stop bits, parity, and does the line idle high or low?

Third, what do I have to do with the code to get it to work? I've read the SoftwareSerial routines on this site, and nothing has worked yet. Also, the Arduino seems to have some weird logical rules, I've got "If" statements that seem to run all the time, regardless of the condition being tested.

I'm trying to send three-byte data packets from one to the other...

... communicate with each other through digital pins ...

This is a bit vague. You could be using async serial, I2C, SPI, or some homebrew protocol.

Assuming for the moment you are using serial, you connect all the grounds together, as a reference point. Then the Tx (transmit) from one goes to Rx (receive) of the other. And vice-versa if you want two-way communication. To daisy-chain is going to get fiddlier. You might want to think about I2C which lets you connect up to 119 devices by simply connecting Gnd, SDA and SCL together (not swapped). Having said that there are some wire-length considerations because of capacitance.

I2C requires a single set of pull-up resistors. A lot of detail is here:

What size resistor do I use? Do I put a resistor on the output, and what size? Why, when I use resistors, do the other uCs (or the other Arduino) power up with no Vcc hooked up to them?

I'd have to see your circuit to comment. But with a resistor some current will still flow. It sounds odd they are powering up by just connecting the digital pins. In fact it is probably unwise to apply current to the digital pins if they are not powered in some way. You could just connect all the VCCs together (plus all the GNDs) if you had a power supply that could supply enough current.

If you aren't sure, maybe post a quick sketch (diagram) of what you are proposing to do.

Also, the Arduino seems to have some weird logical rules,

No it does not, it is just plane C code

I've got "If" statements that seem to run all the time, regardless of the condition being tested.

My money is on the fact that you have ended the if statement with a colon.

My money is on the fact that you have ended the if statement with a colon.

You lose. I'm using the example code in the "softserial" section on this site.

In fact it is probably unwise to apply current to the digital pins if they are not powered in some way.

I don't WANT the other arduino powered. I've tried putting resistors on the digital pins, but it's still powering up, and now I'm getting "sync" errors so I'm pretty sure my Nano is screwed. I have to wait until a new one comes in before I can continue troubleshooting. How can I stop them from powering up?

I've had no problems with serial comm on Basic Stamps, PICAXES or the BX-24. They all talk to each other just fine, but the Arduinos aren't getting any info, and the example routines don't work.

My money is on the fact that you have ended the if statement with a colon.

You lose. I'm using the example code in the "softserial" section on this site.

Whoosh. That was hint to post your code. Went completely over your head, apparently.

In fact it is probably unwise to apply current to the digital pins if they are not powered in some way.

I don't WANT the other arduino powered.

Then don't apply signals to them that is probably what knackered your Nano. On the other hand if you WANT what you WANT how about re inventing the laws of physics, preferably in some other universe than here.

You are the one asking for help, I think you need a change in attitude to start with.

That statement:-

Also, the Arduino seems to have some weird logical rules,

Is total bull and is result of you not understanding what you are doing.

Crow:
I don't WANT the other arduino powered. I've tried putting resistors on the digital pins, but it's still powering up, and now I'm getting "sync" errors ...

You don't want the Arduino powered? Wouldn't it be easier to omit it altogether?

... but the Arduinos aren't getting any info, and the example routines don't work.

Because they are unpowered? Be reasonable and give more information. What example routines anyway?

I'm sorry, I didn't mean to sound as if I had an attitude. I simply asked a few questions, and was trying to specify what I was looking for.

Let me try this again:

  1. What is the serial communications protocol, ie. stop bit, parity, logic inverted or not?

  2. How do I keep the other Arduino from powering up through the digital pins?

The protocol is configurable. Typically you have 8 data bits, 1 stop bit, normal logic, no parity. The baud rate you choose on the Serial.begin() function call.

You could normally connect Tx -> Rx and Rx -> Tx (ie. swap them) and also connect the Ground pins.

The chips aren't really designed to "power up" through the few milliamps that come down the serial pins, however as a general rule you don't pump voltages into a device that is itself powered off. Having said that, it probably won't hurt.

To connect serial ports, I would not be using any resistors at all.

I've documented Arduino serial ports here:

How do I keep the other Arduino from powering up through the digital pins?

On the powered Arduino change all connected pins to inputs or drive them LOW.


Rob

I've documented Arduino serial ports here:

Gammon Forum : Electronics : Microprocessors : Async (Serial) peripheral interface - for Arduino

Wow, thanks a lot. That's exactly what I was looking for & more.

I should probably say that I need the "regular" serial port for diagnostics, and later it'll most likely be connected to a LCD. I need a single communications port to let the Arduinos talk to each other, and I'm using the SoftSerial library for that. It's possible that the other Arduino might not be on sometimes, and I don't want it powering up through the pins - if inline resistors won't work, is there some way I can isolate the pins so that I won't blow up any more Arduinos?

I just thought of something after I posted this: what if I add an additional digital line from the possibly unpowered Arduino, a "ready to receive" line? The main uC wouldn't have its output line high until it saw a high on the RTR line. If all output lines were low, it couldn't power up through the pins, right? I guess I'll find out for myself after my new Nano arrives...

is there some way I can isolate the pins so that I won't blow up any more Arduinos?

You can use an opto isolator and a transistor to turn the signal the right way up again.

If all output lines were low, it couldn't power up through the pins, right?

See reply #9.


Rob

Crow:
Third, what do I have to do with the code to get it to work? I've read the SoftwareSerial routines on this site, and nothing has worked yet. Also, the Arduino seems to have some weird logical rules, I've got "If" statements that seem to run all the time, regardless of the condition being tested.

I'm really curious to see the if statements that run all the time. Sounds bad. Can you post your code?

Crow:
Also, the Arduino seems to have some weird logical rules, I've got "If" statements that seem to run all the time, regardless of the condition being tested.

This is the Gnu C++ compiler you are talking about here. If it had "weird logical rules" your iPhone wouldn't work.

Perhaps show some examples?

I've got "If" statements that seem to run all the time, regardless of the condition being tested.

You probably have

if (x = y)

instead of

if (x == y)

Or comparing a pin number instead of reading the pin value.

Without seeing your code only the Phantom knows, but one thing is certain, the processor is doing exactly what you told it to do :slight_smile:


Rob