Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Programs >> multiple input mode problem
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1125830640

Message started by geek05 on 09/04/05 at 10:43:59

Title: multiple input mode problem
Post by geek05 on 09/04/05 at 10:43:59
i run into a deadend and my suspicion is, there might be a firmware bug on the wiring board.

it seems each time a serial event is triggred, the digital ports (set as INPUT) are triggerd as well.

in my application a button is connected to one of the digital io ports (set as input) and the script checks the input status (digitalRead(button_pin)) in the main loop. the script has also a serialevent() function. each time it receives a char through the serial port the button digitalRead is HIGH, without the button being pressed.

can anybody confirm this is a problem?

Title: Re: multiple input mode problem
Post by barragan on 09/07/05 at 04:12:45
Which digital I/O pin are you using to connect the button?

Title: Re: multiple input mode problem
Post by Sean_Dockray on 11/17/05 at 04:23:00
This may or may not be related...

I am counting how many cycles a particular pin stays high.  For some strange reason, the following bit of code only works on the first pin of PORT 0 (pin 0, none of the others) and the first pin of PORT1 (pin 8, none of the others).

I've done the "pinMode(whateverPin,INPUT);" thing in setup for each pin I've tried.  Then I just call the function readPulseWidth(whateverPin) and send the results to the serial monitor.  After many wiring permutations, I'm positive that it only depends on which pin I'm using.  Even in an utterly simple example hardcoding the pin number, it behaves the same.  Only the first pin in each port (0,8,16) works.

Am I missing something obvious??

---

int readPulseWidth(int pin) {
 counter = 0;
 while (digitalRead(pin)==HIGH) {
   counter = 0;
 }
 while (digitalRead(pin)==LOW) {
   counter = 0;
 }
 while (digitalRead(pin)==HIGH) {
   counter++;
 }
 return counter;
}

---

Title: Re: multiple input mode problem
Post by Sean_Dockray on 11/17/05 at 04:49:15
This may or may not be related...

I am counting how many cycles a particular pin stays high.  For some strange reason, the following bit of code only works on the first pin of PORT 0 (pin 0, none of the others) and the first pin of PORT1 (pin 8, none of the others).

I've done the "pinMode(whateverPin,INPUT);" thing in setup for each pin I've tried.  Then I just call the function readPulseWidth(whateverPin) and send the results to the serial monitor.  After many wiring permutations, I'm positive that it only depends on which pin I'm using.  Even in an utterly simple example hardcoding the pin number, it behaves the same.  Only the first pin in each port (0,8,16) works.

Am I missing something obvious??

---

int readPulseWidth(int pin) {
 counter = 0;
 while (digitalRead(pin)==HIGH) {
   counter = 0;
 }
 while (digitalRead(pin)==LOW) {
   counter = 0;
 }
 while (digitalRead(pin)==HIGH) {
   counter++;
 }
 return counter;
}

---

Title: Re: multiple input mode problem
Post by eucarya on 11/20/05 at 02:29:16
I think I have noticed something similar to this.
What I did was have each port either INPUT or OUTPUT. I noticed issues when I had both an INPUT and OUTPUT pin on the same port.

See this for more info: http://wiring.org.co/reference/portMode_.html

Not sure if its a bug, or if the Wiring I/O board is setup this way on purpose.

Title: Re: multiple input mode problem
Post by barragan on 11/22/05 at 21:50:45
hey guys, I had a similar issue, here is what I did:

check the new diagram for wiring a switch: http://wiring.org.co/reference/electronics/button.html

also check the following code from one of my students, he's reading several switches at a time and then writting 0's and 1's to the serial port:

int mandado = 0;
int ledpin = 48;        // LED connected to pin 48 (on-board LED)
int switchpin_a = 0;    // switch connected to pin 0
int switchpin_b = 1;    // switch connected to pin 1
int switchpin_c = 2;    // switch connected to pin 2
int switchpin_d = 3;    // switch connected to pin 3
int switchpin_e = 4;    // switch connected to pin 4


void setup()
{
 pinMode(ledpin, OUTPUT);        // pin 48 (on-board LED) as OUTPUT
 pinMode(switchpin_a, INPUT);    // pin 0 as INPUT
 pinMode(switchpin_b, INPUT);    // pin 1 as INPUT
 pinMode(switchpin_c, INPUT);    // pin 2 as INPUT
 pinMode(switchpin_d, INPUT);    // pin 3 as INPUT
 pinMode(switchpin_e, INPUT);    // pin 4 as INPUT
 Serial.begin(9600);             // start serial communication at 9600bps
 digitalWrite(ledpin, HIGH);     // turn ON the LED
}

void loop()
{
 if(digitalRead(switchpin_a) == LOW)           // if switch connected to pin 0 is ON
 {
   Serial.write('1');                          // send 1 to Processing
   mandado = 0;
 }
 else
 {
   Serial.write('0');                          // send 0 to Processing
   mandado = 1;
 }
 if(digitalRead(switchpin_b) == LOW)      // if switch connected to pin 1 is ON
 {
   Serial.write('1');                          // send 1 to Processing
   mandado = 0;
 }
 else
 {
   Serial.write('0');                          // send 0 to Processing
   mandado = 1;
 }
 if(digitalRead(switchpin_c) == LOW)      // if switch connected to pin 2 is ON
 {
   Serial.write('1');                          // send 1 to Processing
   mandado = 0;
 }
 else
 {
   Serial.write('0');                          // send 0 to Processing
   mandado = 1;
 }
 if(digitalRead(switchpin_d) == LOW)      // if switch connected to pin 3 is ON
 {
   Serial.write('1');                          // send 1 to Processing
   mandado = 0;
 }
 else
 {
   Serial.write('0');                          // send 0 to Processing
   mandado = 1;
 }
 if(digitalRead(switchpin_e) == LOW)      // if switch connected to pin 4 is ON
 {
   Serial.write('1');                          // send 1 to Processing
   mandado = 0;
 }
 else
 {
   Serial.write('0');                          // send 0 to Processing
   mandado = 1;
 }
 Serial.write('A');                          // send A to Processing
 //delay(10);                                  // wait 10ms for next reading

 delay(500);
}

Title: Re: multiple input mode problem
Post by mellis on 11/23/05 at 02:39:34
There is a bug in the digitalRead() function: it doesn't always return HIGH when a pin is high.  Instead, the value depends on the position of the pin in the port.

For now, instead of:

if (digitalRead(pin) == HIGH) {}

use:

if (digitalRead(pin) != LOW) {}

or:

if (digitalRead(pin)) {}

Title: Re: multiple input mode problem
Post by JuanMa on 11/25/09 at 17:03:39
hey people :) I have already the code for communicating processing and wiring, but my question is a bit electronical. I could say I have a really good knowledge in prograaming and solving code problems, but... :-/

If I wat to use several buttons connected in a wiring... do i have to use a protoboard in order to connect all of them to Wiring? please help, i donīt have a very large knowledge in electronics, thanks  :D

Title: Re: multiple input mode problem
Post by barragan on 11/26/09 at 06:45:36
A protoboard makes easy to do a prototype check this: http://wiring.org.co/learning/topics/switchesprocessing.html , then you could move to a generic pcb to fix things like this soldering protoboard: http://www.nastypixel.com/instantsoup/recipes/tinkertoy/build/
I hope this help, let me know.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.