-
Notifications
You must be signed in to change notification settings - Fork 0
Edge Cases
vihaanvp edited this page Jul 3, 2026
·
3 revisions
-
Multiple Board instances: Each creates its own serial connection. The last one created becomes the active board for
Servo. -
get_active_board()before any Board exists: RaisesRuntimeError. -
stbypin: If provided, automatically set HIGH (wake) on creation. Set LOW (sleep) onclose(). -
Context manager: Always calls
close()even if an exception occurs inside thewithblock.
-
Speed range: Integer or float.
0= stopped,100= full. Converted internally to0.0–1.0for pyfirmata2 PWM. -
forward()/backward()with no argument: Defaults to100(full speed). -
set_speed()changes speed without affecting direction pins. -
stop()vsbrake():stop()lets the motor coast (inertia);brake()shorts the terminals for abrupt halting. -
Reusing after stop: Just call
forward()orbackward()again.
-
Angle clamping: All angles are clamped to
[0, 180]. Passing200behaves the same as180. Passing-10behaves the same as0. -
attach()requires a priorBoard: UsesBoard.get_active_board()internally. -
read()requires a priorwrite(): The library tracks the last commanded angle, not the physical angle (servos don't report position). -
move_smooth()whencurrent_angleisNone: Jumps directly to target without stepping. -
move_smooth()when already at target: No-op (no writes sent). -
sweep()direction: Automatically determined bystartvsend.stepmust be positive. -
detach(): Clears all state. Callattach()again to reuse.
-
Lazy imports:
adafruit_vl53l0x,board,busio,digitalioare imported only whenVL53L0X()orauto_address()is called — safe to importmegawrapperon any platform. -
Auto I2C: If no
i2cis passed,busio.I2C(board.SCL, board.SDA)is created. Requires Blinka on the host (e.g. Raspberry Pi). -
Single sensor: Just call
VL53L0X()— uses default address0x29. -
Multi-sensor limits:
auto_address()assigns addresses0x30–0x3F→ max 16 sensors. The order ofxshut_pinsdetermines the order of the returned list. -
distanceunits: Returns centimetres (raw mm ÷ 10). -
No exception wrapping: If the underlying
adafruit_vl53l0xraises (e.g. no sensor found at the address), the raw exception propagates. There is noSensorErrorin the MegaWrapper hierarchy.
-
Port already in use: pyfirmata2 will raise an exception, which MegaWrapper converts to
BoardConnectionError. - Serial latency: Some Arduino clones may need extra time to initialise after opening the serial port.
- Power: Always use an external power supply for motors and servos. Do not draw significant current from the Arduino's 5 V pin.
-
delay()vstime.sleep():delay(ms)is a thin wrapper aroundtime.sleep(ms / 1000)— they are equivalent. Use whichever you prefer.