Difference between revisions of "Template:Power Management HAT (B) rpi"
From Waveshare Wiki
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:// | + | 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:// | + | 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
- Download the installation script.
cd ~ wget https://raw.githubusercontent.com/raspberrypi/pico-setup/master/pico_setup.sh
- Give run permission and run:
chmod +x pico_setup.sh ./pico_setup.sh
- 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.
- 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
- Download the OpenOCD source code.
git clone https://github.com/raspberrypi/openocd.git --recursive --branch rp2040 --depth=1
- 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.
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:
- Connect the USB connector of the Raspberry Pi and the USB connector of the board.
- Press the Reset key and the BOOT key.
- Release the Reset key first and then the BOOT key.
- 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).
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:
- 2. Select Serial Port:
- 3. Select close the serial port debug function.
- 4. Choose to enable the serial port hardware.
- 5. System prompts as follows:
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).
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.
Common Rules/Functions
Status Indicator
- The status indicators all follow the rules below:
- In the shutdown state or power off state, the status indicator flashes at a frequency of about 0.83HZ (slow flashing).
- Boot-up state or power-on state, the status indicator about 2.5HZ frequency flashing (fast flashing).
- Waiting for the power on or waiting for the power off, the status indicator is always on.
Judging by Current
- Judging by Current
- This function can judge the device on and off in real time and turn off the power to save energy.
- This feature is disabled by default (can be turned on via ". /examples/examples.h/USE_CURRENT_TO_CHECK_PI_STATUS").
- 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
- Power on via RTC or the key.
- 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
- Soft shutdown triggered by key press.
- 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
- Shutdown triggered by RTC, long key press, and current.
- Forced power off and device shutdown.
Button_Ctr Demo
- Implement function: Use the PWR button to power on/off.
- When the Raspberry Pi is turned off.
- When the PWR button is pressed, it turns on.
- 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:
- Power on when the time reaches the specified time Power_On_Time (default is 9:00:30).
- Shut down when the time reaches the specified time Power_Off_Time (default is 10:00:00).
Cycle_Time Demo
- Cycle power on/off
- Power_On_Keep_Time (default is 1800S).
- Power_Off_Keep_Time (default is 3600S).