Two Arduinos on same serial port

Excuse what may be my shear ignorance on this matter.

I have some Arduino code which controls several TLC5940s for doing PWM on 9 RGBLEDS.

I have another sketch which reads 32 analog sensors from two multiplexers and sends them to Processing via serial.

So, the first sketch really only requires serial IN from the PC, and the second only serial OUT.

Since I want to keep the two isolated to ensure as fast operation as possible, I would like to put one sketch one one Atmega328, and the other on another. I would tie one to Rx on a RS232 breakout, and the other to Tx.

The only downside of this is that even though the one that would be controlling the LEDs only needs serial IN, it'd be nice for it to be able to spit a byte to the PC once in a while to handshake.

SO, my question:

Is it possible to use a shift register or something such that these two Arduinos can use the same Tx and Rx pins on my RS232 breakout? Or should I go about this another way (like, say, using two RS232s and just putting these each on their own serial port)

Thanks!

I am not sure why you want to use two arduinos in the first place. It seem you could simply do it with one.

You have to stop the two systems trying to talk at the same time, you might be able to do this by connecting two pins and have a sort of token holding protocol to decide if it can transmit.

That's not a bad idea. I haven't tested this yet, so I may not have to have two.

The reason I'm thinking about having two is that I am using the one to A2D to read sensors for musical performance, and I want to ensure that things are as fast as possible. I'm already a little concerned because 10 of those sensors are endless rotary encoders, and what I'm reading appears to show the only reliable way to read them is using interrupts.

I'm concerned that this will disrupt the speed of the rest of my system, but who knows...

read sensors for musical performance,

It's all going to go very fast compared with the human feel of a music performance.

he only reliable way to read them is using interrupts.

yes that's right for 10 sensors, you can't poll that many fast enough.

I suppose I'll try it on a single Arduino first. Two questions, then:

  1. Do you know of a good way I can clock how fast things are running? Like some cheap way to figure out how long one cycle through all sensor readings are taking, etc?

  2. If I'm sensing, say 10 pushbuttons, 10 on/off switches, and 10 rotary encoders, would this idea potentially work:

  • Have two 16 channel multiplexers.
  • In main loop, go through channels 1-20 polling the on/off switches and pushbuttons.
  • Have an interrupt that when it gets any transition from either of the squares waves on ANY rotary encoder, polls ALL rotary encoders. Perhaps this is a bad idea:

I probably can't have an interrupt if I'm multiplexing the rotary encoders, since they will only be hooked up to a pin when I'm addressing them on the MUX. Thus, they are always being polled and really can't use interrupts.

Since I have 10, that's 20 input's I would need. There is no way I can do that on Arduino without a multiplexer, which effectively means I can't use interrupts for them, I think!

So, is there any way I can read rotary encoders reliably with polling rather than interrupts? I'm fine with conditioning / decoding in software, if that could work - I'm sending all my sensor readings to Max/MSP, where I could reject noise...

Like some cheap way to figure out how long one cycle through all sensor readings are taking

Two ways:-

  1. Toggle an LED each time round the loop and time the interval with an oscilloscope. (least obtrusive)
  2. Use the millis function to time the length of a loop and print it out at the end (or send a midi message with the time as a parameter and use a midi monitor terminal to see it)

So, is there any way I can read rotary encoders reliably with polling rather than interrupts?

Not for 10 of them. You can simplify things by using a bit of hardware to count pulses you would otherwise miss:-
http://www.thebox.myzen.co.uk/Workshop/Rotary_Max.html

since they will only be hooked up to a pin when I'm addressing them on the MUX

If you take the signal from all the inputs and logically OR them together using gates you will get a signal you can use as an interrupt if any of them goes off.

Alternatively a port expander MCP23016 can be used, that has a pin that changes if any one of the 16 inputs change.

Is it that important that every pulse is gathered? Especially when it is being turned very quickly?