ubitlogger


Nameubitlogger JSON
Version 0.5.2 PyPI version JSON
download
home_pageNone
SummaryA micro:bit serial port logger
upload_time2024-04-26 09:06:53
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8.10
licenseNone
keywords microbit microbit-v1 data-logger serial-port-listener
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![ubitlogger CI](https://github.com/p4irin/ubitlogger/actions/workflows/ci.yml/badge.svg)](https://github.com/p4irin/ubitlogger/actions/workflows/ci.yml)
![PyPI - Version](https://img.shields.io/pypi/v/ubitlogger)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ubitlogger)
![PyPI - License](https://img.shields.io/pypi/l/ubitlogger)
[![Static Badge](https://img.shields.io/badge/microbit-v1.3x-blue?logo=microbit&link=https%3A%2F%2Ftech.microbit.org%2Fhardware%2F1-3-revision%2F)](https://tech.microbit.org/hardware/1-3-revision/)
[![Static Badge](https://img.shields.io/badge/Ubuntu-22.04_LTS_jammy-orange?logo=ubuntu)](https://ubuntu.com/download/server)
[![Static Badge](https://img.shields.io/badge/Raspberry_Pi-4B_8GB-red?logo=raspberrypi&logoColor=red)](https://www.raspberrypi.com/products/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
# ubitlogger

A micro:bit serial port logger

## Stack

- Python 3.8, 3.9, 3.10
- Ubuntu 22.04 LTS jammy on
    - WSL 2 on Windows 11
        - usbipd-win to attach micro:bit to WSL
    - Raspberry Pi 4B, 8GB
- micro:bit
    - Board revision 1.3B
    - Bootloader 02xx
    - Interface 0253
    - See [update daplink version](https://tech.microbit.org/software/daplink-interface/#:~:text=It%20is%20possible%20to%20update%20the%20version%20of%20DAPLink%20running%20on%20your%20micro%3Abit)

## Installation

### From PyPI

```bash
(venv) $ pip install ubitlogger
(venv) $
```

### or from GitHub

```bash
(venv) $ pip install git+https://github.com/p4irin/ubitlogger.git
(venv) $
```

## Usage

```bash
# Show version
(venv) $ ubitlogger -V
x.y.x

# Show help
(venv) $ ubitlogger -h
usage: ubitlogger [-h] [-V] {start,flash} ...

micro:bit serial port logger

options:
  -h, --help     show this help message and exit
  -V, --version  show version and exit.

Sub commands:
  {start,flash}
    start        start logging
    flash        Flash an example sensor reader script to the micro:bit.
                 Does NOT work on WSL! On Ubuntu jammy the micro:bit is
                 NOT auto mounted! You need to mount it like "sudo mount
                 /dev/<device> /media/MICROBIT" Figure out the <device>
                 with "sudo fdisk -l". To flash, you need sudo and the
                 path to ubitlogger! I.e., "sudo venv/bin/ubitlogger
                 flash -s light", assuming you use a virtualenv venv.

# Show help on start sub command
(venv) $ ubitlogger start -h
usage: ubitlogger start [-h] [-d] [-t TIMEOUT] [-i INTERVAL]

options:
  -h, --help            show this help message and exit
  -d, --debug           show debugging output
  -t TIMEOUT, --timeout TIMEOUT
                        set a timeout (float)
  -i INTERVAL, --interval INTERVAL
                        time between readings

# Show help on the flash sub command
(venv) $ ubitlogger flash -h
usage: ubitlogger flash [-h] -s {temperature,light,accelerometer,radio} [-rg RADIO_GROUP]

options:
  -h, --help            show this help message and exit
  -s {temperature,light,accelerometer,radio}, --sensor {temperature,light,accelerometer,radio}
                        Specify the sensor to read
  -rg RADIO_GROUP, --radio-group RADIO_GROUP
                        Specify the "group" the radio should listen on.
                        A "group" is a number between 0 and 255, inclusive.
                        The default is 0.

# Log to the console with defaults
(venv) $ ubitlogger start
...
<data>
...
# Hit CTRL-C to stop logging
^C
Exited by CTRL-C
Cleaning up thread
--> Waiting for thread to finish

# Log to a file
(venv) $ ubitlogger start > data.log

# Flashing an example script to read a sensor (temperature, light, accelerometer and radio).
# This doesn't work on WSL as we can't mount the micro:bit as a
# USB mass storage device.
# On Ubuntu jammy the micro:bit isn't auto mounted.
# First figure out the device with
(venv) $ sudo fdisk -l
# and then mount it like this
(venv) $ sudo mount /dev/<device> /media/MICROBIT

# Flash a script to the micro:bit that reads the light sensor and sends
# readings to the serial port.
(venv) $ sudo venv/bin/ubitlogger flash -s light

# Flash a script to the micro:bit that lets it act like a
# receiver of data send by other micro:bits. Data received
# is sent over the serial link to ubitlogger.
# This example flashes a script that listens on radio group 6.
(venv) $ sudo venv/bin/ubitlogger flash -s radio -rg 6
(venv) $ ubitlogger start -d
```

## Using ubitlogger from a linux distro on WSL 2

Connect a USB device to your linux distro on WSL 2 using [usbipd-win](https://github.com/dorssel/usbipd-win)

List USB devices

```powershell
PS C:\Users\p4irin> usbipd list --usbids

Connected:
BUSID  VID:PID  DEVICE                          STATE
1-1    046d:c534  Logitech, Inc., NanoReceiver  Not shared
1-3    0d28:0204  NXP, ARM  mbed                Not Shared
...
```

Register/bind a USB device for sharing. Device "NXP, ARM mbed" with busid _1-3_ identifies our micro:bit:

```powershell
PS C:\Users\p4irin> usbipd bind --busid 1-3
```

If you list USB devices again, the microbit wil show up as _Shared_:

```powershell
PS C:\Users\p4irin> usbipd list --usbids

Connected:
BUSID  VID:PID  DEVICE                          STATE
1-1    046d:c534  Logitech, Inc., NanoReceiver  Not shared
1-3    0d28:0204  NXP, ARM  mbed                Shared
...
PS C:\Users\p4irin>
```

Attach the USB device to WSL:

```powershell
PS C:\Users\p4irin> usbipd attach --wsl --busid 1-3 --auto-attach

usbipd: info: Using WSL distribution 'Ubuntu-22.04' to attach; the device will be available in all WSL 2 distributions.
usbipd: info: Using IP address 172.21.144.1 to reach the host.
usbipd: info: Starting endless attach loop; press Ctrl+C to quit.

PS C:\Users\p4irin>
```

Listing USB devices will show the micro:bit attached:

```powershell
PS C:\Users\p4irin> usbipd list --usbids

Connected:
BUSID  VID:PID  DEVICE                          STATE
1-1    046d:c534  Logitech, Inc., NanoReceiver  Not shared
1-3    0d28:0204  NXP, ARM  mbed                Attached
...
PS C:\Users\p4irin>
```

In your WSL distro's terminal, check if the micro:bit is listed:

```bash
$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 0d28:0204 NXP ARM mbed
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$
```

Now run _ubitlogger_ in your Python virtualenv:

```bash
(venv) $ ubitlogger start -d -t 3

Found a micro:bit on: /dev/ttyACM0
Listening on port /dev/ttyACM0
Baudrate: 115200
Data bits: 8
Stop bits: 1
Parity: N
timeout: 3.0
18 17
18 6
^C
Exited by CTRL-C
Cleaning up thread
--> Waiting for thread to finish.

(venv) $
```

To detach the device from WSL:

```powershell
PS C:\Users\p4irin> usbipd detach --busid 1-3
```

## Reference

* [pySerial](https://pythonhosted.org/pyserial/)
* [usbipd-win](https://github.com/dorssel/usbipd-win)
* [micro:bit 1.3x](https://tech.microbit.org/hardware/1-3-revision/)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ubitlogger",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8.10",
    "maintainer_email": null,
    "keywords": "microbit, microbit-v1, data-logger, serial-port-listener",
    "author": null,
    "author_email": "p4irin <p4irin.github.io@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/3a/e8/fccdd23990c6a6d101a9e589e48319567fb41b3cf602ef9607c9964e8ce1/ubitlogger-0.5.2.tar.gz",
    "platform": null,
    "description": "[![ubitlogger CI](https://github.com/p4irin/ubitlogger/actions/workflows/ci.yml/badge.svg)](https://github.com/p4irin/ubitlogger/actions/workflows/ci.yml)\n![PyPI - Version](https://img.shields.io/pypi/v/ubitlogger)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ubitlogger)\n![PyPI - License](https://img.shields.io/pypi/l/ubitlogger)\n[![Static Badge](https://img.shields.io/badge/microbit-v1.3x-blue?logo=microbit&link=https%3A%2F%2Ftech.microbit.org%2Fhardware%2F1-3-revision%2F)](https://tech.microbit.org/hardware/1-3-revision/)\n[![Static Badge](https://img.shields.io/badge/Ubuntu-22.04_LTS_jammy-orange?logo=ubuntu)](https://ubuntu.com/download/server)\n[![Static Badge](https://img.shields.io/badge/Raspberry_Pi-4B_8GB-red?logo=raspberrypi&logoColor=red)](https://www.raspberrypi.com/products/)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n# ubitlogger\n\nA micro:bit serial port logger\n\n## Stack\n\n- Python 3.8, 3.9, 3.10\n- Ubuntu 22.04 LTS jammy on\n    - WSL 2 on Windows 11\n        - usbipd-win to attach micro:bit to WSL\n    - Raspberry Pi 4B, 8GB\n- micro:bit\n    - Board revision 1.3B\n    - Bootloader 02xx\n    - Interface 0253\n    - See [update daplink version](https://tech.microbit.org/software/daplink-interface/#:~:text=It%20is%20possible%20to%20update%20the%20version%20of%20DAPLink%20running%20on%20your%20micro%3Abit)\n\n## Installation\n\n### From PyPI\n\n```bash\n(venv) $ pip install ubitlogger\n(venv) $\n```\n\n### or from GitHub\n\n```bash\n(venv) $ pip install git+https://github.com/p4irin/ubitlogger.git\n(venv) $\n```\n\n## Usage\n\n```bash\n# Show version\n(venv) $ ubitlogger -V\nx.y.x\n\n# Show help\n(venv) $ ubitlogger -h\nusage: ubitlogger [-h] [-V] {start,flash} ...\n\nmicro:bit serial port logger\n\noptions:\n  -h, --help     show this help message and exit\n  -V, --version  show version and exit.\n\nSub commands:\n  {start,flash}\n    start        start logging\n    flash        Flash an example sensor reader script to the micro:bit.\n                 Does NOT work on WSL! On Ubuntu jammy the micro:bit is\n                 NOT auto mounted! You need to mount it like \"sudo mount\n                 /dev/<device> /media/MICROBIT\" Figure out the <device>\n                 with \"sudo fdisk -l\". To flash, you need sudo and the\n                 path to ubitlogger! I.e., \"sudo venv/bin/ubitlogger\n                 flash -s light\", assuming you use a virtualenv venv.\n\n# Show help on start sub command\n(venv) $ ubitlogger start -h\nusage: ubitlogger start [-h] [-d] [-t TIMEOUT] [-i INTERVAL]\n\noptions:\n  -h, --help            show this help message and exit\n  -d, --debug           show debugging output\n  -t TIMEOUT, --timeout TIMEOUT\n                        set a timeout (float)\n  -i INTERVAL, --interval INTERVAL\n                        time between readings\n\n# Show help on the flash sub command\n(venv) $ ubitlogger flash -h\nusage: ubitlogger flash [-h] -s {temperature,light,accelerometer,radio} [-rg RADIO_GROUP]\n\noptions:\n  -h, --help            show this help message and exit\n  -s {temperature,light,accelerometer,radio}, --sensor {temperature,light,accelerometer,radio}\n                        Specify the sensor to read\n  -rg RADIO_GROUP, --radio-group RADIO_GROUP\n                        Specify the \"group\" the radio should listen on.\n                        A \"group\" is a number between 0 and 255, inclusive.\n                        The default is 0.\n\n# Log to the console with defaults\n(venv) $ ubitlogger start\n...\n<data>\n...\n# Hit CTRL-C to stop logging\n^C\nExited by CTRL-C\nCleaning up thread\n--> Waiting for thread to finish\n\n# Log to a file\n(venv) $ ubitlogger start > data.log\n\n# Flashing an example script to read a sensor (temperature, light, accelerometer and radio).\n# This doesn't work on WSL as we can't mount the micro:bit as a\n# USB mass storage device.\n# On Ubuntu jammy the micro:bit isn't auto mounted.\n# First figure out the device with\n(venv) $ sudo fdisk -l\n# and then mount it like this\n(venv) $ sudo mount /dev/<device> /media/MICROBIT\n\n# Flash a script to the micro:bit that reads the light sensor and sends\n# readings to the serial port.\n(venv) $ sudo venv/bin/ubitlogger flash -s light\n\n# Flash a script to the micro:bit that lets it act like a\n# receiver of data send by other micro:bits. Data received\n# is sent over the serial link to ubitlogger.\n# This example flashes a script that listens on radio group 6.\n(venv) $ sudo venv/bin/ubitlogger flash -s radio -rg 6\n(venv) $ ubitlogger start -d\n```\n\n## Using ubitlogger from a linux distro on WSL 2\n\nConnect a USB device to your linux distro on WSL 2 using [usbipd-win](https://github.com/dorssel/usbipd-win)\n\nList USB devices\n\n```powershell\nPS C:\\Users\\p4irin> usbipd list --usbids\n\nConnected:\nBUSID  VID:PID  DEVICE                          STATE\n1-1    046d:c534  Logitech, Inc., NanoReceiver  Not shared\n1-3    0d28:0204  NXP, ARM  mbed                Not Shared\n...\n```\n\nRegister/bind a USB device for sharing. Device \"NXP, ARM mbed\" with busid _1-3_ identifies our micro:bit:\n\n```powershell\nPS C:\\Users\\p4irin> usbipd bind --busid 1-3\n```\n\nIf you list USB devices again, the microbit wil show up as _Shared_:\n\n```powershell\nPS C:\\Users\\p4irin> usbipd list --usbids\n\nConnected:\nBUSID  VID:PID  DEVICE                          STATE\n1-1    046d:c534  Logitech, Inc., NanoReceiver  Not shared\n1-3    0d28:0204  NXP, ARM  mbed                Shared\n...\nPS C:\\Users\\p4irin>\n```\n\nAttach the USB device to WSL:\n\n```powershell\nPS C:\\Users\\p4irin> usbipd attach --wsl --busid 1-3 --auto-attach\n\nusbipd: info: Using WSL distribution 'Ubuntu-22.04' to attach; the device will be available in all WSL 2 distributions.\nusbipd: info: Using IP address 172.21.144.1 to reach the host.\nusbipd: info: Starting endless attach loop; press Ctrl+C to quit.\n\nPS C:\\Users\\p4irin>\n```\n\nListing USB devices will show the micro:bit attached:\n\n```powershell\nPS C:\\Users\\p4irin> usbipd list --usbids\n\nConnected:\nBUSID  VID:PID  DEVICE                          STATE\n1-1    046d:c534  Logitech, Inc., NanoReceiver  Not shared\n1-3    0d28:0204  NXP, ARM  mbed                Attached\n...\nPS C:\\Users\\p4irin>\n```\n\nIn your WSL distro's terminal, check if the micro:bit is listed:\n\n```bash\n$ lsusb\nBus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub\nBus 001 Device 004: ID 0d28:0204 NXP ARM mbed\nBus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub\n$\n```\n\nNow run _ubitlogger_ in your Python virtualenv:\n\n```bash\n(venv) $ ubitlogger start -d -t 3\n\nFound a micro:bit on: /dev/ttyACM0\nListening on port /dev/ttyACM0\nBaudrate: 115200\nData bits: 8\nStop bits: 1\nParity: N\ntimeout: 3.0\n18 17\n18 6\n^C\nExited by CTRL-C\nCleaning up thread\n--> Waiting for thread to finish.\n\n(venv) $\n```\n\nTo detach the device from WSL:\n\n```powershell\nPS C:\\Users\\p4irin> usbipd detach --busid 1-3\n```\n\n## Reference\n\n* [pySerial](https://pythonhosted.org/pyserial/)\n* [usbipd-win](https://github.com/dorssel/usbipd-win)\n* [micro:bit 1.3x](https://tech.microbit.org/hardware/1-3-revision/)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A micro:bit serial port logger",
    "version": "0.5.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/p4irin/ubitlogger/issues",
        "Homepage": "https://github.com/p4irin/ubitlogger"
    },
    "split_keywords": [
        "microbit",
        " microbit-v1",
        " data-logger",
        " serial-port-listener"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0f397ca553e1d26440503d008e2a53ccc42edbfd87145a90679c788a8a44e51b",
                "md5": "866eabe42e2bbdd2064eb206eaf0ef57",
                "sha256": "ee44451d0857ac476383c3d08ab4969924384fa7f80f29c623df239ac5bd1b6d"
            },
            "downloads": -1,
            "filename": "ubitlogger-0.5.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "866eabe42e2bbdd2064eb206eaf0ef57",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.10",
            "size": 8948,
            "upload_time": "2024-04-26T09:06:52",
            "upload_time_iso_8601": "2024-04-26T09:06:52.353830Z",
            "url": "https://files.pythonhosted.org/packages/0f/39/7ca553e1d26440503d008e2a53ccc42edbfd87145a90679c788a8a44e51b/ubitlogger-0.5.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3ae8fccdd23990c6a6d101a9e589e48319567fb41b3cf602ef9607c9964e8ce1",
                "md5": "1efe9a8827a2e95525a24b3aeb7f70c7",
                "sha256": "a008af33cdf90d35370554b90ae7496a1ab94ed9bc2a6de32eccdf187165006c"
            },
            "downloads": -1,
            "filename": "ubitlogger-0.5.2.tar.gz",
            "has_sig": false,
            "md5_digest": "1efe9a8827a2e95525a24b3aeb7f70c7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.10",
            "size": 10761,
            "upload_time": "2024-04-26T09:06:53",
            "upload_time_iso_8601": "2024-04-26T09:06:53.437190Z",
            "url": "https://files.pythonhosted.org/packages/3a/e8/fccdd23990c6a6d101a9e589e48319567fb41b3cf602ef9607c9964e8ce1/ubitlogger-0.5.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-26 09:06:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "p4irin",
    "github_project": "ubitlogger",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ubitlogger"
}
        
Elapsed time: 0.24978s