Metadata-Version: 2.1
Name: quarky-intellio
Version: 0.1.4
Summary: Official Intellio Python SDK
Author: Quarky Intellio Team
Project-URL: Homepage, https://ai.thestempedia.com/docs/quarky-intellio/
Project-URL: Support, https://thestempedia.com/contact/
Keywords: intellio,quarky,robotics,camera,ai
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: opencv-python
Requires-Dist: numpy
Requires-Dist: bleak

# Intellio Python Module

**Agilo Research Pvt Ltd (STEMpedia)**

**Connect Intellio hardware to Python to build robotics, sensor, computer-vision, and AI projects.**

The Intellio Python module exposes the `QuarkyIntellio` class. It connects to an Intellio board using a Bluetooth Low Energy (BLE) Wi-Fi setup flow, receives camera images over Wi-Fi, and provides Python methods for hardware controls such as LEDs, audio, motors, servos, and supported external sensors.

It can be combined with **OpenCV**, **MediaPipe**, and **NumPy** to build hand-tracking, gesture-recognition, eye-tracking, and other interactive projects on a computer.

> **Documentation scope:** This README is based on the `Intellio/camera.py`, `ble.py`, `ble_gui.py`, and `stream.py` source versions shared during development. It documents the methods **implemented in that source**, not a certification that every method has been tested on every firmware revision. In particular, Lightning RGB uses a special send-only workaround on the tested device; see [Lightning compatibility note](#lightning-compatibility-note).

## Contents

- [Features](#features)
- [Requirements](#requirements)
- [Project structure](#project-structure)
- [Set up your development environment](#set-up-your-development-environment)
  - [Windows](#windows)
  - [Linux](#linux)
  - [macOS](#macos)
  - [Conda](#conda)
  - [VS Code, PyCharm, and WSL](#vs-code-pycharm-and-wsl)
- [Install dependencies](#install-dependencies)
- [Connect to Intellio](#connect-to-intellio)
- [Complete API reference](#complete-api-reference)
- [Examples](EXAMPLES.md)
- [Lightning compatibility note](#lightning-compatibility-note)
- [Troubleshooting](#troubleshooting)
- [Support and development](#support-and-development)
- [Terms of Use](#terms-of-use)

## Features

- BLE-assisted Wi-Fi configuration and automatic Intellio IP discovery.
- Live JPEG camera frames delivered to Python as OpenCV-compatible NumPy arrays.
- Hardware commands for onboard LED, motors, servos, speaker and audio, camera settings, and supported external sensors.
- Lightning extension commands for RGB strips and an 8x8 LED matrix.
- Integration with Python computer-vision libraries without running hand-tracking inference on the microcontroller.

## Requirements

**Hardware**

- Intellio board with compatible firmware.
- A Windows, Linux, or macOS computer with Bluetooth Low Energy and Wi-Fi.
- Intellio and the laptop connected to the appropriate network after BLE setup.
- Optional hardware for examples: ultrasonic/IR sensor, RGB LED matrix, OLED, supported color/motion sensors, or motors.

**Software**

- Python **3.9 or newer** for the SDK.
- A Python virtual environment or Conda environment.
- `tkinter` and a desktop session for the BLE setup window. The camera and vision demos also open graphical windows.
- `bleak`, `opencv-python`, and `numpy` are installed with the SDK.

The pip distribution is named `quarky-intellio`. Python code imports it as `Intellio`.

## Project structure

```text
Intellio_pip/
|-- Intellio/
|   |-- __init__.py
|   |-- camera.py         # QuarkyIntellio public hardware API
|   |-- ble.py            # BLE scanning and GATT communication
|   |-- ble_gui.py        # Connection manager
|   `-- stream.py         # JPEG-over-UDP camera receiver
|-- Examples/
|-- EXAMPLES.md
|-- pyproject.toml
`-- README.md
```

The [examples guide](EXAMPLES.md) contains the commands and code samples for the projects in this repository.

## Set up your development environment

Open a terminal in the repository root, where `pyproject.toml` is located. Choose one environment below, then continue to [Install dependencies](#install-dependencies).

### Windows

Install Python 3.12 with Tcl/Tk support. In PowerShell, create and activate the environment. [Python on Windows](https://docs.python.org/3.12/using/windows.html)

```powershell
py -3.12 -m venv air-env
.\air-env\Scripts\Activate.ps1
```

In Command Prompt, activate with `air-env\Scripts\activate.bat`. In Git Bash, use `source air-env/Scripts/activate`. If PowerShell blocks script activation, use Command Prompt or run `.\air-env\Scripts\python.exe` directly in place of `python` in the install and run commands below. [Python virtual environments](https://docs.python.org/3.12/library/venv.html)

### Linux

On **Ubuntu or Debian**, install Python, Tk, and the Bluetooth and networking tools. The commands below use the distribution's default Python. Check `python3 --version`, and use the Conda setup below if you need Python 3.12 for the vision examples. [Ubuntu Python packages](https://packages.ubuntu.com/noble/python3-tk) · [Ubuntu BlueZ package](https://packages.ubuntu.com/noble/bluez)

```bash
sudo apt update
sudo apt install python3 python3-venv python3-tk bluez iproute2 libgl1
python3 -m venv air-env
source air-env/bin/activate
```

On **Fedora**, install the equivalent system packages and create the environment. [Fedora Tkinter package](https://packages.fedoraproject.org/pkgs/python3.14/python3-tkinter/)

```bash
sudo dnf install python3 python3-pip python3-tkinter bluez iproute libglvnd-glx
python3 -m venv air-env
source air-env/bin/activate
```

For BLE setup, enable Bluetooth and check that `bluetoothctl show` lists an adapter. On a systemd desktop, start the Bluetooth service with `sudo systemctl start bluetooth` if it is stopped. Bleak uses BlueZ on Linux. [Bleak Linux backend](https://bleak.readthedocs.io/en/stable/backends/linux.html)

### macOS

Install Python 3.12 from python.org, then create a virtual environment from Terminal. If macOS asks for Bluetooth access, allow it for the app running Python. If access was denied, check **System Settings > Privacy & Security > Bluetooth**. [Python on macOS](https://docs.python.org/3.12/using/mac.html) · [Bleak macOS troubleshooting](https://bleak.readthedocs.io/en/stable/troubleshooting.html)

```bash
python3.12 -m venv air-env
source air-env/bin/activate
```

### Conda

From a shell initialized for Conda, create an environment with Python 3.12, pip, and Tk. On Linux, complete the system Bluetooth setup above before using the board. [Conda environment creation](https://docs.conda.io/projects/conda/en/stable/commands/create.html)

```bash
conda create -n air-env python=3.12 pip tk
conda activate air-env
```

### VS Code, PyCharm, and WSL

- **VS Code.** Open the repository, install the Python extension, and run **Python: Select Interpreter**. Choose the environment you created, then open a new integrated terminal. [VS Code Python environments](https://code.visualstudio.com/docs/python/environments)
- **PyCharm.** Open the repository and select your existing environment in the **Python Interpreter** settings. Set the run configuration's working directory to the repository root. [PyCharm interpreter setup](https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html)
- **WSL.** Use the Linux instructions for package development. For board tests, use native Windows unless WSL has access to a Bluetooth adapter, a graphical desktop, and incoming UDP traffic from the board. [WSL USB devices](https://learn.microsoft.com/en-us/windows/wsl/connect-usb) · [WSL networking](https://learn.microsoft.com/en-us/windows/wsl/networking)

## Install dependencies

With the environment active, confirm which Python you are using. Run `python -m tkinter` to verify that a small Tk window opens, then close it.

```bash
python --version
python -c "import sys; print(sys.executable)"
python -m tkinter
```

For SDK development, install from the repository in editable mode.

```bash
python -m pip install -e .
```

To install the latest release from PyPI, run `python -m pip install --upgrade quarky-intellio`. If you downloaded a wheel, run `python -m pip install <wheel-filename>` from the download directory, replacing `<wheel-filename>` with the actual filename.

Verify the SDK and its dependencies. Run the import from outside the repository if you want to confirm it resolves through your environment.

```bash
python -m pip check
python -c "from Intellio import QuarkyIntellio; print(QuarkyIntellio.__name__)"
```

## Connect to Intellio

1. Power on Intellio and enable Bluetooth and Wi-Fi on your laptop.
2. Run the [connection example](EXAMPLES.md#connect-to-intellio). `connect()` opens the Intellio BLE/Wi-Fi manager.
3. Scan for Intellio, select the board, and connect over Bluetooth.
4. Supply Wi-Fi credentials and choose **Station Mode** (through a router) or the compatible AP setup for your firmware.
5. Wait for the program to print a discovered Intellio IP address.
6. Close the connection-manager window to allow the script to continue. The existing implementation starts the camera-stream receiver automatically when the IP is discovered.

`connect()` **blocks while the Tkinter window is open**. You can also instantiate with a known IP, `QuarkyIntellio(ip="192.168.x.x")`, but that bypasses BLE discovery and does **not** automatically start the camera stream; call `startstream()` explicitly when using that approach.

### Communication used by the supplied implementation

| Channel | Purpose | Configuration in source |
|---|---|---|
| BLE | Device discovery and Wi-Fi provisioning | `ble.py` and `ble_gui.py` |
| UDP `5005` on PC | Incoming JPEG camera frames | `stream.py` |
| UDP `5006` on device | Outgoing PC hardware-control commands | `camera.py` |
| UDP `5007` on PC | Expected hardware-control replies | `camera.py` socket binding |

Port numbers describe the shared Python implementation. The actual board firmware and network must support the same transport for hardware commands to work.

## Complete API reference

All methods below are on an instance of `QuarkyIntellio`. Names and argument order match the shared `camera.py`; Python method names are case-sensitive. The class includes **54 public methods** in the supplied version, plus internal helpers documented at the end.

### Connection and video

| Method | Description / parameters |
|---|---|
| `QuarkyIntellio(ip=None)` | Create the client. Optional `ip` skips IP discovery but not the need for compatible Wi-Fi connectivity. |
| `connect()` | Open BLE/Wi-Fi manager; wait for window to close. IP notification also starts the stream in this source version. |
| `startstream()` | Start receiving camera frames on UDP 5005. |
| `get_frame()` | Return latest BGR OpenCV frame, or `None` while unavailable. |
| `stopstream()` | Stop the receiver and release its UDP port before returning. |

### Robot motors and servos

| Method | Description / parameters |
|---|---|
| `runrobot(direction, speed)` | Robot direction: `1` forward, `2` backward, `3` left, `4` right, `5` stop; speed `0-100` as documented in source. |
| `runbothmotors(left_speed, right_speed)` | Drive left/right motors at separate speed values. |
| `stoprobot()` | Stop robot motors. |
| `runmotor(motor, direction, speed)` | Motor `'L'` or `'R'`; direction `1` forward, `2` backward, `3` lock, `4` stop. |
| `stopmotor(motor)` | Stop one motor (`'L'` or `'R'`). |
| `setservo(pin, angle)` | Logical servo pin: `0=S1`, `1=A2`, `2=A1`; angle `0-180` degrees. |
| `servomoveintime(pin, angle, seconds)` | Move a servo to an angle over the requested duration. |

> Motor-control methods are documented from the Python implementation. Some mappings may require alignment with the specific firmware and expansion-board configuration; do not assume all have been hardware-verified.

### Built-in RGB LED

| Method | Description / parameters |
|---|---|
| `setled(r, g, b, brightness=30)` | Set Intellio's built-in RGB LED, with requested brightness. |
| `turnoffled()` | Turn off the built-in LED. |

### Lightning RGB strips and 8x8 LED matrix

| Method | Description / parameters |
|---|---|
| `initialisergb(strip, numled, pin)` | Initialize strip index (`1` is typical), number of LEDs (`64` for an 8x8 matrix), and firmware-expected pin identifier. Command `73`. |
| `setrgbpixel(strip, pixel, r, g, b)` | Set a **zero-based pixel index**; send `showrgb()` to apply it. Command `74`. |
| `showrgb(strip)` | Push pending pixel colors to the physical LEDs. Command `75`. |
| `showpattern1(pattern, strip, r, g, b, delay_ms)` | `1` Color Wipe, `2` Theater Chase. Delay in milliseconds. Command `76`. |
| `showpattern2(pattern, strip, delay_ms)` | `1` Rainbow, `2` Rainbow Cycle, `3` Theater Chase Rainbow. Delay in milliseconds. Command `77`. |
| `clearrgb(strip)` | Clear the strip/matrix. Command `78`. |

See the [RGB matrix example](EXAMPLES.md#initialize-the-lightning-rgb-matrix) and the [Lightning compatibility note](#lightning-compatibility-note).

### Ultrasonic and digital/analog sensors

| Method | Description / parameters |
|---|---|
| `setultrasonicpins(trig, echo)` | Assign distinct ports from `'A1'`, `'A2'`, `'S1'` to trigger and echo. Validates the names. |
| `getultrasonic()` | Read distance as a float from firmware. |
| `readdigital(pin)` | Read digital state `0` or `1`; uses GET action. |
| `prepare_ir_input(pin="A1")` | Prepare `A1`/`A2` for IR/digital input by switching PWM/analog state as required by this firmware. |
| `readanalog(pin)` | Read an analog value as float or `None`; source documents `'A1'`/`'A2'`. |
| `readpushbutton(button)` | Read left (`1`) or right (`2`) pushbutton as float or `None`. |

The ultrasonic and IR input paths were tested during development. Other sensor methods are included because they exist in `camera.py`; confirm action-code compatibility before release.

### Color and proximity sensor (APDS9960)

| Method | Description / parameters |
|---|---|
| `initcolorsensor()` | Initialize the attached color/proximity sensor; returns `True` only on exact `"Done"`. |
| `getlightlevel(channel=0)` | `0` clear, `1` red, `2` green, `3` blue channel; numeric result or `None`. |
| `iscolordetected(color)` | Check a firmware-defined color index; returns boolean. |
| `getproximity()` | Proximity value, documented `0-255`, or `None`. |
| `recordcolorprofile(slot)` | Save a color profile to slot `0-7`; returns boolean in this implementation. |
| `deleteallcolorprofiles()` | Clear recorded profiles; returns raw firmware response. |
| `iscolorprofiledetected(slot)` | Check whether a saved profile is detected; returns boolean. |
| `isgesturedetected(gesture)` | Sensor gesture indices: `0` none, `1` up, `2` down, `3` left, `4` right. Not the same as MediaPipe hand tracking. |

### Motion sensor (MPU6050)

| Method | Description / parameters |
|---|---|
| `initmotionsensor()` | Initialize supported motion sensor; returns boolean on exact `"Done"`. |
| `getacceleration(axis)` | Read acceleration, axis `0=X`, `1=Y`, `2=Z`; float or `None`. |
| `getgyroscope(axis)` | Read gyroscope value for axis `0=X`, `1=Y`, `2=Z`; float or `None`. |
| `gettiltangle(axis)` | Read tilt-angle value for axis `0=X`, `1=Y`, `2=Z`; float or `None`. |
| `gettemperature()` | Read sensor temperature in Celsius, or `None`. |

### OLED display

| Method | Description / parameters |
|---|---|
| `initoled()` | Request OLED initialization; returns boolean on exact `"Done"`. |
| `clearoled()` | Clear OLED display; returns boolean. |
| `displaytext(text)` | Display text; returns boolean. |
| `scrolltext(text)` | Scroll supplied text; returns boolean. |
| `displayemotion(emotion)` | Display a firmware-defined emotion index; returns boolean. |

**Status note:** OLED initialization was **not confirmed working** in the shared firmware. The device-side `advancesensorhandler()` section previously contained `_ensure_oled` without calling it, so a `Done` response does not prove that the display initialized. This cannot be fixed solely by documenting or calling `initoled()` from the PC. Avoid advertising OLED as tested until verified on the release firmware.

### Speaker and audio

| Method | Description / parameters |
|---|---|
| `playsound(filename, volume=80)` | Play a sound by filename available to the device/firmware. |
| `playsounduntildone(filename, volume=80)` | Play and wait for completion response; returns boolean based on `"done"`. |
| `stopsound()` | Stop currently playing device sound. |
| `setvolume(volume)` | Set speaker volume, documented `0-100` by source. |
| `playtone(frequency, duration_ms)` | Play a tone of the specified frequency (Hz) for the specified duration (milliseconds); validates positive values and waits for response. |

`playtone()` generates a tone, **not synthesized speech**. A file passed to `playsound()` must be accessible to the Intellio firmware; an arbitrary filename on the laptop is not automatically transferred to the device.

### Camera settings

| Method | Description / parameters |
|---|---|
| `setbrightness(value)` | Set camera brightness. Firmware defines the accepted range. |
| `setcontrast(value)` | Set contrast. Firmware defines the accepted range. |
| `setsaturation(value)` | Set saturation. Firmware defines the accepted range. |
| `setquality(value)` | Set camera JPEG quality setting. Firmware defines the accepted range. |
| `setvflip(value)` | Enable/disable vertical flip (commonly `0`/`1`). |
| `sethmirror(value)` | Enable/disable horizontal mirroring (commonly `0`/`1`). |

### Internal methods (not part of the recommended public API)

| Method | Role |
|---|---|
| `_send(*args, action=2, timeout=None)` | Build a `frame/{action}/...` command, send via UDP `5006`, and await response on the client's UDP socket. |
| `_rgb_request(command, *args)` | Lightning transport helper; special handling described below. |
| `_send_sensor(*args)` | Wrap hardware command `215` for advanced sensors. |
| `_send_setting(*args)` | Send `setting/...` commands to the device. |
| `_set_ip(ip)` | Validate/set the discovered IP; starts the camera receiver on discovery. |

**Other implementation components:**

- `BLEManager` (`ble.py`): `scan()`, `connect(address)`, `disconnect()`, `send(data)`, `start_notify(callback)`, and `is_connected`. These are asynchronous BLE utilities used by the connection manager.
- `BLEApp` (`ble_gui.py`): Tkinter UI for scanning, connecting, provisioning Wi-Fi, and forwarding an IP notification to `QuarkyIntellio`.
- `CameraStream` (`stream.py`): `start()`, `stop()`, and `get_frame()`; background `_receiver()` assembles JPEG data packets into decoded OpenCV frames.

## Lightning compatibility note

**The hardware-tested development setup required a send-only Lightning request.** The earlier uploaded `camera.py` source used the regular request-response helper and raised `WinError 10054` during RGB initialization. In a later local test, replacing `_rgb_request()` with a send-only command sender allowed the LED matrix to work. Ultrasonic and IR should continue using the original `_send()` request-response path.

See the [send-only implementation](EXAMPLES.md#lightning-send-only-workaround) for older checkouts. This approach confirms that the SDK sent the command. Firmware execution remains unconfirmed.

Avoid calling long-running Rainbow patterns continuously in a live camera loop: pattern execution may block firmware control, and repeated calls can cause sluggish video or lost device commands. Prefer short Color Wipe updates triggered only by **confirmed gesture changes**.

## Troubleshooting

| Symptom | What to check |
|---|---|
| `ModuleNotFoundError: No module named 'Intellio'` | Install the SDK in the same environment that runs your script and use the exact capitalization `Intellio`. |
| `No module named 'mediapipe'`, `cv2`, or `bleak` | Activate the intended `air-env`, then install the missing package with `python -m pip`. |
| `No module named 'tkinter'` or the Tk window cannot open | Run `python -m tkinter` and check the Tk installation and desktop session for your platform. |
| Linux cannot find a Bluetooth adapter | Check `bluetoothctl show`, the BlueZ service, and Bluetooth access in the environment running Python. |
| Connection manager opens but no IP appears | Check BLE connection, Wi-Fi credentials, compatible Station/AP mode, laptop network, and notifications. |
| `get_frame()` returns `None` | Wait for camera stream, check network and UDP `5005`, and ensure only one program owns the receiver port. |
| `[WinError 10054]` during hardware command | Check the board's UDP control service, correct device IP/port, and firmware; the camera stream can work independently of hardware commands. |
| Ultrasonic/IR works but Lightning errors | Check whether the repo uses the tested send-only `_rgb_request()`; leave general `_send()` unchanged. |
| Lightning command prints `SENT_UNCONFIRMED` but nothing lights | Confirm firmware/device receives command, strip initialization, pin mapping, LED type, power supply, data connection, and shared ground. |
| Rainbow animation appears stuck | Animation can be long or blocking; use shorter effects and avoid repeated requests. |
| OLED reports `False` | Check board firmware's OLED initialization implementation and hardware wiring; a PC-only change may not resolve it. |
| Video freezes while playing audio | Avoid blocking speaker commands on the frame-processing thread; serialize device commands in a worker. |
| `Address already in use` on UDP `5005`/`5007` | Close duplicate Python scripts or other processes holding those ports. |


## Support and development

For board questions, see the [Quarky Intellio documentation](https://ai.thestempedia.com/docs/quarky-intellio/) or contact [STEMpedia support](https://thestempedia.com/contact/).

In a repository checkout or unpacked source archive, see the [changelog](CHANGELOG.md), [contribution guide](CONTRIBUTING.md), and [security reporting instructions](SECURITY.md).

## Terms of Use

These conditions apply to use of the Intellio Python SDK and its example projects.

- Use the SDK for lawful purposes. Connect only to boards and networks you own or have permission to use.
- Follow the hardware instructions and test scripts in a controlled environment before enabling motors, servos, or other attachments. Do not rely on the SDK or example projects for safety-critical decisions or emergency alerts.
- Respect the privacy of people within the camera's view. Obtain any required permissions before recording, storing, or sharing images, video, or biometric data.
- Follow any licenses supplied with the SDK, third-party libraries, and example assets.

For Agilo Research Pvt Ltd's published terms and privacy information, see the [STEMpedia Terms and Conditions](https://thestempedia.com/terms-and-conditions/) and [Privacy Policy](https://thestempedia.com/privacy-policy/).
