Traveling in Blanquillo AND MORE
  • Home
  • Trips
    • 2022 >
      • 2022 Tennessee
      • 2022 Blue Ridge Parkway
    • 2021
    • 2020 >
      • 2020 Sierras
    • 2019 >
      • 2019 Crater Lake
      • 2019 Westside Regional Park
    • 2018 >
      • 2018 So.California
      • 2018 Colorado-Arizona
      • 2018 Banff-Jasper
      • 2018 Osoyoos, BC
    • 2017 >
      • 2017 Olympic
      • 2017 Channel Islands
      • 2017 Eclipse
    • 2016 >
      • 2016 Glacier-Yellowstone
      • 2016 Southwest
    • 2015 >
      • 2015 Bryce-Zion
      • 2015 Lava Beds
      • 2015 Bristlecone-Yosemite
      • 2015 July first trip
    • 2014 >
      • 2014 Utah
    • 2011 >
      • Gold Beach
  • Camping Map
  • Our Escape
  • Radio and Hobbies
    • Amateur Radio Commentary >
      • AREDN
      • Antenna on mast
      • Winlink
    • Christmas LED Display
    • Scripts for Growing Classes >
      • 12- WeatherFIles
      • 11- sketch_MorseCodeDecoder.ino
      • 2e-RGB-LED
      • 2f-RGB-LED-GUI
      • 2g-RGB-LED-GUI
      • 3a-thermometer.py
      • 3b-thermometer-plus
      • 4a_DHT_simpletest.py
      • 4b_DHT_send_temperature.py
      • 4c_DHT_send_temperature_LED.py
      • 4c_DHT_send_temp.service
      • 4d_DHT_send_temp_LED_OLED.py
    • Winlink for Field Day 2020
    • VE Credentials
    • Antenna Analyzer Code
  • Collegedale Tax Prep
  • Links
  • Contact
  • Home
  • Trips
    • 2022 >
      • 2022 Tennessee
      • 2022 Blue Ridge Parkway
    • 2021
    • 2020 >
      • 2020 Sierras
    • 2019 >
      • 2019 Crater Lake
      • 2019 Westside Regional Park
    • 2018 >
      • 2018 So.California
      • 2018 Colorado-Arizona
      • 2018 Banff-Jasper
      • 2018 Osoyoos, BC
    • 2017 >
      • 2017 Olympic
      • 2017 Channel Islands
      • 2017 Eclipse
    • 2016 >
      • 2016 Glacier-Yellowstone
      • 2016 Southwest
    • 2015 >
      • 2015 Bryce-Zion
      • 2015 Lava Beds
      • 2015 Bristlecone-Yosemite
      • 2015 July first trip
    • 2014 >
      • 2014 Utah
    • 2011 >
      • Gold Beach
  • Camping Map
  • Our Escape
  • Radio and Hobbies
    • Amateur Radio Commentary >
      • AREDN
      • Antenna on mast
      • Winlink
    • Christmas LED Display
    • Scripts for Growing Classes >
      • 12- WeatherFIles
      • 11- sketch_MorseCodeDecoder.ino
      • 2e-RGB-LED
      • 2f-RGB-LED-GUI
      • 2g-RGB-LED-GUI
      • 3a-thermometer.py
      • 3b-thermometer-plus
      • 4a_DHT_simpletest.py
      • 4b_DHT_send_temperature.py
      • 4c_DHT_send_temperature_LED.py
      • 4c_DHT_send_temp.service
      • 4d_DHT_send_temp_LED_OLED.py
    • Winlink for Field Day 2020
    • VE Credentials
    • Antenna Analyzer Code
  • Collegedale Tax Prep
  • Links
  • Contact
​#4d_send_temp_LED_OLED.py
# get temperature from DHT22 and send to an Adafruit IO feed
# blink LED when data sent to Adafruit
# display temperature on OLED
# Import standard python modules
import os, sys, time
from datetime import datetime, date
import Adafruit_DHT
from gpiozero import LED

# import Adafruit IO REST client
from Adafruit_IO import Client
# Initialize the DHT device, with data pin connected to:
sensor = Adafruit_DHT.DHT22
pin = 18
green=LED(23)

# set up display
from luma.core.interface.serial import i2c, spi
from luma.core.render import canvas
from luma.oled.device import sh1106
from PIL import ImageFont
# GND Pin 6
# VCC Pin 1
# SCL Pin 5
# SDA Pin 3
try :
    serial = i2c(port=1, address=0x3C)
    # substitute ssd1331(...) or sh1106(...) below if using that device
    device = sh1106(serial)
except:
    print ('no i2c device')
    pass


# Delay between sensor reads, in seconds
DELAY_SECONDS = 300

# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
ADAFRUIT_IO_KEY = 'ADAFRUIT_IO_KEY'

# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username)
ADAFRUIT_IO_USERNAME = 'ADAFRUIT_IO_USERNAME'

# Create an instance of the REST client
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

# Set up `temperature and humidity` feed
pi_temperature = aio.feeds('temperature')
pi_humidity = aio.feeds('humidity')

print ("Ignoring first 2 sensor values to improve quality...")
for x in range(2):
  Adafruit_DHT.read_retry(sensor, pin)

while True:
    try:
        # Print the values to the serial port
        #temperature_c = dhtDevice.temperature
        humidity, temperature_c = Adafruit_DHT.read_retry(sensor, pin)
        temperature_f = temperature_c * (9 / 5) + 32
        #humidity = dhtDevice.humidity
        #print(
        #    "Temp: {:.1f} F / {:.1f} C    Humidity: {:.1f}% ".format(
        #        temperature_f, temperature_c, humidity
        #    )
        #)
        aio.send(pi_temperature.key, temperature_f)
        aio.send(pi_humidity.key, humidity)
        for x in range(1,3):
            green.on()
            time.sleep(1)
            green.off()
            time.sleep(1)
        timenow = time.strftime("%a, %b %d, %Y %I:%M:%S %p") # for print when value changes
        now = datetime.now() # for clock display
        today_date = now.strftime("%d %b %y")
        today_time = now.strftime("%H:%M:%S")

        try :
            # Display temp on OLED
            # use custom font
            #font = ImageFont.truetype('C&C Red Alert [INET].ttf', 40)
            font = ImageFont.truetype('code2000.ttf', 40)
            with canvas(device) as draw:
              margin = 4
              cx = 30
              cy = min(device.height, 64) / 2
              draw.text(((cx), 0), str(round(temperature_f))+'\u00b0F', fill="yellow", font=font)
              draw.text(((cx + margin), cy + 8), today_date, fill="yellow")
              draw.text(((cx + margin), cy + 16), today_time, fill="yellow")
        except :
            print ('image pass')
            pass
        
    except RuntimeError as error:
        # Errors happen fairly often, DHT's are hard to read, just keep going
        print(error.args[0])

    # Delay for DELAY_SECONDS seconds to avoid timeout from adafruit io
    time.sleep(DELAY_SECONDS)
Copyright © 2023 by Dornbush Web Design