Trinket 5V GPIO doesn't respond to commands

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
waleedelmandouh
 
Posts: 27
Joined: Tue Apr 03, 2018 10:09 pm

Trinket 5V GPIO doesn't respond to commands

Post by waleedelmandouh »

Hello,

I've been playing with the trinket for a couple moth, The GPIOs are not always responding are configured. Let give a few examples.
Example 1:
PINS:0,1,2 are configured as OUTPUT driving 3 LEDs
PINS: 3,4 are configured as INPUT from a Push Button.
All LEDs work fine as programmed, but the Push Bottons don't. When PIN3 Push Button or PIN 4 Push bottom is pushed the do the same action as if PIN 4 was pushed. This means a physical push (closed loop) on PIN3 is detected as closed loop on PIN4, I've revised the wiring are redid it so many times.
Example 2:
PINS:1,2 are configured as outputs driving LEDs
PINS3,4 are configured as inputs from buttons
the logic here is so simple, each button drives a different LED.
when buttons are pushed nothing happens.
Tried switching the wiring and configuration around and got same result, this applies on three different Trinkets 5V.

Anyone faced the same problem or know a solution or what i'm doing wrong?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V GPIO doesn't respond to commands

Post by adafruit_support_bill »

Do you have pullups enabled for the input pins?

User avatar
waleedelmandouh
 
Posts: 27
Joined: Tue Apr 03, 2018 10:09 pm

Re: Trinket 5V GPIO doesn't respond to commands

Post by waleedelmandouh »

I don't know, but i guess not. How do i do that. I'm using the IDE.

User avatar
waleedelmandouh
 
Posts: 27
Joined: Tue Apr 03, 2018 10:09 pm

Re: Trinket 5V GPIO doesn't respond to commands

Post by waleedelmandouh »

I checked the logic, the answer is No, i set the pin mode to input not input pullup, is this the problem?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V GPIO doesn't respond to commands

Post by adafruit_support_bill »

Without a pullup or pulldown resistor, the input is 'floating' when the switch is open. In this case the input can be influenced by many things - including the state of another nearby pin.

The simplest way to handle switch or button inputs is to use INPUT_PULLUP in your call to pinMode.

When using pullup resistors, the pin will be at logic HIGH when the switch is open. If you connect your switch between the input pin and GND, the value will go to logic LOW when the switch is closed.

User avatar
waleedelmandouh
 
Posts: 27
Joined: Tue Apr 03, 2018 10:09 pm

Re: Trinket 5V GPIO doesn't respond to commands

Post by waleedelmandouh »

Bill,

I just tried this and there is no change. I have pins 0,1,2 configured as outputs,pins 3 and 4 configured as INPUT_PULLUP. I have pin 3 drive logic on the output pins, pin 4 has no logic what so ever. i even tried not having a digital read for it put same result.

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V GPIO doesn't respond to commands

Post by adafruit_support_bill »

Please post photos of your soldering and connections. And also please post the code you are using to test.

User avatar
waleedelmandouh
 
Posts: 27
Joined: Tue Apr 03, 2018 10:09 pm

Re: Trinket 5V GPIO doesn't respond to commands

Post by waleedelmandouh »

here is the code

Code: Select all


// Enable 16MHz Mode
#include <avr/power.h>


// constants won't change. They're used here to set pin numbers:
const int Pin0 = 0;
const int Pin1 = 1;
const int Pin2 = 2;
const int PushB1 = 3;
const int PushB2 = 4;
const int PulseTime = 1 * 1000; // relay coil pulse time


// variables will change:
int PB1State = HIGH;         // variable for reading the PB status
int PB1State_L = HIGH;
int PB2State = HIGH;         // variable for reading the PB status
int PB2State_L = HIGH;

void setup() {

  // enable 16MHz Mode
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);

  
  // initialize the relay pins as an outputs:
  pinMode(Pin0, OUTPUT);
  pinMode(Pin1, OUTPUT);
  pinMode(Pin2, OUTPUT);
  // initialize the PB pin as an input:
  pinMode(PushB1, INPUT_PULLUP);
  pinMode(PushB2, INPUT_PULLUP);
}

