Tx/Rx as digitals on Mini

I'm pretty sure the answer is yes, but can I use Tx/Rx as digital0 and digital1? Do I just references them as pins 0 and 1 in code, or do they have a special label?

I'm looking to drive 2 7 segment displays using a pair of decimal->binary encoded switches.

Each segment is 4 LEDs, 2.5V @ 20ma each in series-parallel. To display an 8 would be 280ma, at 40mA per segment (pin). I know this is on the upper bound of the arduino :confused: To display 88 would be twice that, 560mA @ 40mA per pin. I guess this pretty much means I'm going to need a pair of ULN2802's?

segment0 pin0
segment1 pin1
segment2 pin2
segment3 pin3
segment4 pin4
segment5 pin5
segment6 pin6
segment7 pin7
segment8 pin8
segment9 pin9
segment10 pin10
segment11 pin11
segment12 pin12
segment13 pin13

SW1,1 pinA0
SW1,2 pinA1
SW1,4 pinA2
SW1,8 pinA3
SW2,1 pinA4
SW2,2 pinA5
SW2,4 pinA6
SW2,8 pinA7

pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);

pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);

pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);

pinMode(A4, INPUT);
pinMode(A5, INPUT);
pinMode(A6, INPUT);
pinMode(A7, INPUT);

digitalWrite(A0, HIGH);
digitalWrite(A1, HIGH);
digitalWrite(A2, HIGH);
digitalWrite(A3, HIGH);

digitalWrite(A4, HIGH);
digitalWrite(A5, HIGH);
digitalWrite(A6, HIGH);
digitalWrite(A7, HIGH);

int digitOne;
int digitTwo;

void setup(){



}

