You're not actually re-checking GPIO4, you're just re-reading the variable mag1.
One way to fix this would be to add mag1=GPIO.input(4) after your time.sleep(20).
import RPi.GPIO as GPIO
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
I'm going to post this as an answer because I had a lot of trouble researching how to drive an ESC with just a Rasp Pi(using a zero w) and it works now, Hopefully someone having the trouble finding out how will see this:
Joan was completely right with the 1000 low and 2000 ms high pulse width.
I ran the GPIO pins at 50 hz. Here is some light arithmetic ...
The Pi is a great way to process data especially if the desired output is digital (Binary) in the physical form, it is however less able to handle analogue inputs and outputs.
To assist the Pi, HATs/processors can be connected via the SPI or I2C interfaces. When you do this for 20 off outputs you will find that costs increase and you start to leave the ...
I wrote my own (limited) version of Lirc in Python, it can send IR codes and can be controlled via TCP (just like Lirc). I use it with an Android app, to control my amplifier.
You can find the source and instructions on https://github.com/amfasis/lyrc
Apart from the beta Microsoft emulator (https://azure-samples.github.io/raspberry-pi-web-simulator/), which only supports one built in circuit board, the only other emulator i could find is
http://www.rpi-emulator.com/ provides an offline downloadable RPi-3 emulator for windows systems.
Raspberry Pi Emulator lets you emulate Raspberry Pi 3 hardware ...
I had the same problem. Somewhere I read that the BCM numbering schema is buggy concerning the event handling. You have to take the WiringPi Numbering Schema, then it works!
Your temporary solution is polling while the event handling here depends on interrupts.
The connections you have made are fine.
You don't need the resistor in series between GPIO 17 and S. However if the relay still operates it will not do any harm to leave it there.
The relay board itself has the circuitry needed to protect the Pi from the relay load.
The GPIO (General Purpose Input Output) may be set in a variety of modes. Potentially each Pi GPIO may be set into 8 different modes called INPUT, OUPUT, ALT0, ALT1, ALT2, ALT3, ALT4, and ALT5.
All GPIO may be set in INPUT or OUTPUT modes. The other potential modes depend on the GPIO and are summarised on page 102 of BCM2835 ARM Peripherals.
Several of ...
Your should really consider using a micro-controller (e.g. Arduino) instead of a Raspberry. With no other code running than your own, you will get predictable behaviour and timing in every event, which is simply not possible under Linux. Then you will be able to tell if the input signal is really glitch-free or not.
Not easy to answer your question because of wire scheme about the projects is necessary. Share with us and I will try to help again.
According to photography, you have nothing plugged to pin 17 and a yellow wire to the 18th pin. They both are the 9th row starting by the left of the photography. You said it works but it shouldn't. I think you could ...
The 5V pins are already connected (and also to the on-board 5V rail - which, depending on model, is NOT "attached directly to the Pi's power supply").
Using both will make NO difference. (Strictly there will be a minor reduction in resistance, but as this is negligible it would be impossible to measure.)
Note the pins do not push anything! The current ...
You can use the 5V pins on the expansion header to provide power to external circuitry.
Indeed this is their purpose and it is safe (provided the power supply is adequate); an op-amp will require negligible power.
NOTE the 5V pins are NOT "GPIO pins"!
"shorting" ANY pins risks damage.
The most likely explanation is that the GPIO is floating, i.e. randomly changing between low and high. This will be the case until you explicitly set a voltage at the GPIO.
Perhaps print the current level in the loop.
You are shifting the r1 register 16 bits left, this clears the 16th pin. You should instead shift the r1 register 47 bits left to clear pin 47(the ACT LED). As posted above, you cannot access the ACT LED through the GPIO controller, but you can on the RPI Zero/RPI Zero W, so your code should work on those.
The analog audio output is indeed connected to GPIO pins, but not those on the expansion header.
The SoC has 54 general-purpose I/O (GPIO) lines split into two banks, but only a subset of one bank are brought out to the expansion header. Many of the others are used for dedicated purposes e.g sdio interface to the SD card and analog audio.
The analog audio ...
It depends on what you mean.
The on-board PWM peripheral is used to provide audio to the 3.5 mm audio jack.
GPIO 12/13/18/19 can be configured to mirror the PWM output channels, but they are not connected to the audio jack.
I know this is a very old post but it's the first one you find in Google when searching for how to access multiple gpio pins... and the results don't include a new facility that may be the easiest option:
so for other searchers, this new software may be what you're looking for:
sudo apt install usbbootgui
(described in more detail at https://www....
Pin 4 is connected to the 5V power rail. It will always be 5V.
If you want to vary the voltage you will need external circuitry - probably at least a diode, a transistor, and a couple of resistors. You could then use a GPIO to switch the transistor on and off (the transistor would in turn switch 5V on and off to the fan). You could vary the effective fan ...
Installing WiringPi from the official Raspbian repositories (on Stretch or later, I believe) will create an executable file at /usr/bin/gpio.
By default, the owner of the file is root, i.e. 0, and the group is root, i.e. 0.
By default, the permissions on the file is 4755. The interesting part of this is the 4, which is the setuid bit. It enables executables ...
The Pi3B+ has revision a020d3.
gpiotest uses pigpio to do the test and has incorrectly identified the Pi model.
The Pi3B+ is like all the 40-pin expansion header models in having user GPIO of 0-27 (although 0 and 1 are reserved for HAT usage).
You can ignore the reported problems with GPIO 30 and 31 as they are not user GPIO and no attempt should have ...
I fixed it by using configuring the gpios as pullups instead of pulldowns.
The api didn't return an error, but it seams like is not possible to configure the used pins as pulldown.
To avoid short circuit if two buttons are pressed at the same time I also had to set the not used OUTPUT gpio pins to inputs.
This is my working code example:
Practically speaking, you cannot power the RPi by a raw Li-Ion cell: its voltage will be in the range of 3..4.2V while the RPi requires 4.75V..5.25V. You will need to boost the Li-Ion cell voltage to 5V.