博文

目前显示的是标签为“GPIO”的博文

Does GPIO 2 on Raspberry Pi 5 work like GPIO 4

图片
 Short answer: electrically they’re mostly the same as GPIOs, but they are not identical in function or “gotchas”. Also, be careful: “GPIO 2” ≠ “pin 2” on the header. 1. If you meant physical pin 2 vs pin 4 On Raspberry Pi 5 : Pin 2 = 5 V power Pin 4 = 5 V power Both are fixed 5 V supply pins , not GPIO at all. You cannot use them like GPIO4.  So: ❌ Pin 2 does not work like GPIO 4 (BCM 4). It’s just a 5 V output from the power supply. 2. If you meant BCM GPIO2 vs BCM GPIO4 On the Raspberry Pi 5 header: GPIO2 = BCM2, physical pin 3 → default I²C1 SDA   GPIO4 = BCM4, physical pin 7 → a “normal” GPIO with extras like GPCLK0 , and often used as the default 1-Wire pin . They are similar in that: Both are 3.3 V GPIOs in the same IO bank on Pi 5. You can configure each as input or output in your code. But they differ in details: Fixed pull-up on GPIO2 GPIO2 (and GPIO3) have a permanent pull-up to 3.3 V because they are the mai...

How do I use GPIO pins?

图片
  Using   GPIO (General-Purpose Input/Output) pins   is fundamental in embedded systems and microcontroller projects. Below is a   step-by-step guide   on how to use them for both   input   and   output   operations, with examples for popular platforms like   Arduino , ESP32, and Raspberry Pi . 1. Understanding GPIO Basics GPIO pins  can be configured as: Digital Input  (read a button or sensor). Digital Output  (control an LED or relay). Analog Input  (read sensors like potentiometers, ADC required). PWM Output  (dim LEDs, control servo motors). Special Functions  (I2C, SPI, UART for communication). 2. Setting Up GPIO Pins A. Arduino (AVR/ARM) Digital Output (Control an LED) cpp void setup ( ) { pinMode ( 13 , OUTPUT ) ; // Set pin 13 as output } void loop ( ) { digitalWrite ( 13 , HIGH ) ; // Turn LED ON delay ( 1000 ) ; digitalWrite ( 13 , LOW ) ; // Turn LED OFF delay ( ...

How to use Python to control the GPIO pins on your Raspberry Pi?

图片
  LED Blinker using GPIO and Python This simple project teaches you how to use Python to control the GPIO pins on your Raspberry Pi —blinking an LED on and off.  What You Need: Raspberry Pi (any model) 1x LED 1x 330Ω resistor Breadboard and jumper wires Python 3 (pre-installed) GPIO library ( RPi.GPIO )  Wiring the Circuit: Connect the long leg of the LED (anode) to GPIO pin 18 (physical pin 12). Connect a 330Ω resistor from the LED's short leg (cathode) to GND (physical pin 6). Use a breadboard for easy wiring.  Python Code: Open the terminal and create the script: bash nano led_blink.py Paste this code: python import RPi.GPIO as GPIO import time LED_PIN = 18 GPIO.setmode(GPIO.BCM) GPIO.setup(LED_PIN, GPIO.OUT) try : while True : GPIO.output(LED_PIN, GPIO.HIGH) print ( "LED ON" ) time.sleep( 1 ) GPIO.output(LED_PIN, GPIO.LOW) print ( "LED OFF" ) time.slee...

The working principle of GPIO in STM32

图片
 The GPIO (General Purpose Input/Output) pins on an STM32 microcontroller are highly flexible and are used to interact with external devices—like LEDs, buttons, sensors , or other ICs. Here's a clear explanation of the working principle of GPIO in STM32: Basic Working Principle of GPIO in STM32 Each GPIO pin can be configured as: Input (read external signal) Output (drive a signal high or low) Alternate function (used by peripherals like USART, SPI, etc.) Analog (e.g., for ADC inputs) GPIO Workflow in STM32 1. Clock Enable (RCC) Before using any GPIO port (A, B, C, ...), you must enable its clock in the RCC (Reset and Clock Control): c RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; // Enable clock for GPIOA 2. Pin Mode Configuration Each pin has a mode set in MODER register: c GPIOA->MODER &= ~( 3 << ( 2 * 5 )); // Clear mode for PA5 GPIOA->MODER |= ( 1 << ( 2 * 5 )); // Set PA5 as output Modes: 00 : Input 01 : Out...