void loop(){

digitOne = 0;
digitTwo = 0;

	if (!A0){
	
		digitOne = digitOne + 1;
		
	}
	if (!A1){
	
		digitOne = digitOne + 2;
		
	}
	if (!A2){
	
		digitOne = digitOne + 4;
		
	}
	if (!A3){
	
		digitOne = digitOne + 8;
		
	}
	
	
	if (!A4){
	
		digitTwo = digitTwo + 1;
		
	}
	if (!A5){
	
		digitTwo = digitTwo + 2;
		
	}
	if (!A6){
	
		digitTwo = digitTwo + 4;
		
	}
	if (!A7){
	
		digitTwo = digitTwo + 8;
		
	}
	
	switch (digitOne){
	
		case 1:
			
			digitalWrite(0, LOW);
			digitalWrite(1, HIGH);
			digitalWrite(2, HIGH);
			digitalWrite(3, LOW);
			digitalWrite(4, LOW);
			digitalWrite(5, LOW);
			digitalWrite(6, LOW);
			
		case 2:
			
			digitalWrite(0, HIGH);
			digitalWrite(1, HIGH);
			digitalWrite(2, LOW);
			digitalWrite(3, HIGH);
			digitalWrite(4, HIGH);
			digitalWrite(5, LOW);
			digitalWrite(6, HIGH);
			
		case 3:
			
			digitalWrite(0, HIGH);
			digitalWrite(1, LOW);
			digitalWrite(2, LOW);
			digitalWrite(3, HIGH);
			digitalWrite(4, LOW);
			digitalWrite(5, LOW);
			digitalWrite(6, HIGH);
			
		case 4:
			
			digitalWrite(0, LOW);
			digitalWrite(1, HIGH);
			digitalWrite(2, HIGH);
			digitalWrite(3, LOW);
			digitalWrite(4, LOW);
			digitalWrite(5, HIGH);
			digitalWrite(6, HIGH);
			
		case 5:
			
			digitalWrite(0, HIGH);
			digitalWrite(1, LOW);
			digitalWrite(2, HIGH);
			digitalWrite(3, HIGH);
			digitalWrite(4, LOW);
			digitalWrite(5, HIGH);
			digitalWrite(6, HIGH);
			
		case 6:
			
			digitalWrite(0, HIGH);
			digitalWrite(1, LOW);
			digitalWrite(2, HIGH);
			digitalWrite(3, HIGH);
			digitalWrite(4, HIGH);
			digitalWrite(5, HIGH);
			digitalWrite(6, HIGH);
			
		case 7:
			
			digitalWrite(0, HIGH);
			digitalWrite(1, HIGH);
			digitalWrite(2, HIGH);
			digitalWrite(3, LOW);
			digitalWrite(4, LOW);
			digitalWrite(5, LOW);
			digitalWrite(6, LOW);
			
		case 8:
			
			digitalWrite(0, HIGH);
			digitalWrite(1, HIGH);
			digitalWrite(2, HIGH);
			digitalWrite(3, HIGH);
			digitalWrite(4, HIGH);
			digitalWrite(5, HIGH);
			digitalWrite(6, HIGH);
			
		default:
			
			digitalWrite(0, LOW);
			digitalWrite(1, LOW);
			digitalWrite(2, LOW);
			digitalWrite(3, LOW);
			digitalWrite(4, LOW);
			digitalWrite(5, LOW);
			digitalWrite(6, LOW);
			
	}
	
	switch (digitTwo){
	
		case 1:
			
			digitalWrite(7, LOW);
			digitalWrite(8, HIGH);
			digitalWrite(9, HIGH);
			digitalWrite(10, LOW);
			digitalWrite(11, LOW);
			digitalWrite(12, LOW);
			digitalWrite(13, LOW);
			
		case 2:
			
			digitalWrite(7, HIGH);
			digitalWrite(8, HIGH);
			digitalWrite(9, LOW);
			digitalWrite(10, HIGH);
			digitalWrite(11, HIGH);
			digitalWrite(12, LOW);
			digitalWrite(13, HIGH);
			
		case 3:
			
			digitalWrite(7, HIGH);
			digitalWrite(8, LOW);
			digitalWrite(9, LOW);
			digitalWrite(10, HIGH);
			digitalWrite(11, LOW);
			digitalWrite(12, LOW);
			digitalWrite(13, HIGH);
			
		case 4:
			
			digitalWrite(7, LOW);
			digitalWrite(8, HIGH);
			digitalWrite(9, HIGH);
			digitalWrite(10, LOW);
			digitalWrite(11, LOW);
			digitalWrite(12, HIGH);
			digitalWrite(13, HIGH);
			
		case 5:
			
			digitalWrite(7, HIGH);
			digitalWrite(8, LOW);
			digitalWrite(9, HIGH);
			digitalWrite(10, HIGH);
			digitalWrite(11, LOW);
			digitalWrite(12, HIGH);
			digitalWrite(13, HIGH);
			
		case 6:
			
			digitalWrite(7, HIGH);
			digitalWrite(8, LOW);
			digitalWrite(9, HIGH);
			digitalWrite(10, HIGH);
			digitalWrite(11, HIGH);
			digitalWrite(12, HIGH);
			digitalWrite(13, HIGH);
			
		case 7:
			
			digitalWrite(7, HIGH);
			digitalWrite(8, HIGH);
			digitalWrite(9, HIGH);
			digitalWrite(10, LOW);
			digitalWrite(11, LOW);
			digitalWrite(12, LOW);
			digitalWrite(13, LOW);
			
		case 8:
			
			digitalWrite(7, HIGH);
			digitalWrite(8, HIGH);
			digitalWrite(9, HIGH);
			digitalWrite(10, HIGH);
			digitalWrite(11, HIGH);
			digitalWrite(12, HIGH);
			digitalWrite(13, HIGH);
			
		default:
			
			digitalWrite(7, LOW);
			digitalWrite(8, LOW);
			digitalWrite(9, LOW);
			digitalWrite(10, LOW);
			digitalWrite(11, LOW);
			digitalWrite(12, LOW);
			digitalWrite(13, LOW);
			
	}
	
}

I recently had a similar need for more I/O pins :wink:

You can do it, but you must disable the UART the 'hard way'. It is activated by default and overrides the pin-direction (input/output) internally in hardware. Once you've disabled it you cannot use any hardware serial communication anymore (in that program).

Insert this at the very beginning of setup()

UCSR0A = 0x00;
UCSR0B = 0x00;
UCSR0C = 0x03;

This sets the uart control & status registers to their default values and turns the uart + port override off.

