Raspberry Pi (I) Using Python language to flash GPIO pins[Copy link]
I have been learning about Raspberry Pi for a while recently, and I can't wait to turn on a lamp to try out the effect of Raspberry Pi. There are some differences between Raspberry Pi and MCU. 32 MCU can run some operating systems. When I was working on 32 MCU before, I also tried to run a system once, that is, I downloaded a routine program and burned it into the MCU in the fog. It is not interesting to work on MCU all the time, so I applied for a Raspberry Pi development board. Raspberry Pi runs on Linux operating system, so I have to learn Linux operating system. After getting Raspberry Pi, I can't wait to see its effect, so I started the first Raspberry Pi project - using Raspberry Pi Python language to realize GPIO pin flashing. Let me show you the effect I made: Use Python language to realize GPIO pin flashing The above video is a very basic effect diagram I achieved. Suddenly I found that Raspberry Pi is quite fun. I would like to share with you the pin diagram of Raspberry Pi. You can save this pin diagram, which is very useful.
Below I would like to share with you the program code in the LED.py file I talked about in my demonstration video:
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(18,GPIO.OUT) while True: GPIO.output(18,GPIO.HIGH) time.sleep(0.05) GPIO.output(18,GPIO.LOW) time.sleep(0.05)
复制代码
The first line means inserting the GPIO module of the Raspberry Pi The second line means inserting the time control module The third line means setting the GPIO encoding mode to BCM encoding. There are two GPIO encoding methods for Raspberry Pi, one is BOARD encoding, the other is BCM encoding The fourth line means configuring GPIO to output mode The following is an infinite loop of the program, pulling up GPIO18 for a delay of 0.05s and then pulling down GPIO18 for another delay of 0.05s