TinyCircuits Forum

TinyCircuits Products => TinyDuino => Topic started by: Grimstone on July 17, 2017, 09:26:45 PM

Title: Push Button Issue
Post by: Grimstone on July 17, 2017, 09:26:45 PM
I am feeling incredibly stupid and after all the things I have made on my own, I cannot seem to get a simple push button to work correctly on the TinyScreen+. I have it connect to a proto board in which I am running a 10K resistor from 5v output to digital pin 5 and pin 5 also to my button. The other button lead to my ground. I have tested it with my multimeter and everything looks a go.

I've set pinMode(5, INPUT); and when I do a digitalRead(5), I get 0 no matter if the button is pressed or not. I have set the pin to HIGH and to LOW. Neither changes the results. I've read so many push button arduino tutorials and debugs, but I can't figure it. I have even used a different Tinyscreen+ just in case something may be wrong with the first's pin 5. What am I not seeing?
Title: Re: Push Button Issue
Post by: Grimstone on July 19, 2017, 07:36:59 AM
The sadness just seems to continue. I cannot seem to find a resolution here. The TS+ does not seem to register changes in input. I have tried it with an external resistor (digitalRead(5)==0). I have tried it with the pullup resistor (digitalRead(5)==1). I have tried it with the resistor coming off the VBat. I have tried it with the resistor coming off the ground. Regardless, no change of state when the button is pushed. Sadness. I have built all kinds of devices with TinyDuino and now this simple push button is crushing my soul.
Title: Re: Push Button Issue
Post by: Grimstone on July 19, 2017, 08:43:47 PM
So because I thought I was going crazy, I went out and bought an Arduino Mega 2560. I transfered my same sketch to it and works fine. So why does this not work on a TS+?

Code: [Select]
#include <Wire.h>

#define BUTTON_PIN        5  // Button
#define DELAY            20  // Delay per loop in ms

  #define SM Serial

void setup()
  //digitalWrite(BUTTON_PIN, HIGH); // pull-up

void loop()
  int i = digitalRead(BUTTON_PIN);
  SM.print("Button Result: ");
  if(i==HIGH) SM.println("high");
  else SM.println("low");

It just continually shows the pin as set to high.
Title: Re: Push Button Issue
Post by: Ben Rose on July 25, 2017, 05:32:52 PM
Wow, sorry about this not working. I tested the code on a board here, and it seems to work as expected. In the first post, you mention that you had a pullup connected to 5V- this (or to VBATT) could have damaged the microcontroller, it's powered by an onboard 3.3V regulator. Can you try on another pin that has not been connected to 5V through a resistor?

Title: Re: Push Button Issue
Post by: Grimstone on August 03, 2017, 08:00:18 PM
Thanks Ben for the response. I have kind of lost hope here. I have kind of identified the problem, but not sure what to do here. The pin is okay. The trigger is okay. The code is okay. The issue is, I have a Neopixel ring also connected to the Tinyduino. Both connect to ground. On the Mega, no issue. There are multiple ground pins on the Mega and when I wired it up, it was easier to wire them each to their own ground and thus I never saw the issue. With the TS+, they were wired together at the only ground pin and this is apparently making the pin input not read a shift in state. I have no clue how to fix this for the TS+. I am great with coding, but my electronics kungfu still needs improvement.

I truly want to get the TS+ working for this project. Size of electronics is a big big deal as I am very limited on space. A Mega hogs all available free space and even an Uno is very big for what I am doing. I have made an Iron Man gauntlet complete with 2 Watt laser. I wanted the TS+ to control the lighting and sound. Help is greatly appreciated on how to get this push button and Neopixel both working happily.