MustafaMulla29/rp2040-bldc-motor-controller
Hardware assembly metadata and PCB geometry for a controller board with a snap-off rotary-encoder section, plus four parallel 150 µF/50 V bulk electrolytic capacitors filtering the motor supply.
- Version
- 2.0.40
- License
- unset
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone MustafaMulla29/rp2040-bldc-motor-controller # download the package files into ./rp2040-bldc-motor-controller
tsci add MustafaMulla29/rp2040-bldc-motor-controller # add it to your project as @tsci/MustafaMulla29.rp2040-bldc-motor-controllerIn a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.
firmware/oled_bringup.py
"""Display-only test on the provisioned 9 V / 3 A PD profile; motor stays OFF.
Run alone after provisioning and cold boot. Not installed as automatic main.py.
The OLED hardware has an independent power-fail interlock. This diagnostic
still supervises the USB-PD contract and leaves the motor OFF.
"""
from oled_ssd1309 import Display, power_off
from pd_profile import verify_runtime
from power_policy import valid_motor_contract, adc_millivolts, DEFAULT_MV
def run():
from machine import Pin, ADC, I2C
from time import sleep_ms
Pin(3, Pin.OUT, value=0)
Pin(2, Pin.OUT, value=0)
pd_ok = Pin(6, Pin.IN)
vbus = ADC(26)
pd = I2C(1, sda=Pin(22), scl=Pin(23), freq=100_000)
def power_ready():
verify_runtime(pd, selected_mv=DEFAULT_MV)
rdo = int.from_bytes(pd.readfrom_mem(0x28, 0x91, 4), 'little')
pe = pd.readfrom_mem(0x28, 0x29, 1)[0]
return valid_motor_contract(adc_millivolts(vbus.read_u16()), rdo, pe,
not pd_ok.value(), DEFAULT_MV)
ui = I2C(0, sda=Pin(16), scl=Pin(17), freq=100_000)
try:
# Clear RP2 weak 3.3 V pulls; MCU-side pullups are 3.3 V; U23 isolates the held 3.0 V OLED bus.
Pin(16).init(pull=None)
Pin(17).init(pull=None)
display = Display(ui, delay_ms=sleep_ms, power_ready=power_ready)
import framebuf
fb = framebuf.FrameBuffer(display.buffer, 128, 64, framebuf.MONO_VLSB)
fb.text('BLDC controller', 0, 0, 1)
fb.text('1.54 OLED TEST', 0, 16, 1)
fb.text('MOTOR DISABLED', 0, 32, 1)
fb.rect(0, 48, 128, 16, 1)
display.show()
while True:
display.require_power()
sleep_ms(100)
except BaseException:
# Cover failed construction, runtime PD loss, I2C errors and Ctrl-C.
# SSD1306 charge-pump commands cannot turn off this external boost.
try:
power_off(ui, delay_ms=sleep_ms)
except BaseException as error:
print("OLED shutdown failed:", error)
raise
if __name__ == '__main__':
run()