Skip to content

AntonsMindstorms/lms-line-sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 Installation 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 Installation

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

Regular Python Installation

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

You can read the documentation on our API docs site or build the Sphinx documentation from source in docs. Build them with:

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/*

About

MicroPython and MicroBlocks API for the line sensor

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages