Author Topic: Having issues reading from P0  (Read 3345 times)

maudette01432

  • Newbie
  • *
  • Posts: 16
Having issues reading from P0
« on: January 06, 2013, 03:27:03 pm »
I'm using the following code - I tried on two digisparks but both type "Hello D" regardless wether P0 is wired to ground or not (i.e. the internal pull-up of the ATiny is defeated by the LED).  I believe the the LED is causing the issue.

Code: [Select]

#include "DigiKeyboard.h"

void setup() {
  pinMode(0, INPUT);
  digitalWrite(0, HIGH);  // Enable internal pullup
}


void loop() {
 
  DigiKeyboard.update();
  DigiKeyboard.sendKeyStroke(KEY_D, MOD_SHIFT_RIGHT);
  DigiKeyboard.sendKeyStroke(KEY_A);
  DigiKeyboard.sendKeyStroke(KEY_T);
  DigiKeyboard.sendKeyStroke(KEY_A);
  DigiKeyboard.sendKeyStroke(KEY_SPACE);
 
  if ( !digitalRead(0) ) {
    // Pin pulled low
    DigiKeyboard.sendKeyStroke(KEY_D,MOD_SHIFT_RIGHT);
  } else {
    // Pin pulled high
    DigiKeyboard.sendKeyStroke(KEY_U,MOD_SHIFT_RIGHT);
  }
  DigiKeyboard.sendKeyStroke(KEY_ENTER);
  delay(5000);



}


According to the schematic P0 makes a straight connection to the edge connector (but the schematic on the customer download says rev3 on it so it may not be what actually shipped to kickstarter folks - I have what appears to be REVB - according to the WIKI which has the LED on P0).  In the example above the LED glows faintly and shorting P0 to GND does not alter the output (pulled down - apparently through the LED).  As such this pin cannot be used as an input without modifying the board (I'm assuming cutting the trace will do the trick  but really don't want to go cutting traces willy nilly without knowing if in fact it will do the trick - since I can barely see the trace).  According to the wiki this pin should be able to be used as an input without modifying the board - except for I2C use).  I haven't had this issue on the Arduino Uno boards I have even with the LED on there - so I'm guessing a little has to do with component selection (R5 in the REV3 schematic).

The schematic I have isn't annotated with a value for R5 and I cant read the part with my Loupe. Could you shed some light on this please and provide me a link (via e-mail) for the schematic of the "REVB" board)?  There must be a reason why you changed the LED position yet again and why I can't seem to use P0 as an input with a pull-up.  Since I don't have a schematic that matches what was shipped for me I'm a little at a loss - it makes it hard to work-around when you can't see what's going on on the board.  I'm guessing I'll still be able to use these board but will obviously have to work-around the issue in some way.  knowing the value of R5 will help out.
« Last Edit: January 06, 2013, 03:27:51 pm by maudette01432 »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Having issues reading from P0
« Reply #1 on: January 06, 2013, 06:27:14 pm »
The only difference in the schematic for model B is that the trace from PB1 to LED connects to PB0 instead of PB1 - otherwise it is exactly the same. The schematic online for rev3 is the same as the schematic for Model A, so there has been only one LED change, and that was for the I2C reasons given.

The LED (whether it is on PB0 or PB1) make the pin impractical for using the internal pull-ups - in fact on an attiny I generally don\'t use the internal pullups becase they have a very high resistance (over 25k) and are a bit picky. Hence the pullups on all of our I2C boards. (I\'ll add a note about this to the wiki when I have a moment)

If you cut the trace it will work - any reason you don\'t just pull it high (instead of pulling it low), that would work - or you could use a different pin.

R5 depends on what LED is - in the case of Model B boards it is 680ohm  and LED is 5ma Green 0603. As is often the case, some value get determined for each run of the board based on the available parts, that is why they aren\'t on the schematic. Just about any LED (and corresponding resistor) would be a challenge for the attiny\'s pullups though, so this will be a common issue with most boards smaller and cheaper than the ATMega series.

Hope that helps,
Erik


maudette01432

  • Newbie
  • *
  • Posts: 16
Having issues reading from P0
« Reply #2 on: January 06, 2013, 07:30:42 pm »
Thanks for the response.  Just trying to figure out what I have in my hands.  It might work for me without cutting the trace - I\'ll just have to re-wire and re-code a little.   I haven\'t had too many problems with Atmel\'s internal pullups in the past and am, like the you have done with the digispark, trying to save on component count and keep things simple.

So far I\'m pretty happy with the digisparks  It\'s a learning curve with a new board.  Thanks again - and the work on updating the Wiki will help answer these same questions as more people get the boards in their hands.  A couple people have already commented on my tray on thingiverse that they are still patiently waiting for theirs.

http://www.thingiverse.com/thing:40032  -- digispark board holder/protector
« Last Edit: January 06, 2013, 07:30:57 pm by maudette01432 »