Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpPrograms › multiple input mode problem

Page Index Toggle Pages: 1
multiple input mode problem (Read 10141 times)
09/04/05 at 10:43:59

geek05   Offline
YaBB Newbies

Posts: 2
*
 
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?
 
IP Logged
 
Reply #1 - 09/07/05 at 04:12:45

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
Which digital I/O pin are you using to connect the button?
 
IP Logged
 
Reply #2 - 11/17/05 at 04:23:00

Sean_Dockray   Offline
YaBB Newbies

Posts: 2
*
 
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;
}

---
 
IP Logged
 
Reply #3 - 11/17/05 at 04:49:15

Sean_Dockray   Offline
YaBB Newbies

Posts: 2
*
 
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;
}

---
 
IP Logged
 
Reply #4 - 11/20/05 at 02:29:16

eucarya   Offline
YaBB Newbies
Phoenix, AZ

Posts: 28
*
 
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.
 
IP Logged
 
Reply #5 - 11/22/05 at 21:50:45

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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);
}
 
IP Logged
 
Reply #6 - 11/23/05 at 02:39:34

mellis   Offline
YaBB Newbies

Posts: 43
*
 
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)) {}
 
IP Logged
 
Reply #7 - 11/25/09 at 17:03:39

JuanMa   Offline
YaBB Newbies

Posts: 1
*
 
hey people Smiley 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... Undecided

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  Cheesy
 
IP Logged
 
Reply #8 - 11/26/09 at 06:45:36

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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.
 
IP Logged
 
Page Index Toggle Pages: 1