Difference between revisions of "Template:Power Management HAT (B) rpi"

From Waveshare Wiki
Jump to: navigation, search
m (Text replacement - "https://www.waveshare.com/w/upload/" to "https://files.waveshare.com/upload/")
 
Line 55: Line 55:
 
*Download the script and run it.
 
*Download the script and run it.
 
<pre>
 
<pre>
wget https://www.waveshare.com/w/upload/4/44/Power-Management-HAT.zip
+
wget https://files.waveshare.com/upload/4/44/Power-Management-HAT.zip
 
unzip Power-Management-HAT.zip
 
unzip Power-Management-HAT.zip
 
cd Power-Management-HAT
 
cd Power-Management-HAT
Line 70: Line 70:
 
<pre>
 
<pre>
 
cd ~
 
cd ~
wget https://www.waveshare.com/w/upload/2/27/Power-example.7z
+
wget https://files.waveshare.com/upload/2/27/Power-example.7z
 
7z x ./Power-example.7z
 
7z x ./Power-example.7z
 
</pre>
 
</pre>

Latest revision as of 06:30, 2 September 2023

Working With Raspberry Pi

Configure Pico Compile Environment

  1. Download the installation script.
    cd ~
    wget https://raw.githubusercontent.com/raspberrypi/pico-setup/master/pico_setup.sh
    
  2. Give run permission and run:
    chmod +x pico_setup.sh
    ./pico_setup.sh
    
  3. Restart the Raspberry Pi:
    sudo reboot
    

Openocd

  • Power Management HAT (B) has connected SWD (debug) to the Raspberry Pi interface, you can directly use the debug interface to download programs or debug.
  1. Download the library source code required for OpenOCD.
    cd ~/pico
    sudo apt install automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-
    dev
    
  2. Download the OpenOCD source code.
    git clone https://github.com/raspberrypi/openocd.git --recursive --branch rp2040 --depth=1
    
  3. Compile and install:
    cd openocd
    ./bootstrap
    ./configure --enable-ftdi --enable-sysfsgpio --enable-bcm2835gpio
    make -j3
    sudo make install
    

Soft Shutdown Script

  • Power Management HAT (B) requires a script to enable soft shutdown and run detection of the Raspberry Pi.
  • Download the script and run it.
wget https://files.waveshare.com/upload/4/44/Power-Management-HAT.zip
unzip Power-Management-HAT.zip
cd Power-Management-HAT
sudo chmod a+x Power-Management-HAT-Setup.sh
sudo ./Power-Management-HAT-Setup.sh
  • The result is shown below, when prompted "Would you like to reboot now? y/n", enter "y" to reboot the Raspberry Pi.
  • You must reboot the Raspberry Pi for this operation to be effective, if the Raspberry Pi is not rebooted, you must manually reboot the Raspberry Pi to take effect.
Soft Shutdown Script01.png

Note: You should check whether there is an error reported after the execution of the above operation, there is an error reported according to the prompts to correct before continuing.

Demo Usage

Get the Demo

cd ~
wget https://files.waveshare.com/upload/2/27/Power-example.7z
7z x ./Power-example.7z

Compile the Demo

  • The default demo is for periodic power-on.
cd ~/Power-example/build/
export PICO_SDK_PATH=/home/pi/pico/pico-sdk
cmake ..
make -j

Program the Demo

  • Note: Program the demo will cause the RP2040 to reset and the power supply to be interrupted.
  • Therefore, you should use the Raspberry Pi's power port for power supply instead of the Power Management HAT(B) when programming.

Program via SWD Interface

  • We already connect the SWD interface of the RP2040 to the Raspberry Pi, and you can directly operate it through Openocd.
openocd -f interface/raspberrypi-swd.cfg -f target/rp2040.cfg -c "program ./Power_Management_HAT.elf verify reset exit"

