You should import the GPIO library as import RPi.GPIO as GPIO than reference it by using GPIO.
Also packages for python 3.x require you to use pip3 install rather than sudo apt-get install python3-rpi.gpio as it doesn't require elevated privileges and has access to the python package index (pypi.org)
When you have a recursive function like this (one with too much depth potential), you need to convert it into a loop. In this case you have two functions alternating calling each other:
This will loop forever (as does the original version, you are exiting on a signal), but you can also use some kind of state as a ...
That's one way of doing it - it will work. The better way is to use GPIO.wait_for_edge(17, GPIO.RISING) which will pause at that line until the button is pressed (on a RISING or FALLING edge).
However, BOARD numbering pin 17 is not a GPIO, it's 3V3.
You could also use GPIO Zero which is more intuitive (and uses BCM numbering):
from gpiozero import Button
The preliminary Pi4 datasheet shows there are 6 UARTs.
Given that UART 0/1 are both connected to the same GPIO you can only use one of them at any one time. So potentially there are 5 accessible UARTs at any one time.
You can enable each of the UARTs on the Pi4B by making appropriate ...
Yes, it is possible to control the built-in leds. Green LED is easier.
According to here, though it is probably Pi 3 specific, since it didn't work for my Pi 4:
In the terminal:
sudo echo 1 > sudo /sys/class/leds/led0/brightness
This turns the green led on.
sudo echo 0 > sudo /sys/class/leds/led0/brightness
To turn off the activity indicator ...
As far as I am aware it should work provided you download and install the latest version of wiringPi.
sudo dpkg -i wiringpi-latest.deb
It's possible that this might mirror something I was doing a couple of years ago and I preface this with the observation that I don't believe that it was good practice, but I didn't find a way around it, so I welcome any correction.
The issue (in my case) was that running a python program that accessed the GPIO pins required root access. If you are going to ...
The FIRST thing you MUST do in interconnecting 2 devices is ensure they have a common reference (incorrectly called Gnd - as the Pi will float wrt Ground).
It is also recommended to join Gnd FIRST - before making any other connection.
It is acceptable to directly connect 2 GPIO, but it is prudent to use a series resistor (~1kΩ) to protect the GPIO in the ...
Yes. There are several ways this can be done. The method used will depend upon the characteristics of the load connected to the relay's contacts.
As @OyaMist has stated, "the actual relay state may differ from its nominal state". From a distance, when the relay state must be known, we are reduced to making a simple assumption; i.e. "...
After hours of hitting my head against the wall I tried to connect it directly without passing through the level shifter and it worked... I don't understand exactly why it is, I suppose it's because of the pulldown resistors or something like that but can tell exactly.
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 ...
It is safest to introduce a resistor.
Connect any Pi ground pin to any of the other Pi's ground pins.
Connect any Pi GPIO pin to any of the other Pi's GPIO pins via a resistor (if you have one, anything between 300 ohms to 100 thousand ohms will do).
Set the transmitting GPIO as an output and the receiving GPIO as an input.
The resistor is ...
Arguably, the best way is to use the package manager still (downloading the packages manually), because the installation process will keep track of the dependencies for you.
First, you will need to download the package. You can do it either using the browser from http://archive.raspbian.org/raspbian/pool/, or by adding the content of Raspbian's sources.list ...
The GPIO is still working, it's the software refusing to continue without a warning unless you correct the condition causing the warning.
Either do what the warning message says or add the following line at the (logical) end of your script.
though it is probably Pi 3 specific, since it didn't work for my Pi 4
It works on the 4 as well, you just need to set the right trigger. The instructions that you provided are not applicable to the 4 or just incorrect.
This will tell you what triggers you have available:
To enable manual control on a 4, do:
echo gpio |...
On the first RPi :
In a first terminal : (create FIFO)
In a second terminal : (Write datas into FIFO)
readfifo-writeUART.py : pyserial short-intro
with serial.Serial() as ser:
ser.baudrate = 19200
Yes, as long as the signal is 3V3 compatible.
You could use the Pi's UART RX pin (pin 10, GPIO 15) and the standard Linux serial software. That will handle standard baud rates (say up to 1 Mbps).
Alternatively you can use a general GPIO (any other GPIO on the extension header) and software serial. That should be good up to 19k2 bps or so.
It is inadvisable to mix libraries.
You can control a servo with
See https://gpiozero.readthedocs.io/en/stable/api_output.html#servo for documentation of the servo class.
NOTE that gpiozero, by default uses RPi.GPIO
GPIO Zero builds on a number of underlying pin libraries, including RPi....
The module you have includes a resistive sensor and a comparator which produces a 1-bit value (0 or 1). There's nothing you can do to get a more detailed signal from that module.
There are two main approaches which allow to read analog values from resistive sensors with devices which don't have analog pins, such as raspberries.
simulate this ...
How can Rpi python read a SPI MFRC255 RFID/NFC tag?
Part 1 - Introduction to I2C and SPI NFC/RFID Chips and Modules
Part 2 - Setting up SPI MFRC522 Module
Part 3 - Troubleshooting SPI Software and Hardware using Loopback
Part 4 - Using Rpi4B buster Python 3 and Mfrc522 library to read NFC Tag
I have successfully installed ...
I doubt you will reliably be able to read NEC IR signals with RPi.GPIO.
The combination of Linux scheduling and GPIO interrupt handling and Python will likely conspire to miss transitions.
I suppose that is something you will have to find out for yourself by trying.
My pigpio Python module will capture the data.
See the following examples.
The code you have should be fine.
I'd expect the resulting sleep to be within 1% of n the majority of the time (getting more accurate for larger values of n).
If you are seeing 2 times n it suggests something like:
your system is exceptionally busy
or the circuit you are driving has a large amount of capacitance to overcome
or some other program is ...
As Joan has stated only 1 of UART0/1 is accessible (UART0 /dev/ttyAMA0 is connected to Bluetooth on later model Pi).
There are additional UART on the Pi4.
I haven't actually tried these.
I doubt UART2 would be usable as GPIO0/1 are used for HATs (and shown as reserved).
I suspect that the SDA0/SCL0 connected to these pins are used for other internal ...
Most EEPROM chips use either SPI or I2C to transfer data, check the docs for the chip you choose to find out which and connect to the appropriate bus on the Pi. From there it's a matter of sending the right commands on the right bus -- again the chip docs will help with this.
There is, no doubt, many Python libraries to help with the commands (e.g. https://...
Unfortunately the Pi has no GPIO programmable built-in LED.
Edit: This is incorrect. As pointed out in an answer below, the on-board can be controlled using echo none > /sys/class/leds/led0/trigger to enable, echo 1 >/sys/class/leds/led0/brightness to turn the LED on, and echo 0 >/sys/class/leds/led0/brightness to turn the LED off.
The rest of my ...