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_ssd1306.py
"""ER-OLED013A1-1W (SSD1306) diagnostic, independent of motor control.
Use hardware I2C0 on GP16/17 at 100 kHz. External pull-ups are to 3.0 V.
No internal 3.3 V pull-ups; wait for the supervisor and charge pump supply.
"""
try:
from time import sleep_ms
except ImportError:
from time import sleep
def sleep_ms(ms): sleep(ms/1000)
class Display:
def __init__(self, i2c, address=0x3c, delay_ms=sleep_ms, power_ready=None):
self.i2c, self.address = i2c, address
self.buffer = bytearray(1024)
self.power_ready = power_ready
delay_ms(350)
self.off()
self.require_power()
# ER-OLED013-1 manufacturer I2C demo: internal DC/DC, contrast 0x8F.
self.command(0xae, 0xd5, 0x80, 0xa8, 0x3f, 0xd3, 0, 0x40,
0x8d, 0x14, 0xa1, 0xc8, 0xda, 0x12, 0x81, 0x8f,
0xd9, 0xf1, 0xdb, 0x40, 0xa4, 0xa6, 0x20, 0)
self.show()
delay_ms(100)
self.require_power()
self.command(0xaf)
def require_power(self):
try:
if self.power_ready is None or not self.power_ready():
raise OSError("OLED requires a verified 3 A USB-PD contract")
except Exception:
self.off()
raise
def command(self, *values):
self.i2c.writeto(self.address, b'\x00' + bytes(values))
def show(self):
self.command(0x21, 0, 127, 0x22, 0, 7)
# Small writes also work with the RP2040 MicroPython I2C driver.
for start in range(0, 1024, 128):
self.i2c.writeto(self.address, b'\x40' + self.buffer[start:start+128])
def fill(self, on):
self.buffer[:] = bytes([0xff if on else 0]) * 1024
def off(self):
self.command(0xae, 0x8d, 0x10)