(Noobs) - rising/fallingEdge... bleed from one pin to another?

Status
Not open for further replies.

CaptMench

New member
My son and I are trying to build a button box using the Teensy for keystrokes to switches. We feel we've done rather well so far, but in trying to get this to work, we've used the risingEdge and fallingEdge with a 40ms pause for the positions of each switch.

Basically using the switch settings as a button, right?

However, we are noticing bleedover onto nearby switches causing them to fire as well. Could this be a ground issue, or a code issue. Does this make any sense?

Sorry - son is the coder, I'm the messenger. If you think you need our code, we'll add it. Different parts of the house as it were.

thanks -
v/r
Mike
 
Likely crosstalk - a cable issue perhaps, or as you say grounding - a lack of enough ground-return wires?
High speed logic signals aren't designed to travel far.
 
Could this be a ground issue, or a code issue. Does this make any sense?

Yes, absolutely, we see this sort of thing all the time. It can be very difficult to know whether a problem is caused by hardware or software when you're creating both.

One way to troubleshoot involves running a known-good example program, even if it's not exactly what you need, so you can at least check if your hardware is ok. For example, maybe try File > Examples > Teensy > USB_Keyboard > Buttons.


Basically using the switch settings as a button, right?

I'm not getting a clear mental picture. Maybe an accurate diagram or photos would help. The exact part numbers or links to the photos and technical data on the exact parts you're really using could also really help.

We can assist you much better if we can see the problem, and even more if you give enough info that we could reproduce the problem. Sometimes we also figure these thing out with pretty much blind guessing, but in this case it's so unclear that I really believe you should take share photos, the code, and links to the parts you're using.


Likely crosstalk - a cable issue perhaps, or as you say grounding - a lack of enough ground-return wires?

Improper ground connections would seem likely. But with a little blind guessing that we're talking about merely mechanical switches and the relatively weak pullup resistors using INPUT_PULLUP, I'd say crosstalk seems unlikely. Usually you need buffers with very fast transistors to get the sort of rapidly changing signals that result in crosstalk. But that's all blind guessing about the switches, whether INPUT_PULLUP is used, and so on...
 
Here's the code that we were using. We have some ON-ON switches and ON-OFF-ON ones.



#include <Bounce.h>
#include <elapsedMillis.h>

Bounce d_switch_0 = Bounce(0,10);
Bounce d_switch_1 = Bounce(1,10);
Bounce d_switch_2 = Bounce(2,10);
Bounce d_switch_3 = Bounce(3,10);
Bounce t1_switch_4 = Bounce(4,10);
Bounce t2_switch_4 = Bounce(5,10);
Bounce t1_switch_5 = Bounce(6,10);
Bounce t2_switch_5 = Bounce(7,10);

elapsedMillis timeElapsed;
unsigned int t_interval = 200; //interval to hold buttons on for when needed



void setup() {
// put your setup code here, to run once:
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);

}

void loop() {
// put your main code here, to run repeatedly:
//UPDATE
d_switch_0.update();
d_switch_1.update();
d_switch_2.update();
d_switch_3.update();
t1_switch_4.update();
t2_switch_4.update();
t1_switch_5.update();
t2_switch_5.update();

//ON-ON Switches (will treat as if ON-OFF)
//want to pulse one joy button for one direction of flip, and another for other direction
if (d_switch_0.fallingEdge()) {
Joystick.button(1,1);
timeElapsed = 0;
}
else if (d_switch_0.risingEdge()) {
Joystick.button(2,1);
timeElapsed = 0;
}

else if (d_switch_1.fallingEdge()) {
Joystick.button(3,1);
timeElapsed = 0;
}
else if (d_switch_1.risingEdge()) {
Joystick.button(4,1);
timeElapsed = 0;
}

else if (d_switch_2.fallingEdge()) {
Joystick.button(5,1);
timeElapsed = 0;
}
else if (d_switch_2.risingEdge()) {
Joystick.button(6,1);
timeElapsed = 0;
}

else if (d_switch_3.fallingEdge()) {
Joystick.button(7,1);
timeElapsed = 0;
}
else if (d_switch_3.risingEdge()) {
Joystick.button(8,1);
timeElapsed = 0;
}


if (timeElapsed > t_interval) {
Joystick.button(1,0);
Joystick.button(2,0);
Joystick.button(3,0);
Joystick.button(4,0);
Joystick.button(5,0);
Joystick.button(6,0);
Joystick.button(7,0);
Joystick.button(8,0);
}






//ON-OFF-ON switches: one joy button for top and bottom, if neither are on pulse middle button

if (t1_switch_4.fallingEdge()) {
Joystick.button(9,1);
timeElapsed = 0;
}//switch up

if (t1_switch_4.risingEdge() || t2_switch_4.risingEdge()) {
Joystick.button(10,1);
timeElapsed = 0;
}//switch middle

if (t2_switch_4.fallingEdge()) {
Joystick.button(11,1);
timeElapsed = 0;
}//switch down


if (t1_switch_5.fallingEdge()) {
Joystick.button(12,1);
timeElapsed = 0;
}//switch up

if (t1_switch_5.risingEdge() || t2_switch_5.risingEdge()) {
Joystick.button(13,1);
timeElapsed = 0;
}//switch middle

if (t2_switch_5.fallingEdge()) {
Joystick.button(14,1);
timeElapsed = 0;
}//switch down




if (timeElapsed > t_interval) {
Joystick.button(9,0);
Joystick.button(10,0);
Joystick.button(11,0);
Joystick.button(12,0);
Joystick.button(13,0);
Joystick.button(14,0);

}






}//end of voiploop
 
Here is the hardware side of things. We have a teensy 3.2 on a breadboard to connect everything. The black wires are our ground, yellow for the 2-position switches and white for the 3-position switches. We didn't solder anything, we figured for this test project we could just twist the wires on.

Hardwareforpractice.jpg

IMG_4777.jpg
 
Soldering is not optional here, unreliable connections are never worth it...

Well the wirings fairly short at least, but you're not using twisted pair so there's a lot of crosstalk possible.
Twisted pair is pretty easy to make:
https://www.youtube.com/watch?v=cTM_vxGeGeo

Or you can strip the jacket off some CAT5 cable and use the 4 twisted pairs within it.
 
Agreed, you need to solder the connections to the switches.

I still recommend running File > Examples > Teensy > USB_Keyboard > Buttons simply to test the hardware using known-good software.

This part of the code might have an issue:

Code:
if (timeElapsed > t_interval) {
Joystick.button(9,0);
Joystick.button(10,0);
Joystick.button(11,0);
Joystick.button(12,0);
Joystick.button(13,0);
Joystick.button(14,0);

}

After timeElapsed has increased to more than 200, this will transmit 6 button off messages to your PC. You probably only meant for it to do that once. But it will keep needlessly transmitting that same set of messages as fast as the USB can go. To make this work the way you probably intended, you should do something like set timeElapsed back to zero. Or add another boolean variable to remember whether you've sent this message, where you'd only do this transmit if the timeElapsed has grown large and the variable indicates a message is needed. You'd write to that variable if you want to allow timeElapsed to keep growing, so that each time loop() runs again, your code will know that it already sent the message and avoid flooding your PC with needless communication.
 
Everyone.... thanks for the patience!!

We’ll digest the help and keep going on it. After reading a few of the other threads on this site I’m impressed with the depth of comments AND help here.

Yes, we were trying to start slow and test before buying our soldering iron and enclosure. Ok, off to HomeDepot today.

Mike and Alex
 
Status
Not open for further replies.
Back
Top