wrightmac
Published

ItsyBisty CircuitPython Playground

I recently acquired an Adafruit ItsyBitsy M4 Express and I am playing around learning about it and CircuitPython.

BeginnerShowcase (no instructions)257
ItsyBisty CircuitPython Playground

Things used in this project

Hardware components

Adafruit ItsyBitsy M4 Express
×1
Gravity: I2C BME280 Environmental Sensor
DFRobot Gravity: I2C BME280 Environmental Sensor
×1
High Accuracy Pi RTC (DS3231)
Seeed High Accuracy Pi RTC (DS3231)
×1
0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Mu-editor

Story

Read more

Schematics

DateTimeTemp_Schematic

Code

Base Clock

Python
This is the simple, simple version of a clock using an ItsyBitsy with a RTC, OLED. This is done in CircuitPython.
# Using the ItsyBitsy, readin the time from a RTC and
# displaying it on an OLED

import time
import board
import adafruit_ssd1306
import busio
import adafruit_ds3231

# Setup I2C
i2c = busio.I2C(board.SCL, board.SDA)

# Create instances:
rtc = adafruit_ds3231.DS3231(i2c)
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)

# Lookup table for names of days (nicer printing).
days = ("Sunday", "Monday", "Tuesday", "Wednesday",
        "Thursday", "Friday", "Saturday")

# Change False to True, edit time, save, reboot. Once time
# is set, change True back to False, save, and reboot. 
# The time is now set. 
if False:
    #                     year, mon, date, hour, min, sec, wday, yday, isdst
    t = time.struct_time((2019,  7,   4,   14,  00,  100,    4,   -1,    -1))
    # you must set year, mon, date, hour, min, sec and weekday
	
    print("Setting time to:", t)     
    rtc.datetime = t
    print()

# Main loop:
while True:
    t = rtc.datetime
    
    # DEBUG     
    print("The date is {} {}/{}/{}".format(days[int(t.tm_wday)],
          t.tm_mday, t.tm_mon, t.tm_year))
    print("The time is {}:{:02}:{:02}".format(t.tm_hour, t.tm_min, t.tm_sec))
	
	# Send time to the screen. 
    display.fill(0)
    display.show()
    display.text("The time is {}:{:02}:{:02}".format(t.tm_hour, t.tm_min,
                 t.tm_sec))
    display.show()

    time.sleep(1)  # wait a second

Date, Time, and Temp

MicroPython
Added BME280 to the project just for fun.
# ItsyBitsy RTC, OLED Clock, and BME280
# This is one of my adventures into the world of both Circuitpython
# and the M4 platform. I am using the Adafuit ItsyBitsy M4.

import time
import board

import busio
import adafruit_ds3231
import adafruit_ssd1306
import adafruit_bme280

# Setup I2C
i2c = busio.I2C(board.SCL, board.SDA)

# Create instances for i2c devices:
rtc = adafruit_ds3231.DS3231(i2c)
display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x76)

# change this to match your local pressure (hPa) at sea level
# Check your local airport or weather forcast
bme280.sea_level_pressure = 1016.25

# Lookup table for the days of the week.
days = ("Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat")

# Below, change False to True to set the time. Once set
# change it back to False and save again.
if False:
    #                     year, mon, date, hour, min, sec, wday, yday, isdst
    t = time.struct_time((2019,  7,   4,   14,  00,  100,    4,   -1,    -1))
    # print("Setting the time to:", t)
    rtc.datetime = t
    print()

while True:
    t = rtc.datetime
    # get values for:
    Tmp = bme280.temperature
    Prs = bme280.pressure
    Hmd = bme280.humidity
    Alt = bme280.altitude   # calculated by adafruit library from pressure

    # Print statements below are for debugging to the serial console
    # remove or comment out when done.
    # print(t)
    print("The date is {} {}/{}/{}".format(days[int(t.tm_wday)],
          t.tm_mday, t.tm_mon, t.tm_year))
    print("At the tone the time will be {}:{:02}:{:02}"
          .format(t.tm_hour, t.tm_min, t.tm_sec))
    print("\nTemperature: %0.1f C" % Tmp)
    #  print("\nTemp degrees %0.1f F" % bme280.temperature * 1.8 + 32)
    print("Humidity: %0.1f %%" % Hmd)
    print("Pressure: %0.1f hPa" % Prs)
    print("Altitude = %0.2f meters" % Alt)
    # Display it to the OLED
    display.fill(0)
    display.show()
    display.text("wrightMac time is:", 20, 10, 1)
    display.text("{} {}/{}/{}".format(days[int(t.tm_wday)],
                 t.tm_mday, t.tm_mon, t.tm_year), 20, 45, 1)
    display.text("{}:{:02}".format(t.tm_hour, t.tm_min), 50, 28, 1)
    #  display.text("{}:{:02}:{:02}".format(t.tm_hour, t.tm_min,
    #            t.tm_sec), 30, 40, 1)
    display.show()
    time.sleep(5)
    display.fill(0)
    display.show()
    display.text("wrightMac Temp", 20, 10, 1)
    display.text("%0.1f C" % Tmp, 30, 30,1)
    display.show()

    time.sleep(5)  # wait a second
    #  need to work on this as screen is refreshed ever¥ second
    #  and the blinking is not cool
    #  if it isn't cleared the pixels pile up

Credits

wrightmac

wrightmac

8 projects • 12 followers
Network geek by day, apprentice hardware hacker by night, Apple advocate ex·tra·or·di·naire always!

Comments

Add projectSign up / Login