Program via USB

  • The Raspberry Pi Foundation has cured the UF2 bootloader within the RP2040 by following a few steps:
  1. Connect the USB connector of the Raspberry Pi and the USB connector of the board.
  2. Press the Reset key and the BOOT key.
  3. Release the Reset key first and then the BOOT key.
  4. Drag and drop the corresponding files into the pop-up mass storage.
  • You can refer to the following diagram (the diagram is the official Raspberry Pi GIF for the Hello World demo).

Power Management B09.gif

UART Listening

Enable UART Function

  • Execute the following commands to configure the Raspberry Pi.
sudo raspi-config
  • Enable the UART function:
1. Choose Interfacing Options and Enter:
UART Listening01.png
2. Select Serial Port:
UART Listening02.png
3. Select close the serial port debug function.
UART Listening03.png
4. Choose to enable the serial port hardware.
UART Listening04.png
5. System prompts as follows:
UART Listening05.png

Minicom

  • Minicom is a common command-line serial debugging tool for Linux.
  • Its function is similar to that of HyperTerminal under Windows, and it can control external hardware devices via a serial port, which is usually used for managing embedded devices.
1. Install and run minicom:
sudo apt-get install minicom -y
sudo minicom -D /dev/ttyS0
2. Now you can see the running information returned by the demo timer (here the demo is a timer switch demo).

Power Management HAT (B)11.jpg

Demo Description

  • To switch between demos, you need to turn on the corresponding initialization and loop functions in the main function, and block the functions of the remaining demos.
  • In the following figure, Period_Time demo is enabled.

Power Management HAT (B)06.jpg

Common Rules/Functions

Status Indicator

  • The status indicators all follow the rules below:
  1. In the shutdown state or power off state, the status indicator flashes at a frequency of about 0.83HZ (slow flashing).
  2. Boot-up state or power-on state, the status indicator about 2.5HZ frequency flashing (fast flashing).
  3. Waiting for the power on or waiting for the power off, the status indicator is always on.

Judging by Current

  • Judging by Current
  1. This function can judge the device on and off in real time and turn off the power to save energy.
  2. This feature is disabled by default (can be turned on via ". /examples/examples.h/USE_CURRENT_TO_CHECK_PI_STATUS").
  3. By determining whether the current value is less than the shutdown current if it is, the device is considered to be shut down, and the power is turned off (shutdown current setting . /examples/examples.h/Shutdown_Current_Ma, you need to adjust it according to your own device, otherwise the function will not work or the device will not be powered on).

Power on and off

  • Power on
  1. Power on via RTC or the key.
  2. Turn on the power, and determine whether the power has been turned on through GPIO, the default maximum wait time for power on is 90 seconds, more than the maximum value is considered to have been turned on (the maximum wait time is set by lib/Power_Management_Lib/Power_Management_Lib.c/Power_Wait_Time_S).
  • Soft shutdown
  1. Soft shutdown triggered by key press.
  2. The default maximum wait time for power off is 60 seconds, if the maximum wait value is exceeded, the power will be forced to shut down (the maximum wait time is set by lib/Power_Management_Lib/Power_Management_Lib.c/Wait_Boot_). Time_S).
  • Forced shutdown process
  1. Shutdown triggered by RTC, long key press, and current.
  2. Forced power off and device shutdown.

Button_Ctr Demo

  • Implement function: Use the PWR button to power on/off.
  1. When the Raspberry Pi is turned off.
    • When the PWR button is pressed, it turns on.
  2. When the Raspberry Pi is powered on.
    • Default long press PWR button more than 2S but less than 8S, try to soft shut down the Raspberry Pi.
    • Default long press PWR button more than 8S then try to power off directly.

Period_Time Demo

  • Timed power on/off:
  1. Power on when the time reaches the specified time Power_On_Time (default is 9:00:30).
  2. Shut down when the time reaches the specified time Power_Off_Time (default is 10:00:00).

Cycle_Time Demo

  • Cycle power on/off
  1. Power_On_Keep_Time (default is 1800S).
  2. Power_Off_Keep_Time (default is 3600S).