Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Modulino SMARS

A SMARS robot with five senses, built from Arduino Modulinos and running MicroPython on a board Arduino didn't make.

Sense Module What it does
See Modulino Distance VL53L4CD time-of-flight ranging
Hear / speak Modulino Buzzer tones and tunes
Move Modulino Motors drives SMARS's two stock N20 motors
Show Modulino LED Matrix an 8x12 face
Measure Modulino Movement six-axis IMU, tilt and rotation

Brain: UnexpectedMaker FeatherS2 Neo (ESP32-S2). Chassis: stock SMARS — motors, wheels, tracks and the 9 V battery, unchanged.


The one thing that trips everyone up

Arduino's Modulino library works out which pins carry I2C by looking up os.uname().machine against a table of Arduino boards. The FeatherS2 Neo isn't on that table, so the lookup fails and construction raises:

RuntimeError: I2C interface couldn't be determined automatically for '...'

Nothing is wrong with your wiring or your modules. You just have to name the bus yourself:

from machine import I2C, Pin
from modulino import ModulinoDistance

i2c = I2C(0, scl=Pin(9), sda=Pin(8))     # FeatherS2 Neo's I2C pins
distance = ModulinoDistance(i2c_bus=i2c)

Two extra lines, and Arduino's sensors run on someone else's board. Every Modulino class takes i2c_bus, so build the bus once and hand it to each module. That's all config.py does.

Pin numbers verified against MicroPython's own board definition, ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.h: MICROPY_HW_I2C0_SCL (9), MICROPY_HW_I2C0_SDA (8).

Running a different board? Change SCL_PIN and SDA_PIN in config.py and everything else works unchanged. That's the whole point.


Power — two supplies, one wire

Everything on this robot plugs in, except one connection:

  • The Qwiic chain carries 3.3 V logic to all five modules — plug, plug, plug.
  • The LiPo plugs into the Feather's own JST socket.
  • The stock 9 V battery wires into the Modulino Motors screw terminal.

Modulino Motors runs its motor supply completely separately from the logic side: VIN wants 5-24 V, and the 9 V sits comfortably in that window. The grounds are common; the positive rails are isolated.

Never run motors off the Qwiic 3V3 rail. It can't source the current, and a stalled motor pulling several amps through a Qwiic cable is a fire, not a brownout.


Install

Flash MicroPython to the FeatherS2 Neo, then install the Modulino library. One package covers every module:

import mip
mip.install("github:arduino/arduino-modulino-mpy")

Snakie offers to do this for you when you drop a Modulino onto the board — once, however many Modulinos your design has.

Then copy this folder to the board:

config.py      board pins, addresses, drivetrain and behaviour tuning
tools/         desktop scripts — NOT copied to the board
sprites.py     loads Snakie .spr sprite animations
faces.py       the eyes (from a sprite) plus fallback ASCII expressions
*.spr          face artwork, drawn in Snakie's Sprite editor
smars.py       the ModulinoSMARS class — all five senses in one object
main.py        the full demo, runs on power-up
demos/         you can ignore all these files
  scan.py      what's actually on the Qwiic chain
  sprite_demo.py  how to use .spr sprites from MicroPython
  motor_setup.py  wizard: works out the motor wiring, writes config.py
  orient.py    which way up the LED panel is mounted
  selfcheck.py sprite rendering diagnostic
  see.py       Distance on its own
  express.py   Buzzer + LED Matrix
  move.py      Motors + Movement
stl/           the two printed parts - don't copy these

The face

The eyes come from a Snakie .spr sprite, drawn in the Sprite editor (Display instrument -> "Sprites") rather than hand-coded. The file carries its own size, frame count and timing, so restyling the robot's face is a drawing job, not a code job.

Two ship with the project, both 12x8 and both a six-frame blink at 125 ms:

File Eyes
simple-eyes.spr solid blocks, matching faces.py (default)
blinking-eyes.spr large and round, with pupils
blink.spr smaller ovals

