import machine
import dht
import time
from machine import Pin, I2C
import BME280
import onewire
import ds18x20


# DHT22 setup
dht_pin = machine.Pin(2)
dht_sensor = dht.DHT22(dht_pin)

# BME280 setup
i2c = I2C(0, scl=Pin(17), sda=Pin(16), freq=400000)
try:
    bme = BME280.BME280(i2c=i2c)
except OSError as e:
    print(f"Error initializing BME280: {e}")
    import sys
    sys.exit(1)

# DS18B20 setup
ds_pin = machine.Pin(22)
ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))
roms = ds_sensor.scan()
print('Found DS devices:', roms)


while True:
    # --- DHT22 Readings ---
    try:
        dht_sensor.measure()
        temp_dht = dht_sensor.temperature()
        hum_dht = dht_sensor.humidity()

        print("DHT22 Readings:")
        print(f"  Temperature: {temp_dht:.2f} °C")
        print(f"  Humidity: {hum_dht:.2f} %")

    except OSError as e:
        print("Error reading DHT22:", e)

    # --- BME280 Readings ---
    try:
        temp_bme = bme.temperature
        hum_bme = bme.humidity
        pres_bme = bme.pressure

        print("\nBME280 Readings:")
        print(f"  Temperature: {temp_bme}")
        print(f"  Humidity: {hum_bme}")
        print(f"  Pressure: {pres_bme}")

    except OSError as e:
        print("Error reading BME280:", e)

    # --- DS18B20 Readings ---
    try:
        ds_sensor.convert_temp()
        time.sleep_ms(750)  # Wait for conversion

        print("\nDS18B20 Readings:")
        for rom in roms:
            tempC_ds = ds_sensor.read_temp(rom)
            print(f"  Sensor ROM: {rom}")
            print(f"  Temperature (ºC): {tempC_ds:.2f} °C")


    except Exception as e:
        print("Error reading DS18B20:", e)


    print("-" * 20)
    time.sleep(2)

combine with this code

import machine
import time
import neopixel

# ADC pin connected to the sensor's SIG pin
adc_pin = machine.ADC(26)

# Calibration (CRITICAL - determine these experimentally)
V_REF = 3.3
UV_MAX = 10.0
SENSOR_MAX_VOLTAGE = 1

# NeoPixel configuration
NEOPIXEL_PIN = 6
NUM_PIXELS = 8
np = neopixel.NeoPixel(machine.Pin(NEOPIXEL_PIN), NUM_PIXELS)

def set_neopixels(color):
    """Set all NeoPixels to a specific color."""
    for i in range(NUM_PIXELS):
        np[i] = color
    np.write()

def read_uv_index():
    """Reads and calculates the UV index."""
    adc_value = adc_pin.read_u16()
    voltage = (adc_value * V_REF) / 65535
    uv_index = (voltage / SENSOR_MAX_VOLTAGE) * UV_MAX
    return uv_index

def uv_risk_level(uv_index):
    if uv_index < 3:
        return "Low"
    elif uv_index < 6:
        return "Moderate"
    elif uv_index < 8:
        return "High"
    elif uv_index < 11:
        return "Very High"
    else:
        return "Extreme"

def get_color_based_on_uv(uv):
    if uv > 0.3:
        return (0, 0, 255)    # Blue
    elif uv > 0.15:
        return (0, 255, 0)    # Green
    elif uv > 0.09:
        return (255, 255, 0)  # Yellow
    elif uv > 0.06:
        return (255, 165, 0)  # Orange
    else:
        return (255, 0, 0)    # Red
        
while True:
    try:
        uv = read_uv_index()
        risk = uv_risk_level(uv)
        color = get_color_based_on_uv(uv)
        set_neopixels(color)
        print(f"UV Index: {uv:.2f}, Risk Level: {risk}")
    except Exception as e:
        print(f"Error: {e}")
        set_neopixels((255, 0, 0))  # Indicate error with Red
    time.sleep(1)

make the neopixel indicate both uv and temp with 4 led read uv and another 4 led read temp