circuitpython-deploy 0.1.2

Fast, reliable CircuitPython project deployment tool
Documentation
# Sensor Dashboard Example

A comprehensive CircuitPython project that reads temperature and light sensors and displays the data on screen. This example demonstrates advanced project organization, error handling, and configuration management.

## ๐Ÿ”ง Hardware Required

- CircuitPython board with display (e.g., Adafruit PyPortal, Matrix Portal, or board + separate display)
- TMP36 temperature sensor (or similar analog temperature sensor)
- Photoresistor and 10kฮฉ resistor (for light sensing)
- Breadboard and jumper wires

## ๐Ÿ”Œ Wiring

```
Temperature Sensor (TMP36):
- VCC โ†’ 3.3V
- GND โ†’ GND  
- OUT โ†’ A0

Light Sensor (Photoresistor):
- One leg โ†’ 3.3V
- Other leg โ†’ A1 and one leg of 10kฮฉ resistor
- Other leg of 10kฮฉ resistor โ†’ GND
```

## ๐Ÿš€ Quick Start

1. **Wire up your sensors** according to the diagram above
2. **Deploy the project:**
   ```bash
   cd examples/sensor-dashboard
   cpd --verbose
   ```
3. **Watch the dashboard update** with live sensor readings!

## ๐Ÿ“ Project Structure

```
sensor-dashboard/
โ”œโ”€โ”€ code.py                 # Main application
โ”œโ”€โ”€ config.py              # Configuration settings
โ”œโ”€โ”€ lib/                   # Custom libraries
โ”‚   โ”œโ”€โ”€ sensors.py         # Sensor reading classes
โ”‚   โ””โ”€โ”€ display_manager.py # Display management
โ”œโ”€โ”€ .cpdignore            # Deployment exclusions
โ””โ”€โ”€ README.md             # This file (not deployed)
```

## โš™๏ธ Configuration

Edit `config.py` to customize:

```python
CONFIG = {
    'update_interval': 2.0,        # Seconds between readings
    'temperature_unit': 'celsius', # 'celsius' or 'fahrenheit'
    'brightness': 0.8,             # Display brightness
    'temp_offset': 0.0,            # Temperature calibration
}
```

## ๐Ÿ“Š Features

- **Real-time sensor readings** updated every 2 seconds
- **Temperature display** in Celsius or Fahrenheit
- **Light level percentage** from photoresistor
- **Error handling** with on-screen error messages
- **Status display** showing system state
- **Modular code** organized into libraries
- **Configurable settings** for easy customization

## ๐Ÿงช Testing Deployment

```bash
# Preview what will be deployed
cpd --dry-run --verbose

# Deploy with backup (recommended for first time)
cpd --backup ./backup

# Quick deployment during development
cpd --yes
```

## ๐Ÿ“– Code Organization

### Main Application (`code.py`)
- Initializes hardware and display
- Main sensor reading loop
- Error handling and recovery

### Configuration (`config.py`)
- Centralized settings
- Pin assignments
- Display layout configuration

### Sensor Library (`lib/sensors.py`)
- `TemperatureSensor` class for analog temperature reading
- `LightSensor` class for photoresistor readings
- `StatusLED` class for visual feedback

### Display Manager (`lib/display_manager.py`)
- Screen layout management
- Text label updates
- Error message display

## ๐Ÿ”ง Customization

### Adding New Sensors

1. **Add sensor class to `lib/sensors.py`:**
   ```python
   class HumiditySensor:
       def __init__(self, pin):
           # Sensor initialization
       
       def read_percent(self):
           # Reading logic
   ```

2. **Update display in `lib/display_manager.py`**
3. **Modify main loop in `code.py`**

### Changing Pin Assignments

Edit the `SENSOR_PINS` section in `config.py`:

```python
SENSOR_PINS = {
    'temperature': 'A2',  # Changed from A0
    'light': 'A3',        # Changed from A1
    'led': 'D13',
}
```

### Customizing Display Layout

Modify `DISPLAY_LAYOUT` in `config.py`:

```python
DISPLAY_LAYOUT = {
    'title_y': 10,
    'temp_y': 40,
    'light_y': 70,
    'status_y': 100,
    'margin_x': 10,
}
```

## ๐Ÿ› Troubleshooting

### No Sensor Readings
- Check wiring connections
- Verify sensors are getting power
- Test with multimeter if available

### Display Issues
- Ensure board has built-in display or display is connected
- Check `board.DISPLAY` is available
- Verify display library imports

### Deployment Issues
- Run `cpd --list-boards` to verify board detection
- Check that required libraries are available
- Use `cpd --verbose --dry-run` to see what will be deployed

### Temperature Readings Seem Wrong
- Adjust `temp_offset` in config.py
- Verify TMP36 wiring (curved side facing you: +3.3V, signal, GND)
- Check if sensor needs different conversion formula

### Light Readings Not Changing
- Verify photoresistor and resistor values
- Check voltage divider wiring
- Adjust `light_calibration` in config.py

## ๐Ÿ“ˆ Expected Output

Serial monitor should show:
```
Sensors initialized successfully
Starting sensor dashboard...
Temp: 23.5ยฐC (74.3ยฐF), Light: 45%
Temp: 23.7ยฐC (74.7ยฐF), Light: 43%
Temp: 23.6ยฐC (74.5ยฐF), Light: 47%
```

Display should show:
```
Sensor Dashboard
Temp: 23.6ยฐC
Light: 47%
Running
```

## โžก๏ธ Next Steps

- Try the [WiFi Weather Station]../wifi-weather/ example
- Add data logging to a file
- Implement sensor alerts/thresholds
- Add network connectivity for remote monitoring
- Create custom sensor calibration routines

## ๐Ÿ”— Related Libraries

This example uses several CircuitPython libraries:
- `adafruit_display_text` - Text rendering
- `displayio` - Display management
- Built-in `analogio` - Analog sensor reading

Make sure these are installed on your board via `circup` or manual installation.