digitalRead on TX pin always "LOW"

Hello to all,

I am trying to program a simple keyboard which is using shortcuts and macros.
For the controller, I am using Keyestuido Pro micro. Because I am short with pins, I am trying to use also TX pin as digitalRead.

But when I upload the program, it seems as if this pin is always LOW and is triggering the key.

I know, that I cannot use Serial.print command with this and I don't.

#include <Keyboard.h>

// set pin numbers for the five buttons:
const int Yminus = 0;
const int Xminus = 2;

...

void setup() { // initialize the buttons' inputs:
  pinMode(Yminus, INPUT);
  pinMode(Xminus, INPUT);

...

  Keyboard.begin();
}
void loop() {
  // use the pushbuttons to control the keyboard:
  if (digitalRead(Yminus) == LOW) {
    Keyboard.press(arrowDown);
    Keyboard.releaseAll();
    delay(3000);
  }

This program is automatically triggering pin D00 every 3 seconds.

I have checked if the button is not working and this is not the case.
Also I have checked if maybe when I soldered the Pro micro made a shortcut, and this is also not the case.

Can you help me please with this issue?

Thank you in advance.

Welcome, read the guide to the forum at the top of every section and tidy up your code in code tags <|>. Edit with :pencil2: :point_down:

Assume you know the Analog pins can be used as digital pins.

Is the board still connected to your computer's USB port?

This is RX pin looks like TX pin is 1

Agree with @killzone_kid
image

Show all your code. How many pins are you using?

Yes. This is very clear for me.

Ok. This is my mistake. Yes it is on RX pin. I also tried addressing pin 1 and 0. Same result.

My code is:

#include <Keyboard.h>


// set pin numbers for the buttons:
const int Yminus = 0;
const int Xminus = 2;
const int Rapid = 3;
const int Xplus = 4;
const int Zminus = 5;
const int Yplus = 6;
const int Zplus = 7;
const int ZeroX = 8;
const int ZeroZ = 9;
const int ZeroY = 10;
const int RST = 16;
const int SpindleStart = 14;
const int RefPoint = 15;
const int GoTo0 = 18;
const int CycleStop = 19;
const int Hold = 20;
const int CycleStart = 21;
char ctrlKey = KEY_LEFT_CTRL;
char altKey = KEY_LEFT_ALT;
char arrowUp = KEY_UP_ARROW;
char arrowDown = KEY_DOWN_ARROW;
char arrowR = KEY_RIGHT_ARROW;
char arrowL = KEY_LEFT_ARROW;
char zPlus = KEY_PAGE_UP;
char zMinus = KEY_PAGE_DOWN;
char goHome = KEY_HOME;
char goToZero = KEY_DELETE;
char setZeroX = KEY_LEFT_ARROW;
char setZeroY = KEY_LEFT_ARROW;
char setZeroZ = KEY_LEFT_ARROW;
char alarmUnlock = KEY_END;
char cycleStop = KEY_ESC;
char startHold = KEY_TAB;
char stepDown = '-';
int stepCount = 1;
int programStateU = 0;
int buttonStateU;
long buttonMillisU = 0;
int programStateD = 0;
int buttonStateD;
long buttonMillisD = 0;
const long intervalButton = 500;

void setup() { // initialize the buttons' inputs:
  pinMode(Yminus, INPUT);
  pinMode(Xminus, INPUT);
  pinMode(Rapid, INPUT);
  pinMode(Xplus, INPUT);
  pinMode(Zminus, INPUT);
  pinMode(Yplus, INPUT);
  pinMode(Zplus, INPUT);
  pinMode(ZeroX, INPUT);
  pinMode(ZeroZ, INPUT);
  pinMode(ZeroY, INPUT);
  pinMode(RST, INPUT);
  pinMode(SpindleStart, INPUT);
  pinMode(RefPoint, INPUT);
  pinMode(GoTo0, INPUT);
  pinMode(CycleStop, INPUT);
  pinMode(Hold, INPUT);
  pinMode(CycleStart, INPUT);


  Keyboard.begin();
}
void loop() {
  // use the pushbuttons to control the keyboard:
  if (digitalRead(Yminus) == LOW) {
    Keyboard.press(arrowDown);
    Keyboard.releaseAll();
    delay(3000);
  }
  if (digitalRead(Xminus) == LOW) {
    Keyboard.press(arrowL);
    Keyboard.releaseAll();
    delay(250);
  }
  if (digitalRead(Rapid) == LOW && stepCount < 4) {
    Keyboard.press(ctrlKey);
    Keyboard.press('u');
    Keyboard.releaseAll();
    stepCount++;
    delay(250);
  }
  if (digitalRead(Rapid) == LOW && stepCount == 4) {
    Keyboard.press(ctrlKey);
    Keyboard.press('j');
    Keyboard.releaseAll();
    Keyboard.press(ctrlKey);
    Keyboard.press('j');
    Keyboard.releaseAll();
    Keyboard.press(ctrlKey);
    Keyboard.press('j');
    Keyboard.releaseAll();
    stepCount = 1;
    delay(250);
  }
  if (digitalRead(Xplus) == LOW) {
    Keyboard.press(arrowR);
    Keyboard.releaseAll();
    delay(250);
  }
  if (digitalRead(Zminus) == LOW) {
    Keyboard.press(zMinus);
    Keyboard.releaseAll();
    delay(250);
  }
  if (digitalRead(Yplus) == LOW) {
    Keyboard.press(arrowUp);
    Keyboard.releaseAll();
    delay(250);
  }
  if (digitalRead(Zplus) == LOW) {
    Keyboard.press(zPlus);
    Keyboard.releaseAll();
    delay(250);
  }
  if (digitalRead(ZeroX) == LOW) {
    Keyboard.write('x');
    delay(250);
  }
  if (digitalRead(ZeroZ) == LOW) {
    Keyboard.write('z');
    delay(250);
  }
  if (digitalRead(ZeroY) == LOW) {
    Keyboard.write('y');
    delay(250);
  }
  if (digitalRead(RST) == LOW) {
    Keyboard.press(alarmUnlock);
    Keyboard.releaseAll();
    delay(250);
  }
  if (digitalRead(RefPoint) == LOW) {
    Keyboard.press(goHome);
    Keyboard.releaseAll();
    delay(250);
  }
  if (digitalRead(GoTo0) == LOW) {
    Keyboard.press(goToZero);
    Keyboard.releaseAll();
    delay(250);
  }
  if (digitalRead(CycleStop) == LOW) {
    Keyboard.press(cycleStop);
    Keyboard.releaseAll();
    delay(250);
  }
  if (digitalRead(Hold) == LOW) {
    Keyboard.press(startHold);
    Keyboard.releaseAll();
    delay(250);
  }
  unsigned long currentMillisU = millis();
  buttonStateU = digitalRead(CycleStart);
  if (buttonStateU == LOW && programStateU == 0) {
    buttonMillisU = currentMillisU;
    programStateU = 1;
    Keyboard.press('q');
    Keyboard.releaseAll();
    delay(250);
  }
  else if (programStateU == 1 && buttonStateU == HIGH) {
    programStateU = 0;
  }
  if (currentMillisU - buttonMillisU > intervalButton && programStateU == 1) {
    programStateU = 0;
    Keyboard.press(ctrlKey);
    Keyboard.press('r');
    Keyboard.releaseAll();
    delay(500);
  }
  unsigned long currentMillisD = millis();
  buttonStateD = digitalRead(SpindleStart);
  if (buttonStateD == LOW && programStateD == 0) {
    buttonMillisD = currentMillisD;
    programStateD = 1;
    Keyboard.press('a');
    Keyboard.releaseAll();
    delay(250);
  }
  else if (programStateD == 1 && buttonStateD == HIGH) {
    programStateD = 0;
  }
  if (currentMillisD - buttonMillisD > intervalButton && programStateD == 1) {
    programStateD = 0;
    Keyboard.press(ctrlKey);
    Keyboard.press('r');
    Keyboard.releaseAll();
    delay(500);
  }

}

Additionaly I am adding also picture of PCB.

Why are you showing PCB? Is the problem occurring while everything mounted on PCB?

Honestly, I do not know. I programed it on PCB. But after checking with multimeter everything seams OK. The button, capa, diode and resistor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.