Metadata-Version: 2.4
Name: heicon
Version: 1.0.0
Summary: Python SDK for Heicon modular hardware system
Home-page: https://github.com/yourname/heicon-sdk
Author: Heicon Project
Author-email: 
License: MIT
Project-URL: Homepage, https://github.com/heiju233/HeiconSDK
Project-URL: Documentation, https://github.com/heiju233/HeiconSDK#readme
Project-URL: Repository, https://github.com/heiju233/HeiconSDK.git
Project-URL: Issues, https://github.com/heiju233/HeiconSDK/issues
Project-URL: Hardware, https://github.com/heiju233/Heicon
Keywords: heicon,raspberry-pi,iot,hardware,embedded,i2c,spi,uart,gpio,esp32,robotics
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: System :: Hardware
Classifier: Topic :: Software Development :: Embedded Systems
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyserial>=3.5
Provides-Extra: rpi
Requires-Dist: RPi.GPIO>=0.7.0; extra == "rpi"
Requires-Dist: smbus>=1.1; extra == "rpi"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: black>=22.0; extra == "dev"
Requires-Dist: flake8>=4.0; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# Heicon SDK

Python library and firmware for Heicon modular hardware system.

## Installation

```bash
pip install heicon
```

Or from source:
```bash
git clone https://github.com/yourname/heicon-sdk.git
cd heicon-sdk
pip install -e .
```

## Quick Start

```python
from heicon import IMU, Motor, Relay, RS485, Master

# Read IMU
imu = IMU()
accel = imu.read_accel()
print(f"Acceleration: {accel}")

# Control motors
with Motor('/dev/ttyS0') as motor:
    motor.forward(50)
    time.sleep(1)
    motor.stop()

# Toggle relay
relay = Relay()
relay.on(1)
relay.off(1)

# RS485 communication
with RS485() as rs:
    rs.send("Hello RS485")
    response = rs.readline()

# Master board
with Master() as master:
    master.wifi_connect("SSID", "password")
    devices = master.i2c_scan()
```

## CLI Tool

```bash
# Scan I2C bus
heicon scan

# Read IMU continuously
heicon imu read -c

# Control motors
heicon motor set 50 50
heicon motor stop

# Control relays
heicon relay on 1
heicon relay off 1

# RS485
heicon rs485 send "Hello" -w

# Master board
heicon master ping
heicon master wifi connect MySSID MyPassword
```

## Modules

### IMU (MPU6050)

```python
from heicon import IMU

imu = IMU(bus=1, address=0x68)

# Set ranges
imu.set_accel_range(4)   # ±4g
imu.set_gyro_range(500)  # ±500°/s

# Read data
accel = imu.read_accel()  # (x, y, z) in g
gyro = imu.read_gyro()    # (x, y, z) in °/s
temp = imu.read_temp()    # °C

# Read all at once
data = imu.read_all()
# {'accel': (x,y,z), 'gyro': (x,y,z), 'temp': t}

# Calibrate (device must be still)
offsets = imu.calibrate(samples=100)
```

### Motor (ESP32-C3 + TB6612)

```python
from heicon import Motor

motor = Motor('/dev/ttyS0', baudrate=115200)

# Basic control
motor.set_speed(50, 50)   # -100 to 100
motor.stop()
motor.brake()

# Convenience methods
motor.forward(50)
motor.backward(50)
motor.turn_left(50)
motor.turn_right(50)
motor.curve_left(50, ratio=0.5)

# WiFi (via ESP32)
motor.wifi_connect("SSID", "password")
print(motor.wifi_ip())

motor.close()
```

### Relay (4-channel)

```python
from heicon import Relay

relay = Relay()

# Control individual relays (1-4)
relay.on(1)
relay.off(1)
relay.toggle(2)
relay.pulse(3, duration=0.5)

# Control all
relay.all_on()
relay.all_off()

# Check state
state = relay.get_state(1)  # True/False
states = relay.get_state()  # {1: T/F, 2: T/F, ...}

relay.cleanup()
```

### RS485 (MAX485)

```python
from heicon import RS485

rs = RS485('/dev/ttyS0', baudrate=9600)

# Basic communication
rs.send(b"Hello")
rs.send("Hello")  # Auto-encodes
response = rs.receive(10)
line = rs.readline()

# Query (send + wait + receive)
response = rs.query("CMD", delay=0.1)

# Modbus RTU
data = rs.modbus_read_holding(address=1, register=0, count=2)
rs.modbus_write_single(address=1, register=0, value=100)

rs.close()
```

### RS232 (MAX3232)

```python
from heicon import RS232

rs = RS232('/dev/ttyS0', baudrate=9600)

rs.send("Hello")
rs.sendline("Hello")  # With newline
response = rs.readline()

rs.close()
```

### Master (ESP32-S3)

```python
from heicon import Master

master = Master('/dev/ttyS0')

# System
master.ping()
master.version()
master.info()  # Returns JSON
master.reset()

# WiFi
master.wifi_scan()
master.wifi_connect("SSID", "password")
master.wifi_status()
master.wifi_ip()
master.wifi_ap("HeIconAP", "password")  # Start AP

# BLE
master.ble_name("MyDevice")
master.ble_advertise(True)

# I2C relay
devices = master.i2c_scan()
data = master.i2c_read(0x68, 0x3B, 6)
master.i2c_write(0x68, 0x6B, b'\x00')

# GPIO
master.gpio_mode(5, 'OUTPUT')
master.gpio_write(5, True)
state = master.gpio_read(5)

# MQTT
master.mqtt_connect("broker.mqtt.com", 1883)
master.mqtt_publish("topic", "message")
master.mqtt_subscribe("topic")

# OTA
master.ota_update("http://server/firmware.bin")

master.close()
```

## Firmware

ESP32 Arduino firmware is in the `firmware/` directory:

- `firmware/motor/motor.ino` - Motor board (ESP32-C3)
- `firmware/master/master.ino` - Master board (ESP32-S3)

### Building Firmware

1. Install Arduino IDE
2. Add ESP32 board support
3. Install libraries: `PubSubClient`, `ArduinoJson`
4. Open `.ino` file and upload

## Hardware

See [heicon](https://github.com/yourname/heicon) repository for PCB designs.

## License

MIT License
