ADS1115 ADC Web Panel, REST API, WebSocket API and CLI for Raspberry Pi
Project description
ADS1115 REST API, CLI & Web Panel for Raspberry Pi
Complete solution for controlling the ADS1115 16-bit ADC on Raspberry Pi using adafruit-circuitpython-ads1x15 library.
Features:
- ๐ Web Panel - Modern web interface with live data, I2C scanner, and configuration
- ๐ REST API - FastAPI-based HTTP API for programmatic access
- ๐ป CLI Shell - Interactive command-line interface with logging
- ๐ I2C Detection - Automatic I2C bus scanning and device detection
- ๐ณ Docker Support - Run in containers with mock/real hardware modes
- โ๏ธ Configuration - YAML, .env, and environment variable support
๐ Quick Start
Option 1: Raspberry Pi Native (Recommended for hardware)
# Copy files to RPi, then:
sudo ./install_rpi.sh
# Access web panel
http://raspberrypi.local:8080
Option 2: Docker with Mock Data (Testing/Development)
# Start web panel
docker-compose up web
# Access at http://localhost:8080
Option 3: Native Python
pip install -r requirements.txt
python web_panel.py # Web panel with I2C scanner
python api.py # REST API only
python cli.py --help # CLI commands
๐ File Structure
.
โโโ api.py # FastAPI REST API
โโโ web_panel.py # Web panel with I2C scanner
โโโ cli.py # Click CLI application
โโโ ads1115_service.py # Service layer
โโโ config.py # Configuration management
โโโ run.py # Launcher script
โโโ install_rpi.sh # RPi auto-installer
โโโ RPI_INSTALL.md # Detailed RPi installation guide
โโโ requirements.txt # Python dependencies
โโโ Dockerfile # Docker image
โโโ docker-compose.yml # Docker Compose (uses .env)
โโโ .env # Environment configuration
โโโ .env.example # Environment template
โโโ config.yaml # YAML configuration
โโโ README.md # This file
๐ Web Panel
Features
- I2C Scanner - Detect all devices on I2C bus
- ADC Readings - Read all 4 channels with voltage
- Live Mode - Continuous streaming
- Configuration - Change I2C address, gain, data rate
- Status Monitor - Hardware connection status
Web Panel Endpoints
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Web panel interface |
/api/health |
GET | Service health |
/api/i2c/scan |
GET | Scan I2C bus |
/api/config |
GET/POST | Configuration |
/api/read/all |
GET | Read all 4 channels |
/api/read/{channel} |
GET | Read single channel |
/ws |
WebSocket | Live streaming |
Access at: http://raspberrypi.local:8080
๐ REST API
Endpoints
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health status |
/config |
GET/POST | Configuration |
/read/{channel} |
GET | Read channel (0-3) |
/read/all |
GET | Read all channels |
Example Requests
# Scan I2C bus
curl http://localhost:8080/api/i2c/scan
# Read all channels
curl http://localhost:8080/api/read/all
# Update configuration
curl -X POST -H "Content-Type: application/json" \
-d '{"gain": 2, "data_rate": 250}' \
http://localhost:8080/api/config
API Documentation
Interactive docs available when running:
- Swagger UI: http://localhost:8080/docs
- ReDoc: http://localhost:8080/redoc
๐ป CLI Usage
Commands
# Device status
python cli.py status
# Read single channel
python cli.py read 0
python cli.py read 0 --continuous
# Read all channels
python cli.py readall
python cli.py readall --continuous --count 10
# Log to file
python cli.py log --output data.csv --interval 1
# Update config
python cli.py config --gain 2 --data-rate 250
๐ง Configuration
.env File (Recommended)
# I2C Settings
ADS1115_I2C_ADDRESS=0x48
ADS1115_GAIN=1.0
ADS1115_DATA_RATE=128
ADS1115_MODE=single
ADS1115_MOCK=false # 'true' for testing
# API Settings
API_HOST=0.0.0.0
API_PORT=8080
# RPi Network
RPI_IP=192.168.188.212
Environment Variables
| Variable | Description | Default |
|---|---|---|
ADS1115_I2C_ADDRESS |
I2C address | 0x48 |
ADS1115_GAIN |
ADC gain | 1.0 |
ADS1115_DATA_RATE |
Samples per second | 128 |
ADS1115_MOCK |
Mock mode | false |
API_HOST |
Bind address | 0.0.0.0 |
API_PORT |
Port | 8080 |
๐ณ Docker Usage
Using docker-compose
# Start web panel
docker-compose up web
# Start API
docker-compose up api
# Run CLI command
docker-compose run cli python cli.py status
Manual Docker
# Build image
docker build -t ads1115 .
# Run with mock data
docker run -p 8080:8080 -e ADS1115_MOCK=true ads1115 python web_panel.py
# Run on RPi with hardware
docker run -p 8080:8080 --device /dev/i2c-1 ads1115 python web_panel.py
๐ Raspberry Pi Installation
Automated Installation
# Copy to RPi
scp -r ./* pi@raspberrypi.local:~/ads1115/
# SSH to RPi and install
ssh pi@raspberrypi.local
cd ~/ads1115
sudo ./install_rpi.sh
Hardware Wiring
ADS1115 Raspberry Pi
-------- ------------
VDD -> 3.3V (Pin 1)
GND -> GND (Pin 6)
SCL -> SCL (Pin 5)
SDA -> SDA (Pin 3)
ADDR -> GND (address 0x48)
Service Management
# Check status
sudo systemctl status ads1115-web
# Control service
sudo systemctl start ads1115-web
sudo systemctl stop ads1115-web
sudo systemctl restart ads1115-web
# View logs
sudo journalctl -u ads1115-web -f
๐ API Response Format
I2C Scan Result
{
"bus": 1,
"devices": [
{"address": "0x48", "description": "ADS1115", "detected": true}
],
"ads1115_detected": true,
"ads1115_address": "0x48"
}
Channel Readings
{
"channels": [
{"channel": 0, "raw_value": 8452, "voltage": 1.0565, "gain": 1.0},
{"channel": 1, "raw_value": 9234, "voltage": 1.1543, "gain": 1.0},
{"channel": 2, "raw_value": 7500, "voltage": 0.9375, "gain": 1.0},
{"channel": 3, "raw_value": 6200, "voltage": 0.7750, "gain": 1.0}
],
"mock_mode": false,
"i2c_address": "0x48"
}
๐ Hardware Specifications
- Chip: ADS1115 16-bit ADC
- Interface: I2C (addresses: 0x48, 0x49, 0x4A, 0x4B)
- Channels: 4 single-ended or 2 differential
- Data Rate: 8 - 860 SPS
- Gain: 2/3, 1, 2, 4, 8, 16
I2C Addresses
| ADDR Pin | Address |
|---|---|
| GND | 0x48 |
| VDD | 0x49 |
| SDA | 0x4A |
| SCL | 0x4B |
Gain Settings
| Gain | Voltage Range |
|---|---|
| 2/3 | ยฑ6.144V |
| 1 | ยฑ4.096V |
| 2 | ยฑ2.048V |
| 4 | ยฑ1.024V |
| 8 | ยฑ0.512V |
| 16 | ยฑ0.256V |
๐ ๏ธ Troubleshooting
I2C Permission Denied
sudo usermod -a -G i2c pi
newgrp i2c
Enable I2C Manually
sudo raspi-config
# Interface Options -> I2C -> Enable
# Or edit config
sudo nano /boot/firmware/config.txt
# Add: dtparam=i2c_arm=on
sudo reboot
Check Logs
# Native installation
sudo journalctl -u ads1115-web -f
# Docker
docker-compose logs -f web
๐ Links
- This README
- RPI_INSTALL.md - Detailed RPi installation
- API docs: http://localhost:8080/docs
- Web panel: http://localhost:8080
Made for Raspberry Pi with โค๏ธ
License
Apache License 2.0 - see LICENSE for details.
Author
Created by Tom Sapletta - tom@sapletta.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file piadc-1.0.1.tar.gz.
File metadata
- Download URL: piadc-1.0.1.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c667a035eef27a133db7510a5a3f08c6d0ddb18aa571c3e945dfc45fb1202dd3
|
|
| MD5 |
b9dbcd4d63d87592e3568c28dab65f3d
|
|
| BLAKE2b-256 |
8dcc188f932a81abd34ff43280600d49ab2f66b50d7b0ac3a6a22f44db58892d
|
File details
Details for the file piadc-1.0.1-py3-none-any.whl.
File metadata
- Download URL: piadc-1.0.1-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a13b07a6315ce00818a5cccf6dab9d1f1a77c55b341502c8888e3397dfd1da4
|
|
| MD5 |
a455238d762a92630795d169610b9be0
|
|
| BLAKE2b-256 |
75e36590a33b4d80ff1b675a2df6af623e3e8ddcc0503d368d96b4a08e7d1464
|