I took a break this evening from my work on the SPPBL. I have been learning Python for work and thought this would be a good time to work on my Circuitpython as well.

IBM4_CP clock

Before work I dug around the workbench and grabbed an ItsyBitsy M4 Express, a SSD 1306 128×64 OLED, a BME280, and a DS3231 Real Time Clock (RTC). I am lucky that some night, as tonight, things are quiet and I can work on a personal project.


The Adafruit ItsyBitsy (IB) is really a pretty cool little board. I picked one up a couple of months ago on a whim. It comes with CircuitPython preinstalled on it and it acts as an USB drive so you can carry all of your work with you. Very nice. It is powered with the Atmel SAMD51 chip and plenty of memory. If you want the city-gritty on the board, check out the specs over at Adafruit’s site.

A CircuitPy window in the MacOS Finder.

Above is an example of how the ItsyBitsy appears in a MacOS Finder window. For all intent and purposes it look and acts like a USB drive. It has almost 2MB of storage on it. Personally I am sold that all I need is my little board, plug it in a computer and away I go working on my project(s).

Putting it together

Tonight I started with the RTC. It is a DS3231 board that I had for one of my Raspberry Pi’s. Since it never got used with them, this seemed like a good purpose for it. It is an I2C device; I used a scanner to find the address which is 0x68. I grabbed the adafruit library for the RTC and installed it on the IB. This is as easy as dragging the file from my Mac over to the CircuitPy. There is some code to set the time on the RTC. You can see it below. It was straight forward. The only real issue I had was finding the pinout for the board. The headers cover the labels, but I was able to confirm that the pinout is 3v3, SDA, SCL, nc, GND. For now I just had it printing the date and time to the serial console.

The plan on paper

I2C is as it is a bus that can communication with multiple devices. It also cuts down on the number of wires needed to communicate with a controller down to 2; the SDA and SCL. I like the explanation of I2C from CircuitBasics.

Next is the screen, another I2C device. I checked on its’ address to make sure it didn’t conflict with the RTC. I knew it wouldn’t but no harm in double-checking. Its’ address is 0x3c. It seems that the library is limited right now. The text is pretty tiny. I am working on figuring out how to get something a little larger that I might be able to read. I was thinking of a slightly larger display with a larger font and using it. As is it is going to be a little hard to do. One step at a time. It didn’t take long at all before I had Hello World displayed on the screen.

Lastly is the BME280. This one was giving me problems to no end. The i2c scanner would see it, but the script would not have it even when I tired to force the address. One error barked about a chip ID not being right. Huh, I am using the generic version not the Adafruit. I cracked open the library with BBEdit and tracked down where the address and ID were coded in. I changed both of them to match the board and it started working. The I2C bus is chugging along with 3 devices. I have one more in my box of goodies, the BH1750 light sensor. Time to toss that on and see what fun I can have.

After that it was mashing the three together to get the data displayed on the screen.

At the tone the time will be . . .

And the temperature is. . .


Here are links to the data sheets of the products I have used in this project.


Below is where my code stands as of now. Pretty simple, but let’s see what I can do to expand upon the might little ItsyBitsy M4 Express.

# ItsyBitsy RTC, OLED Clock
# This is my first adventure into the world of both Circuitpython
# and the M4 platform. I am using the Adafuit ItsyBitsy M4.
# Peter Hein, 2019
# Creatvie Commons License. 

import time
import board
import busio
import adafruit_ssd1306
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, 64, i2c)

# 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

while True:
    t = rtc.datetime
    # The print statements are used for debugging comment out 
    # or remove. 
    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))
    # Time to get the information to the screen
    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)
    time.sleep(30)  # 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

© 2019, wrightmac. All rights reserved.

No tags for this post.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.