- SPC
- API
- Class SPC(i2c)
- Properties
- Methods
- SPC.is_ready() -> bool
- SPC.read_input_voltage() -> int
- SPC.read_input_current() -> int
- SPC.read_output_voltage() -> int
- SPC.read_output_current() -> int
- SPC.read_battery_voltage() -> int
- SPC.read_battery_current() -> int
- SPC.read_battery_percentage() -> int
- SPC.read_battery_capacity() -> int
- SPC.read_power_source() -> int
- SPC.read_is_input_plugged_in() -> bool
- SPC.read_is_charging() -> bool
- SPC.read_fan_power() -> int
- SPC.read_shutdown_request() -> bool
- SPC.read_default_on() -> bool
- SPC.read_shutdown_percentage() -> int
- SPC.read_power_off_percentage() -> int
- SPC.read_all() -> dict
- SPC.write_fan_power(power: int) -> None
- SPC.write_shutdown_percentage(percentage: int) -> None
- SPC.write_power_off_percentage(percentage: int) -> None
- SPC.read_firmware_version() -> str
- Constants
- About SunFounder
- Contact us
- API
Sunfounder Power Control
Class for SunFounder Power Control.
- i2c: I2C object from machine module.
from spc.spc import SPC
from machine import Pin, I2C
# For the Raspberry Pi Pico, using I2C(0), pin 0 as SDA, pin 1 as SCL
i2c = I2C(0, sda=Pin(0), scl=Pin(1))
spc = SPC(i2c)
current device class.
print(spc.device.name)
print(spc.device.peripheral)
Check if the SPC is ready.
spc.is_ready()
Read the input voltage in mV.
input_voltage = spc.read_input_voltage()
print(f"Input voltage: {input_voltage} mV")
Read the input current in mA.
input_current = spc.read_input_current()
print(f"Input current: {input_current} mA")
Read the output voltage in mV.
output_voltage = spc.read_output_voltage()
print(f"Output voltage: {output_voltage} mV")
Read the output current in mA.
output_current = spc.read_output_current()
print(f"Output current: {output_current} mA")
Read the battery voltage in mV.
battery_voltage = spc.read_battery_voltage()
print(f"Battery voltage: {battery_voltage} mV")
Read the battery current in mA.
battery_current = spc.read_battery_current()
print(f"Battery current: {battery_current} mA")
Read the battery percentage in %.
battery_percentage = spc.read_battery_percentage()
print(f"Battery percentage: {battery_percentage} %")
Read the battery capacity in mAh.
battery_capacity = spc.read_battery_capacity()
print(f"Battery capacity: {battery_capacity} mAh")
Read the power source. 0: EXTERNAL_INPUT, 1: BATTERY.
power_source = spc.read_power_source()
if power_source == spc.EXTERNAL_INPUT:
print("Power source: EXTERNAL_INPUT")
elif power_source == spc.BATTERY:
print("Power source: BATTERY")
else:
print("Unknown power source")
Read if the input is plugged in.
is_input_plugged_in = spc.read_is_input_plugged_in()
print(f"Is input plugged in: {is_input_plugged_in}")
Read if the battery is charging.
is_charging = spc.read_is_charging()
print(f"Is charging: {is_charging}")
Read the fan power in %.
fan_power = spc.read_fan_power()
print(f"Fan power: {fan_power} %")
Read if a shutdown request is received. 0: None, 1: Low battery, 2: Button.
shutdown_request = spc.read_shutdown_request()
if shutdown_request == spc.SHUTDOWN_REQUEST_NONE:
print("Shutdown request: None")
elif shutdown_request == spc.SHUTDOWN_REQUEST_LOW_BATTERY:
print("Shutdown request: Low battery")
elif shutdown_request == spc.SHUTDOWN_REQUEST_BUTTON:
print("Shutdown request: Button")
else:
print("Unknown shutdown request")
Read if the default-on mode is enabled.
default_on = spc.read_default_on()
print(f"Default on: {default_on}")
Read the shutdown percentage in %.
shutdown_percentage = spc.read_shutdown_percentage()
print(f"Shutdown percentage: {shutdown_percentage} %")
Read the power off percentage in %.
power_off_percentage = spc.read_power_off_percentage()
print(f"Power off percentage: {power_off_percentage} %")
Read all avaliable the data.
data = spc.read_all()
print(data)
Write the fan power in %.
spc.write_fan_power(50)
Write the shutdown percentage in %. Range: 10-100
spc.write_shutdown_percentage(10)
Write the power off percentage in %. Range: 5-100
spc.write_power_off_percentage(5)
Read the firmware version.
firmware_version = spc.read_firmware_version()
print(f"Firmware version: {firmware_version}")
Power source: EXTERNAL_INPUT.
Power source: BATTERY.
Shutdown request: None.
Shutdown request: Low battery.
Shutdown request: Button.
SunFounder is a company focused on STEAM education with products like open source robots, development boards, STEAM kit, modules, tools and other smart devices distributed globally. In SunFounder, we strive to help elementary and middle school students as well as hobbyists, through STEAM education, strengthen their hands-on practices and problem-solving abilities. In this way, we hope to disseminate knowledge and provide skill training in a full-of-joy way, thus fostering your interest in programming and making, and exposing you to a fascinating world of science and engineering. To embrace the future of artificial intelligence, it is urgent and meaningful to learn abundant STEAM knowledge.
website: www.sunfounder.com
E-mail: service@sunfounder.com