This code will set the output Low for about 1 microsecond then reconfigure it as an INPUT.
So depending on what is connected this is expected.
If you want the state to persist remove the call to cleanup.
Probably found an answer thanks to @joan 's answer.
It seems like RPi.PWM can only do software PWM, but the fan requires hardware PWM to run as smooth as possible. To do hardware PWM on any GPIO pin, the pigpio daemon has to be executed, and controlled by Python. Therefore, pigpio has to be installed first and configured to be started on boot (systemd). ...
There are two fundamental differences between the two approaches.
The gpio utility (part of wiringPi)
is using hardware timed PWM.
appears to be setting a frequency of 40 kHz.
The RPi.GPIO script
is using software timed PWM.
is setting a frequency of 50 Hz.
I'd guess the frequency is the main factor.
I would look to use the gpiozero module as that’s more powerful but saying that the cleanup function is designed to reset all pins as it’s the last thing you should do in your program NOT part way through.
Also the setting of the pin mode should only be executed once in your program.
Normally, you would ‘reset’ the output by putting a high or low voltage ...
See RPi.GPIO documentation.
At the end any program, it is good practice to clean up any resources
you might have used. This is no different with RPi.GPIO. By returning
all channels you have used back to inputs with no pull up/down, you
can avoid accidental damage to your RPi by shorting out the pins. Note
that this will only clean up GPIO channels ...
No, the GPIO pins can not be used to drive a DC motor.
They can only supply a few milliamps of current at 3V3 which will not be enough. In addition driving any inductive load direct from a GPIO is likely to destroy the GPIO and the Pi. An inductive load is such as a DC motor or a relay coil.
You need a motor driver board or chip or discrete components (e.g. ...
"Reference voltage"... do you mean supply voltage?
The answer to your question is: "Yes - you can probably use RPi's 3.3V & 5V supples to power your level shifter.".
The caveat was added because you didn't specify a particular device, and there are many devices called "level shifters".
Both the 3.3V and 5V regulators on the RPi have some "excess" ...
I expect in reality the final state of the GPIO is pretty random. As you don't do a cleanup GPIO 17 will be left as an output. Its level will remain at whatever it was when the sleep elapses and RPi.GPIO terminates.
The final level may appear stable over successive runs for a variety of reasons. E.g. in a perfect world the sleep will elapse at exactly ...