Skip to main content

MicroPython driver for the LMS Line Sensor over I2C

Project description

lms line sensor logo

LMS Line Sensor

lms-line-sensor is a MicroPython and MicroBlocks driver for the LMS Line Sensor board. It communicates with the sensor over I2C and exposes a small API for reading raw or calibrated data, calibration management, and LED control.

Features

  • Reads 8 light sensor channels in a single transfer.
  • Exposes position, derivative, and line shape.
  • Supports raw and calibrated sensor modes.
  • Starts calibration and stores calibration values in EEPROM.
  • Controls the IR emitter and RGB LED display modes.
  • Aimed at ESP23 (LMS-ESP32)

Installation

Micropython Using ViperIDE Package Manager (Recommended)

  1. Open ViperIDE on your device
  2. Go to ToolsPackage Manager
  3. Select Install Package via Link
  4. Enter the package link: https://github.com/antonsmindstorms/lms-line-sensor.git
  5. Follow the on-screen prompts to complete installation

MicroBlocks

Open a microblocks editor and drag LMS Line Sensor into the browser window.

On regular Python

This package targets MicroPython devices. For packaging and distribution it is published on PyPI, but it must run on hardware that provides the machine module.

Install from PyPI:

pip install lms-line-sensor

Copy the installed line_sensor.py module to your MicroPython device if your deployment flow does not install packages directly on the board.

Quick Start

Micropython

from time import sleep

from line_sensor import LineSensor

sensor = LineSensor(scl_pin=4, sda_pin=5, device_addr=51)

sensor.ir_led_on()
sensor.load_calibration_from_rom()
sensor.mode_calibrated()

while True:
    position = sensor.position()
    derivative = sensor.position_derivative()
    print(position, derivative)
    sleep(0.1)

Microblocks

Here's a simple program that reads the line shape and distance from center. Shape is an ASCII character in the shape of the line:

SHAPE_NONE     = ' ',
SHAPE_STRAIGHT = '|',
SHAPE_T        = 'T',
SHAPE_L_LEFT   = '<',
SHAPE_L_RIGHT  = '>',
SHAPE_Y        = 'Y'

Microblocks example

API Overview

LineSensor

The LineSensor class provides the public API.

  • light_values() returns the 8 raw light sensor values.
  • data(*indices) returns the full 13-byte response or selected entries.
  • position() returns the current line position.
  • position_derivative() returns the derivative of the line position.
  • shape() returns the sensor-reported shape metric.
  • mode_raw() switches to raw reading mode.
  • mode_calibrated() switches to calibrated reading mode.
  • start_calibration() starts sensor calibration.
  • ir_led_on() and ir_led_off() control the IR emitter.
  • rgb_led_mode(mode) changes the RGB LED display mode.
  • save_calibration_in_rom() stores calibration data in EEPROM.
  • load_calibration_from_rom() loads calibration data from EEPROM.

Documentation

Sphinx documentation sources live in docs. Build them with:

pip install .[docs]
sphinx-build -b html docs docs/_build/html

Development Notes

  • Source module: micropython/line_sensor.py
  • API docs entry point: docs/index.rst
  • The Sphinx configuration mocks the MicroPython machine module so docs can be built on desktop Python.
  • Submit update to Pypi:
    • Update version in line sensor.py
    • Update version in package.json
    • Activate venv
    • rm -rf ./dist && python -m build && twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lms_line_sensor-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lms_line_sensor-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file lms_line_sensor-0.1.0.tar.gz.

File metadata

  • Download URL: lms_line_sensor-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for lms_line_sensor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a5f57fb47f44bdc303817284558ba8521cf1a5b777b988e2841c0413c6841edd
MD5 8e1348d1ba0df3fa23c8b81f93ffad02
BLAKE2b-256 e332d46353b77d6b4c23d4bd288da90f4dd431b8891d8a91908e9243f3826e29

See more details on using hashes here.

File details

Details for the file lms_line_sensor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lms_line_sensor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1fbab2bdc3b51d360c1a010de6e2b6b398c54f57ce6c26fa5f4f272122e61b6
MD5 b7a7fbf270dfc213555c28b4cd0035a2
BLAKE2b-256 29d2549899cc49fcf6c43cd17d590688d22034be70d3b36ebafa71909cb9f48a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page