simple-eyes.spr is generated rather than drawn — tools/make_simple_eyes.py builds it, and its open and shut frames are pixel-identical to faces.NEUTRAL and faces.BLINK, so the blink animation and the static expressions are visibly the same robot. Edit that script and re-run it to restyle. It runs on your Mac, not the board.

.spr files are binary, and some copy tools mangle them. If a file arrives UTF-8-mangled, every byte above 0x7F becomes U+FFFD and the artwork turns to noise. sprites.py refuses such a file rather than drawing it.

The robust way round it is a .py export, which writes every byte as an ASCII escape and survives any copy. Snakie's Sprite editor exports these directly, or convert one you already have:

python3 tools/spr_to_py.py simple-eyes.spr     # -> simple_eyes.py

Then point EYES_SPRITE at "simple_eyes.py". sprites.load() reads either format, and everything downstream behaves identically.

The generated module writes each frame as rows of # and ., the same way faces.py draws its expressions — so the artwork is readable in the source and editable with nothing but a text editor:

FRAMES = (
    (   # frame 0
        "............",
        "..###..###..",
        ".####..####.",
        ...
    ),
)

Anything that isn't a space or a dot counts as lit, so #, O and X all work. sprites.py also accepts the packed-bytes form that Snakie's own editor exports, and honours a DURATIONS tuple for per-frame timing if one is present.

Point EYES_SPRITE in config.py at whichever you want, or at your own. Set it to None to fall back to the hand-drawn ASCII expressions in faces.py.

import faces
faces.EYES              # the loaded Sprite, or None
faces.RESTING           # the open-eyed frame — the robot's default face
faces.EYES.frame(3)     # any individual frame

The other expressions — HAPPY, SURPRISED, ALERT, LOOK_LEFT, LOOK_RIGHT, DIZZY — have no sprite equivalent, so they stay as ASCII art in faces.py. Draw replacements in the Sprite editor whenever you want; draw() takes either kind.

Keep the two styles matched. The ASCII expressions are drawn to look like the shipped sprite: two 6x6 outlined eyes filling the panel, pupils in the middle, no mouth. If you point EYES_SPRITE at artwork in a different style, redraw the ASCII faces to match — otherwise the robot's expression will visibly change character every time it switches between a sprite face and an ASCII one, which reads as a glitch rather than an expression.

Using sprites from your own code

import demos.sprite_demo        # the full tour

The whole API in five lines:

import sprites
eyes = sprites.load("simple-eyes.spr")   # None if missing or corrupt
eyes.draw(matrix, 0)                     # one frame
eyes.play(matrix, loops=3)               # animate (blocks)
eyes.frame(3)                            # a handle you can keep and pass around

Everything the animation needs — size, frame count, per-frame timing — comes out of the file, so redrawing the sprite in Snakie changes how the robot looks without touching any code. demos/sprite_demo.py walks through single frames, blocking playback, stepping frame by frame, positioning with an x offset, and animating without blocking.

Blinking without going blind

A six-frame blink at 125 ms is three quarters of a second. Playing that with sleep_ms inside a driving robot's loop means the robot isn't looking where it's going for the whole animation — far enough at cruising speed to hit the thing it was about to see.

So main.py drives the blink non-blocking:

bot.start_blink()        # arm it
...
while True:
    bot.tick_blink()     # draws the next frame only when it's due
    ...                  # sensing carries on in between

bot.blink() still exists and still blocks — fine when the robot is standing still, wrong while it's moving.


Running it

main.py runs automatically at power-up. It arms the motors on a three second countdown first, so the robot doesn't drive off the bench the moment you plug it in. Ctrl-C in the REPL stops it cleanly and releases the motors.

The robot roams, stops when something gets within 10 cm, backs off and turns away, blinks when idle, and sits still with a startled face if you pick it up.

Individual senses, from the REPL:

import demos.scan       # start here if something isn't responding
import demos.see
import demos.express
import demos.move

Or drive it yourself:

from smars import ModulinoSMARS
import faces

bot = ModulinoSMARS()

