Two-way rocker switch for both power and two inputs? (Doesn't work as expected)

Status
Not open for further replies.
Greetings,
I have a Teensy LC HID project going on. For additional I/O, I wanted to use a two-way rocker switch which could both power on the device and provide two more inputs. (2 birds one stone as space is very limited in the project case) For example, currently I have the middle main terminal of the rocker switch connected to the negative of a battery. Then I have two leads for each of the other two output terminals on the switch which are then soldered to the boards inputs. I can't run wires from the two posts to grounds as they will not be independent signals... Amazingly enough, this still powers on the board!

In code, I have it light an LED that changes colors to determine which pin (internal pullup) is pulled low. One pin reads correctly and lights the LED correctly for one mode. The other pin, other mode, or other rocker switch setting, doesn't work - unless I add an additional ground from the battery to another negative circuit. But THEN, the Teensy doesn't power off when the rocker switch is disabled. So I really don't know what to do at this point to fix the one side of the rocker switch. I've been playing around with additional ground here or there or resistors etc.

(Side note, serial printing is not working for whatever reason. It would help to see the state of the pin(s). It's setup right in Linux, ports, code, buad rates, quality USB cables, etc. Just refuses to work.)

61+v4JJItZL._SL1200_.jpg
 
Not clear on your schematic but it will be tricky to both power and sense through the one set of switch contacts (normally you would use a double throw switch for something like this). Using a pair of diodes may get you where you want. Diodes will have the side effect of adding a 0.5V voltage drop which may be a problem to the rest of the circuit if this is USB powered.

You may want to mock up your sense circuit in an online spice model to make sure you are getting what you want. Measuring voltages with a meter may also make things clearer.

With getting serial terminal to work suggest running some of the serial examples (including on a spare teensy if you have one) to see if it is your code, your Teensy or your PC that is blocking communication.
 
Not clear on your schematic but it will be tricky to both power and sense through the one set of switch contacts (normally you would use a double throw switch for something like this). Using a pair of diodes may get you where you want. Diodes will have the side effect of adding a 0.5V voltage drop which may be a problem to the rest of the circuit if this is USB powered.

You may want to mock up your sense circuit in an online spice model to make sure you are getting what you want. Measuring voltages with a meter may also make things clearer.

With getting serial terminal to work suggest running some of the serial examples (including on a spare teensy if you have one) to see if it is your code, your Teensy or your PC that is blocking communication.

I got serial to work somewhat. Kind of dodgy though. Flicking it seems to work sometimes. :D But turns out it's not dropping those pullups to change modes. Onto plan B. The problem is the switch controls the negative circuit of things....

Currently, I'm trying to make two voltage like sensors between the center and two terminals of the rocker switch. Have the switch go straight to ground on the Teensy; better all around. But have two different resistors on each side of the switch should allow myself to analog read them to determine which side is enabled and thus which mode to run. If you have any easier means of doing that would be helpful? The little case is packed full as it is.
 
If I am understanding the design right, you have gnd on the center pole of the switch and the circuit is connected to both poles of the rocker switch and you want to enter a different mode depending on which way the switch is toggled?

Difficulty is that your circuit is connected to both poles of the switch, so electrically both points are the same and impossible to tell apart. Diodes are one option to differentiate things, also ugly is running the return through a very low value resistor one one pole and then using a voltage divider to read the Teensy supply voltage (teensy LC does not handle voltages <0 or >3.3V at all well) and then measuring the '5V' supply. If the measure result is 5V you are connected normally, if it is lower than 5V you have the resistor in the current path. Since the value measure will change with current consumption this is tricky to do reliably, and will prevent USB operations if you get any serious difference between USB gnd and the gnd in the device due to the resistor.

Think you certainly want to be modeling how this will actually work and/or building a bench mock up of it since there are a number of ways to make this that will destroy the LC.
 
Re-reading your origional post and it looks like you are actually powering the Teensy through the IO pins? Which means you are depending on the reverse polarity protection diodes to make this work. This would potentially explain erratic USB operation since you may have 0.5-0.7V difference between USB gnd and the Teensy.

If you are going to do that you would be better off adding your own higher spec/lower voltage drop diodes and connecting things more normally.

To usefully provide more help a schematic of the relevant parts of your design may be helpful, along with measured voltages for each of the three switch poistions with respect to the Battery gnd pin for:
Teensy Gnd pin
Teensy 3.3V pin
Teensy Vin pin
Both digital IO pins
 
Possible method

first guess at R1/R2 would be 1k, with pins configured as pullups. Still means Teensy -ve and powersupply -ve are not the same so care needed to make that work right and abusing the protection doides to avoid blowing the Teensy up. Better method would involve an op amp or restive divider to bot not up for the math on getting 0 and 3.3V on the Teensy pin form a -0.5V supply.Negative switch detection.jpg
 
Possible method

first guess at R1/R2 would be 1k, with pins configured as pullups. Still means Teensy -ve and powersupply -ve are not the same so care needed to make that work right and abusing the protection doides to avoid blowing the Teensy up. Better method would involve an op amp or restive divider to bot not up for the math on getting 0 and 3.3V on the Teensy pin form a -0.5V supply.View attachment 14025

Thank you very much for your help. I'm truly sorry I cannot provide a schematic at this time. It is quite simple really despite all the wires. There are just a lot of wires because there are a lot of accessories. It's simply a device that presses a button... But you can switch from up or down on the rocker switch to make 3 buttons into 6. It is hard to design something that'll work off of batteries, but fails tests powered via usb!

I'm sure you could understand the frustration and eagerness to get it working when this issue is truly the last piece of the puzzle to having this whole thing work. It literally pushes all the right buttons, besides that second mode. I do greatly appreciate your advice and efforts. I follow your schematic. However, I do not have any diodes on hand to test with at the moment. There is 0 room to work with. A few resistor sized items may work. :D

Side note, I'm powering the Teensy with two coin cell batteries in parallel (for mah) as you can see in the images. However, there is a voltage divider circuit for the 5V of the front usb. I need to detect when the device is supposed to press a button, but the machine is not powered on. It alerts the operator as the machine reboots etc.
 
Last edited:
If all this does is turn 3*2 buttons into keypresses it should power from the hub fine, drawing much less than an ordinary keyboard. So if it was not working that may mean you have/had a short or other problem drawing too much current. Or is this supposed to do something at boot and things took too long to kick in?

Still unclear on the power arrangements, which may have bearing on what is happening. First up, have you cut the trace on the underside of the Teensy to isolate batteries from USB power?

If you are running off batteries in parallel you will be on marginal low side voltages, starting at 3.3V and falling to ~2.6 as they drain down. For stable operation you would normally need a boost regulator to stablise the power.

If the 5V USB is being measured, and the power supply is unregulated you will potentially be seeing a swing in the measure value as the reference voltage falls.

If things are working it is all good but from the description there are a number of marginal points in this that may be a problem later that are worth a look for version 2.
 
If all this does is turn 3*2 buttons into keypresses it should power from the hub fine, drawing much less than an ordinary keyboard. So if it was not working that may mean you have/had a short or other problem drawing too much current. Or is this supposed to do something at boot and things took too long to kick in?

Still unclear on the power arrangements, which may have bearing on what is happening. First up, have you cut the trace on the underside of the Teensy to isolate batteries from USB power?

If you are running off batteries in parallel you will be on marginal low side voltages, starting at 3.3V and falling to ~2.6 as they drain down. For stable operation you would normally need a boost regulator to stablise the power.

If the 5V USB is being measured, and the power supply is unregulated you will potentially be seeing a swing in the measure value as the reference voltage falls.

If things are working it is all good but from the description there are a number of marginal points in this that may be a problem later that are worth a look for version 2.

I cut the 5V line of the USB cable instead of the trace on the board. Then it goes through a voltage divider circuit to be read. But there are no problems with the keyboard functionality or anything like powering everything.

This is my third HID device like this. I found x2 CR2023 coin cells (which I have endless amounts of) powered previous projects for weeks; working 2-3 hours on an off per day. But it always turned out someone left it on and drained the batteries so I can't determine how long they'll last. As soon as I get the 2 modes of the rocker switch figured out. It's done.
 
Status
Not open for further replies.
Back
Top