element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog USB-C Power Delivery – Getting Voltages out of a Charger using Pi Pico and Python!
  • Blog
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: shabaz
  • Date Created: 1 Jan 2023 1:55 AM Date Created
  • Views 6451 views
  • Likes 15 likes
  • Comments 12 comments
  • power delivery
  • python
  • usb c
  • usb-c
  • pico
  • usb-c pd
  • micropython
  • stusb4500
  • python code
  • pi pico
Related
Recommended

USB-C Power Delivery – Getting Voltages out of a Charger using Pi Pico and Python!

shabaz
shabaz
1 Jan 2023

Introduction

December has been a good month for USB-C Power Delivery projects and experimentation. I hope it continues into the next year.

Here are some new blog posts that were created during December! They could be of interest to anyone curious about USB-C Power Delivery (also known as USB-C PD) and what it’s all about:

 USB Type-C and Power Delivery: Any Interest? 

 100W USB Type-C Power Delivery Source: Getting Started 

 Hot Air Tool Upgrade - Quick TR1300A 

 A Soldering Iron for Christmas 

 USB PD - CC decoding adventures 

This quick blog post describes a simple Pi Pico based tool for getting different voltages out of mobile phone chargers.

image

Using this project, it can be possible to obtain 5V, 9V, 12V, 15V or 20V out of a phone charger, and this could be handy for all sorts of purposes. However, this is not a complete project; it is more for experimenting with USB-C PD. I definitely wouldn’t recommend this project to act as a standalone power supply for instance, please don’t try to misuse this project for that purpose. It’s strictly for experimentation. There’s no current-limiting, and no error-handling. Also, not all USB-C chargers will support the five voltages listed above. For instance, Anker chargers seem to omit 12V capability.

The project supports USB-PD version 2.0 capabilities. There is a more advanced capability called PPS which would allow more granular voltage setting, but that requires USB-PD 3.0 support, which this project does not have.

How is it Used?

This project is in effect a Python (actually MicroPython) library. You can load it onto the Pi Pico, and then type Python commands to choose what voltage you want. If desired, the project could be easily extended to have button inputs, since it’s just a bit of Python code that anyone learning MicroPython on the Pico will be comfortable doing.

What’s Required?

The diagram in the introduction shows the physical topology and the items required. The USB-C charger needs to support at least USB-C PD 2.0. I have tried an Anker charger and a UGREEN charger, and they both functioned with this project. Many other chargers and power supplies will function too, provided they specify that USB-C PD 2.0 or 3.0 or higher is supported.

A board is needed that contains USB-C PD ‘Sink’ capability. I used a USB-C Sink Click board, but any other board that contains the STUSB4500 chip should be fine. A Pi Pico , or any other board that supports MicroPython is needed for this project. I have only tested with Pi Pico.

A DC Electronic Load would also be handy. I have not used these particular ones, but MP710259  or TENMA 72-13210  could be possible options depending on region.

How Does it Work?

The diagram below shows the logical view. Both the charger and the USB-C Sink Click board implement USB-C PD functions, namely the Source and Sink functions respectively. They are used to negotiate the desired voltage, and the Source function provides feedback to a power supply circuit (for instance a DC-DC converter) to adjust to the configured voltage.

image

The STUSB4500 USB-PD Sink chip is configured via I2C using the Pi Pico.

Connections

The following connections are required between the USB Sink Click board and the Pi Pico:

Sink Click Pin STUSB4500 QFN Pin Pi Pico Name Pi Pico Pin
SDA 8 GPIO4 6
SCL 7 GPIO5 7
INT (ALERT) 19 GPIO15 20
RST (RESET) 6 GPIO14 19
3V3 22 (VSYS) 3V3 36
GND 10 GND 8

The Pico-Eurocard could be used for this project:

image


Installing the MicroPython Code

Follow the instructions at the raspberrypi website in order to install MicroPython onto the Pi Pico. Install the application called Thonny. Download the usbsink MicroPython code onto your PC.

Next, connect up the Pico to your PC using a USB cable, and start up Thonny. Click the red “Stop/Restart Backend” icon in the menu bar, and you should see a MicroPython command prompt appear in the lower pane. That’s the command prompt where Python commands can be typed.

In the left pane, navigate to the usbsink code, right-click on it, and select to upload it to the Pi Pico. That’s it, the code is installed : )

Using the Project

Start up Thonny if it’s not running, and make sure the command prompt is available (press the red icon mentioned earlier if the prompt is not available).

Here are some commands that can be typed at the prompt. To start, import the usbsink code, and read the contents of the device:

>>> import usbsink as pd
>>> pd.read()

Now you can inspect three profiles:

>>> pd.get_voltage(1)
5.0
>>> pd.get_voltage(2)
9.0
>>> pd.get_voltage(3)
5.0
>>>

The first profile is always set to 5V, but the other two can be changed, for instance, to change the third profile to 15V you can type:

>>> pd.set_voltage(3,15)

To see the currently activated profile number, type the following command, and you’ll see a value returned:

>>> pd.get_pdonum()
2

To set the profile to 3, type:

>>> pd.set_pdonum(3)
>>> pd.softreset()

If there is a multimeter connected to the output connections on the USB Sink Click board, then you’ll see the output voltage change to 15V.

Next Steps

I have not tried all the possible commands that the STUSB4500 chip accepts. There may be errors in the code. It could be interesting to explore the commands available in the code, to see what happens. If you spot errors or make changes, please share them! I'm very new to the STUSB4500 chip, so I don't know much about it and it could be better to refer to the (unfortunately very difficult to follow) documentation and then please share your findings to help others since anyone interested in working with USB-C Power Delivery may at some point need to be able to negotiate different voltages to see what happens with any equipment under test.

Summary

This simple project can be used to experiment a bit with USB-C Power Delivery.

I plan to use it to test USB-C power supplies, using a DC load. I’ll be able to programmatically select an output voltage using this project, and then see if the power supply can support the current that the DC load will demand.

Thanks for reading!

  • Sign in to reply
  • DAB
    DAB over 2 years ago

    Nice project.

    I was amazed at all of the possible options under the USB C specification.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • neuromodulator
    neuromodulator over 2 years ago in reply to shabaz

    I once burned an SBC (that I won on E14) by connecting the wrong barrel power supply to it, so I'm thinking that PD is the ideal solution because you avoid that possibility as well. As to IC's I once found a page that compared many of them, and I remember there  was a huge range in terms of capabilities and implementation difficulty. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wolfgangfriedrich
    wolfgangfriedrich over 2 years ago in reply to scottiebabe

    The CY4533 and the PD chipCYPD3177 on there are great as you can set the requested voltage and current through resistor deviders. The next generation is the CY4535 with the CYPD3176 controller, which also has the resistir dividers and is programmable through I2C for PPS mode. I could not track down the user manual and programming guide yet, but this will be my next major project.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • scottiebabe
    scottiebabe over 2 years ago in reply to shabaz

    Yes, it certainly looks neat, but has one extra digit in its price for an impulse purchase.

    I think I will give the $10 logic analyzer another try, following your blog.

    If pulseview decodes usb-pd then that's great.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 2 years ago in reply to scottiebabe

    That CY4500 PD Protocol Analyzer looks very neat. Not really a price for occasional use unfortunately, but probably worthwhile for those who want to train up at work or are designing/testing for commercial projects with USB-C PD.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube