Hi guys, wanted to get some feedback about an issue I'm trying to solve. I'm trying to interface an Arduino Pro Mini to the Bluegiga WT12, but this issue really applies to any situation where an Arduino with separate USB adapter (e.g. Pro Mini or RBBB) is interfacing to a UART/serial peripheral.
I would like to have my peripheral attached to Arduino RX/TX pins and still be able to upload sketches via my separate USB/UART module (USB-BUB). The issue is that having both the peripheral and the USB adapter attached at the same time causes problems and potential damage.
The way I have attempted to solve this is using a Form A / Form B solid state relay (LH1512). I run the USB supply voltage through the relay's LED pins to ground, so that when USB is attached it activates both the normally open (NO) and normally closed (NC) pins of the relay. The NO pins connect the USB supply voltage to the Arduino VCC. The NC pins connect the Arduino RX to the peripheral TX. Schematic here: http://i55.tinypic.com/2e6at55.jpg
What I'm hoping this accomplishes is that when USB is attached, it connects its own supply to the Arduino VCC while simultaneously disconnecting the peripheral TX from Arduino RX, allowing USB to upload sketches without conflicting with the peripheral. When power is supplied from somewhere other than USB, the relay is not activated and the peripheral TX is left connected to Arduino RX for normal operation.
I ran some tests with some relays I had lying around and it seemed like this should work. Hopefully someone more experienced can give me feedback if this seems like a viable method, or if there is some better, more standard way to handle this issue. Also, is it enough to disconnect the peripheral TX line, or should I also disconnect the peripheral's RX to be safe?
Occurs to me a simpler solution may be to have the relay disconnect the peripheral's power when USB is connected. But I suppose it may depend on the peripheral what state the pins are in when it is unpowered and whether there is still any potential for damage?
In the schematic the two coils seem to be in series, that must be a very low voltage relay.
If the relay is DPDT (not the one in the schematic, or did you not draw the COM pins) why not just swap the TX/RX signals over and leave VCC alone. You will probably get glitchs on the lines which may or may not affect you gadget.
Alternatively use a 4066 transmission gate and an inverter to make a DPDT switch.
Good point; the "coils" are LEDs of course, but yeah it should be just low enough to allow series on 3.3V. There are even lower voltage ones available from Omron or Panasonic, but I guess if I wanted to add any additional switching channels I should just wire them in parallel.
On your suggestion to just swap the TX/RX and leave VCC alone, I think what you're suggesting is that I run the whole setup off a separate power supply all the time, and then when uploading code I can use the USB power just to run the relay LEDs and swap only TX/RX. So in that case USB power wouldn't be connected to the Arduino at all. That seems like a good suggestion. I had come at it with the idea that when uploading code I would power the whole thing off USB, so then there was a need to switch the USB power through the relay to get full power to Arduino VCC but not allow Arduino VCC to trigger the relay when USB was detached.
Would still love to hear some thoughts on what really needs to be switched out to be safe: peripheral TX, peripheral power, or some combination of TX/RX/power?
Good questions. I'd rather have one less thing to plug/unplug; USB is kind of unavoidable. Also this way it is idiot proof, so I don't have to worry about forgetting to unplug (although the possibility of damage is probably not sooo high). Also the WT12 board is not so fun to breakout, although I do have an as yet unproven breakout design, but it takes less space without adding headers. Of course, since the relays don't really come in smaller than DIP packages, not clear that this solution saves space...
I do think it's nice to allow some in-field programming, but it probably doesn't have to be as integrated as this; I could probably unplug the Pro Mini to do any reprogramming and then plug it back in. But if I ever moved to a version with the straight AVR instead of a Pro Mini then I would definitely want to integrate something like this.
Anyway, these are good big picture questions, but half the reason I posted was just to get some expert opinions on ways to solve this kind of problem; I'm pretty new to designing anything more complicated than "hook RX to TX and TX to RX".
It sometimes happens that cutting the power from a peripheral doesn't actually work because an input pin (Rx say) is internally connected to VCC via a clamping diode. I've had situations where I couldn't turn off a display without sending the Tx from the AVR low or making it an input.
Whether or not that will be the case with the WT12 I don't know.
What you have done is pretty close I reckon, but I would leave VCC and use two relay poles (get a dual form B) to disconnect the WT12 Rx/Tx when the USB is plugged in. I'm not familiar with that relay and the only spec sheet I could find started at page 42, so I still don't know exactly what switching it has.
If you're worried about size there is a Clare CPC1014N relay, they are tiny (4x4mm) relays, SMDs but should still be easy to solder. These are the wrong polarity (form A) but they might have form B version or you could use an inverter.
Cool, thanks for all your help! That is my concern with just cutting power; I should be able to figure out how the pins are left unpowered, but I'd rather not mess around with that. What is the concern with leaving Ard TX -> WT12 RX attached? I would assume the WT12 RX is high impedance, so the only downside would be the WT12 getting crap at the wrong baud as input during code upload, which I would have thought would be okay?
I'm thinking now that maybe I should work from the other end and set it up to connect the peripheral only when powered from the non-USB source. If doing it this way, I believe it requires the supply to be routed through the NO relay pins. Actually this is the part of the circuit I am most curious about; it seems a little sketchy to me to run the relay LED from the same supply that you are sending through the NO MOSFET pins. But I guess it should be fine. At the same time, this is the most interesting part to me because if it works it seems to be a reliable way for the circuit to know which power supply it is connected to at any time.
Thanks for the lead to Clare relays. It looks to me like even their SMD packages are still 0.1" spaced pins though, so probably not much smaller (footprint-wise) than a standard DIP. This seems typical for these relays; probably cannot be made smaller due to the optical components?
so the only downside would be the WT12 getting crap at the wrong baud as input during code upload
Correct.
run the relay LED from the same supply that you are sending through the NO MOSFET pins
Seems reasonable, bear in mind that MOSFETs have a parasitic diode that conduct it the power is reversed even if the switch is "off". But these relays all use FETs (or back-to-back MOSFETS) I think so that doesn't count.
so probably not much smaller (footprint-wise) than a standard DIP
Yeah the duals are just DIPs with the legs bent in. The singles are in a smaller package but if you need two you're back where you started.
So I guess it depends on the peripheral whether it's okay to send garbage input during upload... Probably not worth the risk.
Looking up "parasitic diode" now...
I've gone ahead and redesigned the circuit; I think it's an improvement: http://i56.tinypic.com/2mzw9xh.jpg As usual I was getting too fancy with running the USB power line through the relay to prevent the other power source from triggering the relay; simpler to just run USB power through a normal diode!
I decided to trigger the relay from USB after all, rather than triggering from the other power source. The other source could be +3.3-12V in either VCC or RAW, so that was getting complicated. A zener shunt would have taken care of it I guess, but I think that would have been a waste of power.