I have 4 normally open momentary blade switches hooked up to my Diecimila's digital pins 2-5. When I fire up the Max/MSP patch that's talking to the Arduino, the signal I'm getting back from these inputs isn't very stable. Sometimes it's all 1's, sometimes all 0's and it flips randomly between the states across all 4 pins.
All the switches still work, as in pressing them switches whatever state the pin is in, either from 1 to 0 or vice versa, but in order for me to actually do anything with the input I need to have these pins be at a steady state, be it 1 or 0, so that I can test to see if the switch is depressed or not.
Any ideas on some hardware I can solder inline to clean up this signal noise? I've heard both resistors and capacitors mentioned in passing, but I've no idea how I'd use them in this setup, or if they'd even work.
Have you by any chance heard of debounce? Is this the "noise" you're dealing with?
Nope, the switching itself is very clean, it's just that the steady-state signal from the open switch randomly shifts back and forth between 0 and 1, sometimes for several minutes at a time, others switching over every several hundredths of a second. Using a debounce routine to filter the flipping would work to filter out the quick flips, but when the signal inverts for long stretches at a time, it would register as an actual switch instead of just noise.
Are your pins floating when the switch is open? If so, try connecting a resistor (any thing between 1k and 5k would work) between the input pin and the 5v line. Connect your switch so that when closed it pulls the digital input pin to ground. There are other wiring options you can use but that is a simple test to see if the floating input is your problem
Are your pins floating when the switch is open? If so, try connecting a resistor (any thing between 1k and 5k would work) between the input pin and the 5v line. Connect your switch so that when closed it pulls the digital input pin to ground. There are other wiring options you can use but that is a simple test to see if the floating input is your problem
Floating sure sounds like what's going on. I'll grab some resistors during lunch and hook one up to see if that doesn't solve the problem. I assume the internet will tell me more than I ever wanted to know about wiring resistors.
You may also use the Arduino's internal pull up resistors. After setting your pin as an input, use a digitalwrite(x,HIGH) to enable the pull-ups.
(From the reference section)
pinMode(pin, INPUT); // set pin to input
digitalWrite(pin, HIGH); // turn on pullup resistors
Seemed easy enough, but after adding the digitalWrite(pin, HIGH) for each of the 4 read pins, SimpleMessageSystem stopped working entirely, even the digitalWrite section which was working earlier. I commented out those lines and re-uploaded to the Arduino and still nothing through SMS. I then tried to use the default example code that comes with SMS both for the Arduino and the max patch, still nothing.
I tried using the example "digital blink" code, and it works across all pins, so I know the pins themselves aren't fried, but SMS seems to be dead for some reason. Anyone had any experiences like this where using the on-board pull-up resistors disabled SMS? Though we're now getting into software, figured I'd post this here for continuity, and if I get no replies I'll start up a new thread in the software section.