void loop()
{
  // read the state of the PB value:
  PB1State = digitalRead(PushB1);
  PB2State = digitalRead(PushB2);

  // check if IOLinc Got Energized. If it is, the Open Pin Pulses, then delay for x seconds, then the Stop Pin pulses:
  if (PB1State == HIGH & PB1State_L == LOW)
  {
    // Pulse Open for 1 second
    digitalWrite(Pin0, HIGH);
    delay(PulseTime);
    digitalWrite(Pin0, LOW);
    delay(PulseTime);
    digitalWrite(Pin1, HIGH);
    delay(PulseTime);
    digitalWrite(Pin1, LOW);
  delay(PulseTime);
    digitalWrite(Pin2, HIGH);
    delay(PulseTime);
    digitalWrite(Pin2, LOW);
  }
  PB1State_L = PB1State;
  PB2State_L = PB2State;
  delay(PulseTime);        // delay in between reads for stability
}
Last edited by waleedelmandouh on Thu May 10, 2018 12:52 am, edited 1 time in total.

User avatar
waleedelmandouh
 
Posts: 27
Joined: Tue Apr 03, 2018 10:09 pm

Re: Trinket 5V GPIO doesn't respond to commands

Post by waleedelmandouh »

I checked the soldering ond thd PCB for shorts using a fluke multimeter, everything looks ok. Here are some photos, I wish there clear enough. Can't post files,l because of size limitations, I'll try to post tomorrow after i brimg it down on a pc.

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V GPIO doesn't respond to commands

Post by adafruit_support_bill »

I believe that your logic here is inverted:
if (PB1State == HIGH & PB1State_L == LOW)
With pullups enabled, the natural state of PB1 when not pressed is HIGH.
If wired as I described above, it will go LOW when pressed.

Also, the '&' operator is a 'bitwise AND'. For boolean logic you should be using the '&&' operator.
http://www.learncpp.com/cpp-tutorial/38 ... operators/

User avatar
waleedelmandouh
 
Posts: 27
Joined: Tue Apr 03, 2018 10:09 pm

Re: Trinket 5V GPIO doesn't respond to commands

Post by waleedelmandouh »

Bill,

Thanks for the advice, i didn't think it would make a difference to use bit & or bool &&. For the High I'm just initializing my status tags to show High (buttons not pressed), then i'm taking my action on a button press not button push (this is why i'm keeping record of the last state of the button, so if current state is high (not pushed), last state was low (pushed), this means it was just released and i start the action). I updated the logic to &&, unfortunately this didn't make any difference in the result. The push on pin4 or pin3 will give the result of 3. I'm also resized the photos . attached.
Attachments
20180509_232548.jpg
20180509_232548.jpg (189.25 KiB) Viewed 233 times
20180509_232415.jpg
20180509_232415.jpg (124.28 KiB) Viewed 233 times
20180509_232543.jpg
20180509_232543.jpg (180.08 KiB) Viewed 233 times

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V GPIO doesn't respond to commands

Post by adafruit_support_bill »

i didn't think it would make a difference to use bit & or bool &&.
In this case it probably doesn't. But that is due to an implementation detail on this particular compiler. It is technically incorrect and not guaranteed to work that way.

I can't tell from your photo which button is connected to pin #3. Or whether the button is correctly wired between the pin and ground.

User avatar
waleedelmandouh
 
Posts: 27
Joined: Tue Apr 03, 2018 10:09 pm

Re: Trinket 5V GPIO doesn't respond to commands

Post by waleedelmandouh »

Bill,
please see attached wiring. I've confirmed using multimeter that there are no accidental shorts and it is physically wired as in the drawing. I know i can go for a pro but I really need all 5 IOs on this small footprint i can't go for a pro.
Attachments
wiring.png
wiring.png (15.52 KiB) Viewed 218 times

User avatar
waleedelmandouh
 
Posts: 27
Joined: Tue Apr 03, 2018 10:09 pm

Re: Trinket 5V GPIO doesn't respond to commands

Post by waleedelmandouh »

Bill, i tried this with three different trinkets just in case a trinket was bad. same exact result. Is there is a limitation of any kind on how can i use the 5 GPIO pins as digital input and/or outputs?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V GPIO doesn't respond to commands

Post by adafruit_support_bill »

Your switches are not wired correctly. You have them connected to BAT+ instead of GND.

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”