bot.see()                    # centimetres, or None when nothing's in range
bot.show(faces.HAPPY)
bot.beep(880, 150)
bot.forward()
bot.tilt()                   # .x / .y / .z in g
bot.shutdown()               # always

Tuning it for your robot

Everything adjustable is in config.py.

The motors do anything other than drive straight forward. Don't guess — there are eight combinations of SWAP_MOTORS, INVERT_LEFT and INVERT_RIGHT, and working through them by hand is tedious:

import demos.motor_setup      # runs the wizard

It runs one motor at a time, asks which side moved and which way it went, works out all three settings from your answers, and offers to write them into config.py (leaving the rest of the file untouched). Then soft-reboot so the new config is imported, and check it:

import demos.motor_setup
demos.motor_setup.verify()

The motors run during this, so hold the robot with its tracks free. If you'd rather set them by hand: flip INVERT_RIGHT if it spins instead of driving forward, flip both inverts if it drives backwards, and set SWAP_MOTORS = True if left and right are the wrong way round.

It reports tilting left when you tip it right. That depends on how the Movement module is seated in the holder — swap the signs in tilt_direction() in smars.py. A mounting question, not a bug.

It doesn't move on tracks. Raise CRUISE_SPEED — tracks have more friction than wheels.

The face is upside down. The module can't know which way round it was seated in the holder, so the correction is in software. Set both MATRIX_FLIP_X and MATRIX_FLIP_Y in config.py — rotating a picture 180 degrees is a flip on each axis.

Symptom Setting
Upside down both True
Upside down but text reads correctly MATRIX_FLIP_Y only
Mirrored left-to-right MATRIX_FLIP_X only
Correct both False

If it comes out the right way up but mirrored with both set, you only wanted one axis — turn MATRIX_FLIP_X back off.

Faces drawn with faces.draw() pick this up automatically. If you draw with the library's own primitives — text(), line(), rect(), ellipse() — finish with faces.show(matrix) rather than matrix.show(), because those write straight into the buffer and know nothing about orientation.


When something doesn't respond

Run demos/scan.py first. It names every Modulino on the bus, so you can tell a broken module from a connector that isn't clicked in properly.

Expected addresses, as a scan reports them:

Address Module
0x1E Buzzer
0x24 Motors
0x29 Distance
0x39 LED Matrix
0x6A Movement

A couple of quirks worth knowing:

  • The LED Matrix is documented as 0x72 in Arduino's library, but that's the 8-bit form — the firmware answers on 0x72 >> 1 = 0x39, which is what a scan shows. Every Modulino with an onboard MCU works this way. We pass the address explicitly because auto-discovery doesn't find it on every board.
  • The LED matrix stays dark but the code looks right. You're missing a show(). Drawing writes to a buffer in the board's memory; nothing lights up until you push it.
  • distance returns None. That's not an error — it means nothing is in range. Always check for it before comparing, or a stray None crashes the loop.
  • distance can also raise. There's a bug in the library itself: its internal read returns None on a sensor timeout, and the distance property then does if raw_distance <= 0, which raises TypeError on None rather than returning it. So an occasional timeout throws instead of reading empty. smars.py catches it and treats it as "nothing in range" — worth knowing if you call the library directly, because it will end a run that was otherwise fine.
  • Sprite art comes out as noise on the panel. The .spr was copied as text, not binary. Anything that UTF-8-decodes the file replaces every non-ASCII byte with U+FFFD (ef bf bd), inflating a 112-byte sprite to 154 and scrambling the artwork. sprites.py now refuses such a file with a clear message rather than drawing it. Re-copy with mpremote cp file.spr : and check the size on the board is 112, not 154.
  • The Distance module can't be duplicated. Its address is fixed in silicon at 0x29. Same for Movement, Thermo and Light. The modules with an onboard MCU are re-addressable, so those you can double up.

The build

Two custom 3D-printed parts replace the Arduino Uno bay and the old HC-SR04 holder — STLs in stl/. Everything else is stock SMARS.

Full write-up, per-sense walkthrough and both STL downloads: https://www.kevsrobots.com/blog/my-first-robot-just-got-five-new-senses.html

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages