Arduino Uno PortD0 (RX) Problem

I'm building a simple 7 segment-LED circuit using Arduino Uno. The task is to use digital output port (from PORTD0 TO PORTD6 only) to light up that 7 segment-LED at a specific number. My code is not complete, however, the key feature is there. By default, the LED suppose to display number 5, however, the cathode A of the LED does not on and it is connected to PORTD0. If I connect it to PORTD7, it works fine. Can anyone help me with this?

The code:

int G = 6;
int F = 5; 
int E = 4;
int D = 3;
int C = 2;
int B = 1;
int A = 7;
int Button1 = 8;
int Button2 = 9;

void setup()
{
  pinMode(E, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(A, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(Button1, INPUT);
  pinMode(Button2, INPUT);
}

void loop()
{	if (digitalRead(Button1) == LOW && digitalRead(Button2) == LOW) {
  		digitalWrite(E, HIGH);
 	 	digitalWrite(D, LOW);
  		digitalWrite(C, LOW);
  		digitalWrite(B, HIGH);
  		digitalWrite(A, LOW);
  		digitalWrite(F, LOW);
  		digitalWrite(G, LOW);	// No button is pressed. Display number 5
	}
 	else if (digitalRead(Button1) == HIGH && digitalRead(Button2) == HIGH) {	
      	digitalWrite(E, LOW);
 	 	digitalWrite(D, LOW);
  		digitalWrite(C, HIGH);
  		digitalWrite(B, LOW);
  		digitalWrite(A, LOW);
  		digitalWrite(F, HIGH);
  		digitalWrite(G, LOW);	// Button1 is pressed. Display number 2
    	delay(1000);	// Delay for 1000ms
    }
     else {		// Button2 is pressed. Display number 3
      	digitalWrite(E, HIGH);
 	 	digitalWrite(D, LOW);
  		digitalWrite(C, LOW);
  		digitalWrite(B, LOW);
  		digitalWrite(A, LOW);
  		digitalWrite(F, HIGH);
  		digitalWrite(G, LOW);
        delay(1000);	// Delay for 1000ms
     }
}

The circuit setup:

Hello jdimmy
Post your current sketch, well formated, with comments and in so called code tags "</>" and a schematic, not a Fritzy diagram, to see how we can help.
Have a nice day and enjoy coding in C++.

Please edit your post, select all code and apply code tags using the </> button; next save your post.

I'm not sure if it will help, but you can try a Serial.end() in setup().

Why do you connect the common pin (3,8) to both Vcc and GND via resistors. Further each segment LED should have its own resistor if you want to control multiple segments.

I wouldn't use pin 0 (RX) or pin 1 (TX) because they are used for serial communication when uploading your sketch or when using the serial monitor or plotter.

I really don't know about pin 0 and 1, but my teacher ask me to use those pin.

Sorry about those pins and resistors, at first I didn't know how to connect those. I will change them later. The main problem is still the coding. I did what you mentioned but nothing change. So am I doing it wrong or something else? I just add one line of Serial.end() in setup() below those pinMode lines.

Then patiently explain to your teacher that pin 0 is being held low by the CH340/FT232 USB<>UART chip on the Arduino Nano and as a result, pin 0 is difficult to make good use of without altering the hardware of the Arduino.
Edit: same story on the UNO, btw. The 1k series resistor on TX and RX does help, but there's just no good reason to use those pins for other purposes. If only because it limits debugging possibilities.

Hello jdimmy
Take a search engine of your choice and ask the WWW for
"7 segment +tutorial".
Have a nice day and enjoy coding in C++.

p.s.
Take a view here. The port pin 0 and port pin 1 are used internally by the Arduino hardware.

Note that using a single resistor for several parallel LEDs causes them to share the current. The LED's will get dimmer as the current has to be shared by more ON segments. The proper way to control a Common Anode digit is to connect the anode directly to +5V and provide a current limiting resistor for each segment. For Common Cathode, connect the cathode to Ground andprovide a current limiting resistor for each segment.

1 Like

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