How to open and close PNP transistor with IO pin?
Unlike field effect transistors bipolar transistors are not controlled by a gate voltage but by a base current.

The voltage between the base and the emitter is nearly constant as long as the transistor is conducting. This means that the voltage between the base of the transistor and ground (this is the voltage drop over the "pull down" resistor) is nearly constant.

When you operate the switch in the schematic you posted the voltage drop over the "pull down" resistor will be higher than this constant voltage. This means that the voltage between the emitter and the base of the transistor (which is the voltage over the resistor R2) will be too low so no more current can flow out of the transistor's base.

Once again: When working with bipolar transistors you have to think about currents (and to forget about voltages):

You have to design the circuit in a way that current or no current flows out of the transistor's base depending on the microcontroller's software.

If you operate your microcontroller with 5 V you might try to connect the 20 kOhms resistors to the I/O pin instead of ground. Don't place any "pull down" resistor!

If the I/O pin is "low" there is a voltage difference between the transistor's base and the I/O pin. A current will flow through the resistor; this current also flows out of the base of the transistor. The transistor will be conducting.

If the I/O pin is "high" there is no voltage difference over the resistor. No current flows and the transistor will not conduct.

If you operate the microcontroller with 3.3 V things will get more complicated. The easiest way would be to modify the circuit in the schematic you posted in this case:

Put a "small" NPN transistor between the resistor and ground and operate the NPN transistor using the I/O pin:

When the NPN transistor conducts a current can flow out of the PNP transistor's base and the PNP transistor will also conduct.

When the NPN transistor does not conduct no current will flow out of the PNP transistor's base and the PNP transistor will also not conduct.


  It started working when I instead used two 10kOhm resistors, putting one to ground, one to base of resistor and digital output between them. I'm now mostly curious if what I did is theoretically correct.


The 10 kOhms resistor between the I/O pin and ground should have no effect in this case.

However the effects you describe sound very strange with this configuration.

Could you measure the voltage at the I/O pin (to ensure it really switches to high/low) as well as the voltage drop over the 10 kOhms resistor between the transistor and the I/O pin?

By the way:

Some microcontrollers use an open-drain output with a pull-up resistor. In this case the microcontroller can output 0 V very easiely but there will be a voltage drop inside the microcontroller when the output is "high". In this case you have no chance to get a "high" voltage on the I/O pin when the 10 kOhms resistor between the I/O pin and ground is fitted.

According to the data sheet ATtiny 13 does not work like this but you can never know...