Yes they are just IO pins, but there is an important problem - the bootloader uses them at reset to check for a new program download. This limits what hardware you can connect to RX and TX in practice and people avoid using these pins (some boards have them directly connected to the USB/serial chip, BTW, more recent boards have resistors in-line I think.

I suspect these problems can be overcome but you need to be aware of the issues.

This is a mini, so no onboard USB crap. Once I have it programmed, it won't be getting programmed for a good while. It won't be using serial in application, thus why not use them (in my case, there's an exact number of pins)

Well it works just fine on a 'bare' ATmega168 programmed with the Arduino IDE. And a mini is pretty close to that.

madworm:
I recently had a similar need for more I/O pins :wink:

You can do it, but you must disable the UART the 'hard way'. It is activated by default and overrides the pin-direction (input/output) internally in hardware. Once you've disabled it you cannot use any hardware serial communication anymore (in that program).

Insert this at the very beginning of setup()

UCSR0A = 0x00;

UCSR0B = 0x00;
UCSR0C = 0x03;




This sets the uart control & status registers to their default values and turns the uart + port override off.

So if I ever need to re-program, the hardware will still check for packets on the serial line during boot-up, but after that they're D0 and D1?

These are the hardware default values of the registers. Every ATmega168/328 chip has these after reset.

Then later some piece of code changes them to its needs - like the bootloader and later 'user code'.

If it didn't work I wouldn't post it.

electronics question-

Each segment is going to be 5V at 40ma, through a 2802 darlington array. Do I still need to put current limiting resistors in? If so, where? Before 2802 or between 2802 and segment?

The 2802 is rated for 25ma base current..so I'd need a current limiting resistor between arduino and array?

Everything is 5V so no level shifting needed. Just switching.

I doubt you'll want the ULN2802A it's rated for 14-15V operation on the inputs. 5V logic would need a 2803A.

You need a current limiting resistor for each segment/output of the array and it is irrelevant if it comes before or after the LED. And the 2803A has a base resistor already integrated - suitable for 5V input. The datasheet gives a number of about 1.3mA input current for that case.

madworm:
I doubt you'll want the ULN2802A it's rated for 14-15V operation on the inputs. 5V logic would need a 2803A.

You need a current limiting resistor for each segment/output of the array and it is irrelevant if it comes before or after the LED. And the 2803A has a base resistor already integrated - suitable for 5V input. The datasheet gives a number of about 1.3mA input current for that case.

http://www.datasheetcatalog.com/datasheets_pdf/U/L/N/2/ULN2802.shtml

Mouser's datasheet says the 03 is 2.5Vin, the 04 is 5.0Vin?

Well, I'm looking at page 2/8 of the one I posted.

madworm:
Well, I'm looking at page 2/8 of the one I posted.

The table on 3/8 contradicts

Hmmm.

The way I interpret the table is this:

ULN2803A: "If you want it to supply up to 250mA, supply 2.7V to the input" or "If you want it to supply up to 300mA, supply 3V"

If you took the 2804 and supplied 5V, you'd only get 125mA, and the abs. maximum for all types is 500mA. Not reachable with a 5V system on the 2804.

Now I'm confused......

I'm only pulling 40ma from each pin. 280ma for the whole package to display an 8.

That data was taken with the collector wired to Vcc and the emitter to GND + amp-meter in there.

Anyhow, it needs 5V to turn on fully. If you only need 40mA per channel that is of less a concern.

Maybe this datasheet is a bit clearer on how the values were obtained:

madworm:
I recently had a similar need for more I/O pins :wink:

You can do it, but you must disable the UART the 'hard way'. It is activated by default and overrides the pin-direction (input/output) internally in hardware. Once you've disabled it you cannot use any hardware serial communication anymore (in that program).

Insert this at the very beginning of setup()

UCSR0A = 0x00;

UCSR0B = 0x00;
UCSR0C = 0x03;




This sets the uart control & status registers to their default values and turns the uart + port override off.

At the end of the arduino init() function it does this.

madworm:
That data was taken with the collector wired to Vcc and the emitter to GND + amp-meter in there.

Anyhow, it needs 5V to turn on fully. If you only need 40mA per channel that is of less a concern.

Maybe this datasheet is a bit clearer on how the values were obtained:

http://www.datasheetcatalog.org/datasheet/allegromicrosystems/2801.pdf

got it now