maresaku
Published © GPL3+

Hourly Speaking Clock with LED Light 3s

OLED constantly displays image, date, weekday, and time. Speaks time hourly, lights LED for 3s.

IntermediateFull instructions providedOver 1 day55
Hourly Speaking Clock with LED Light 3s

Things used in this project

Hardware components

STAMPS3 
M5Stack STAMPS3 
×1
M5Stack -STAMPS3 GroveBreakOut
×1

Software apps and online services

MicroPython
MicroPython

Story

Read more

Schematics

Wiring

It's about the wiring.

Breakout and Pin Number

The pin numbers are listed on the breakout.

Code

Main Program

MicroPython
This is the main program used.
Please enter your "Wifi ID" and "Wifi password".
The language is MicroPython.
import network
import ntptime
from machine import Pin, PWM, UART, I2C
from ssd1306 import SSD1306_I2C
import framebuf
import time

#-----wifi------

ssid = 'Wifi ID'
Password = 'Wifi Password'

#Wifi connection
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid,Password)

while not wlan.isconnected() and wlan.status() >= 0:
    print("waiting to connect:")
    time.sleep(1)
    
#print(wlan.ifconfig())

#-----NTC------

#Get date and time
UTC_offset = 9 * 60 * 60
day_week = ("Mon","Tue","Wed", "Thu", "Fri", "Sat", "Sun")
ntptime.settime()

#-----OLED-----

#Image
#https://icooon-mono.com/12766-%ef%bd%92abbit-icon-1/?lang=en
picture = bytearray(b'\x03\x07\x00\x00\x07\x8f\x00\x00\x07\x9f\x00\x00\x07\xdf\x00\x00\x07\xff\x00\x00\x07\xff\x00\x00\x07\xfe\x00\x00\x03\xfe\x00\x00\x03\xfc\x00\x00\x07\xfc\x00\x00\x0f\xfc\x00\x00\x1f\xfc\x00\x00\x1f\xfe\x00\x00\x3f\xff\x00\x00\x3f\xff\xc0\x00\x3f\xff\xf0\x00\x3f\xff\xfe\x00\x1f\xff\xff\x00\x07\xff\xff\x80\x03\xff\xff\xc0\x01\xff\xff\xe0\x01\xff\xff\xe0\x00\xff\xff\xf0\x00\xff\xff\xf0\x00\xff\xff\xf0\x00\xff\xff\xf0\x00\xff\xff\xf8\x00\xff\xff\xfc\x01\xff\xff\xfc\x01\xf1\xff\xf8\x01\xf7\xff\xb0\x01\xf7\xff\x80')

#OLED
WIDTH  = 128
HEIGHT = 64
i2c = I2C(0,scl=Pin(13), sda=Pin(15), freq=200000) 
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)

#Image display
image = picture
fb = framebuf.FrameBuffer(image, 32, 32, framebuf.MONO_HLSB)  #Image size 32X32

#-----DF_Player------

uart = UART(1,baudrate=9600,tx = Pin(43),rx = Pin(44))

def Play(num):
    # Creating serial data
    onsei = bytearray([0x7E,0xFF,0x06,0x03,0x00,0x00,num,0xEF])
    # Transmitting serial data
    uart.write(onsei)

#-----RGB------

pwm0 = PWM(Pin(1),10000)  
pwm1 = PWM(Pin(4),10000)
pwm2 = PWM(Pin(2),10000)

pwm3 = PWM(Pin(6),10000)  
pwm4 = PWM(Pin(11),10000)
pwm5 = PWM(Pin(5),10000)

#define a function to set the color of RGBLED.
#Color Code:https://itsakura.com/html-color-codes
#value:0-1023
def setColor1(r1, g1, b1):
    pwm0.duty(r1) 
    pwm1.duty(g1)
    pwm2.duty(b1)
    
def setColor2(r2, g2, b2):
    pwm3.duty(r2) 
    pwm4.duty(g2)
    pwm5.duty(b2)

def Off():
    setColor1(0, 0, 0)
    setColor2(0, 0, 0) 

def Red():
    setColor1(1023, 0, 0)
    setColor2(1023, 0, 0)   

def Green():
    setColor1(0, 1023, 0)
    setColor2(0, 1023, 0)   

def Blue():
    setColor1(0, 0, 1023)
    setColor2(0, 0, 1023)

def Yellow():
    setColor1(1023, 1023, 0)
    setColor2(1023, 1023, 0)

def Orenge():
    setColor1(1023, 256, 0)
    setColor2(1023, 256, 0)
    
def Cyan():
    setColor1(0, 1023, 1023)
    setColor2(0, 1023, 1023)
    
def Aquamarine():
    setColor1(128, 1023, 256)
    setColor2(128, 1023, 256)
    
def LightGreen():
    setColor1(0, 1023, 128)
    setColor2(0, 1023, 128)
    
def Magenta():
    setColor1(1023, 0, 1023)
    setColor2(1023, 0, 1023)
    
def DeepPink():
    setColor1(1023, 128, 1023)
    setColor2(1023, 128, 1023)

def Pink():
    setColor1(1023, 256, 1023)
    setColor2(1023, 256, 1023)

def White():
    setColor1(1023, 1023, 1023)
    setColor2(1023, 1023, 1023)

#-----Code------

while True:
    
    local_date_time = time.localtime(time.time() + UTC_offset)
    local_year =  local_date_time[0]
    local_month = local_date_time[1]
    local_day = local_date_time[2]
    local_hour = local_date_time[3]
    local_minute = local_date_time[4]
    
    local_year_month_day = str('{:04d}'.format(local_year)) + "/" + str('{:02d}'.format(local_month)) + "/" + str('{:02d}'.format(local_day))  
    local_day_week = "(" + day_week[local_date_time[6]] + ")"
    local_hour_minute = str('{:02d}'.format(local_hour)) + ":" + str('{:02d}'.format(local_minute))
       
    oled.fill(0)
    oled.blit(fb, 48, 0)
    oled.text(local_year_month_day + local_day_week ,0,40)
    oled.text(local_hour_minute,0,50)
    oled.show()
    
    if ( local_minute == 0 and local_hour == 1 ):
        Red()
        Play(0x01)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(2.4)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 2 ):
        Green()
        Play(0x02)
        time.sleep(0.3)
        Play(0x0d)
        time.sleep(2.7)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 3 ):
        Blue()
        Play(0x03)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(2.4)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 4 ):
        Yellow()
        Play(0x04)
        time.sleep(0.3)
        Play(0x0d)
        time.sleep(2.7)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 5 ):
        Orenge()
        Play(0x05)
        time.sleep(0.3)
        Play(0x0d)
        time.sleep(2.7)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 6 ):
        Cyan()
        Play(0x06)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(2.4)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 7 ):
        Aquamarine()
        Play(0x07)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(2.4)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 8 ):
        LightGreen()
        Play(0x08)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(2.4)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 9 ):
        Magenta()
        Play(0x09)
        time.sleep(0.3)
        Play(0x0d)
        time.sleep(2.7)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 10 ):
        DeepPink()
        Play(0x0b)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(2.4)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 11 ):
        Pink()
        Play(0x0b)
        time.sleep(0.6)
        Play(0x01)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(1.8)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 12 ):
        White()
        Play(0x0b)
        time.sleep(0.6)
        Play(0x02)
        time.sleep(0.3)
        Play(0x0d)
        time.sleep(2.1)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 13 ):
        Red()
        Play(0x0b)
        time.sleep(0.6)
        Play(0x03)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(1.8)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 14 ):
        Green()
        Play(0x0b)
        time.sleep(0.6)
        Play(0x04)
        time.sleep(0.3)
        Play(0x0d)
        time.sleep(2.1)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 15 ):
        Blue()
        Play(0x0b)
        time.sleep(0.6)
        Play(0x05)
        time.sleep(0.3)
        Play(0x0d)
        time.sleep(2.1)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 16 ):
        Yellow()
        Play(0x0b)
        time.sleep(0.6)
        Play(0x06)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(1.8)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 17 ):
        Orenge()
        Play(0x0b)
        time.sleep(0.6)
        Play(0x07)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(1.8)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 18 ):
        Cyan()
        Play(0x0b)
        time.sleep(0.6)
        Play(0x08)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(1.8)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 19 ):
        Aquamarine()
        Play(0x0b)
        time.sleep(0.6)
        Play(0x09)
        time.sleep(0.3)
        Play(0x0d)
        time.sleep(2.1)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 20 ):
        LightGreen()
        Play(0x0c)
        time.sleep(0.9)
        Play(0x0d)
        time.sleep(2.1)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 21 ):
        Magenta()
        Play(0x0c)
        time.sleep(0.9)
        Play(0x01)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(1.5)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 22 ):
        DeepPink()
        Play(0x0c)
        time.sleep(0.9)
        Play(0x02)
        time.sleep(0.3)
        Play(0x0d)
        time.sleep(1.8)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 23 ):
        Pink()
        Play(0x0c)
        time.sleep(0.9)
        Play(0x03)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(1.5)
        Off()
        time.sleep(57)
    elif ( local_minute == 0 and  local_hour == 0 ):
        White()
        Play(0x0a)
        time.sleep(0.6)
        Play(0x0d)
        time.sleep(2.4)
        Off()
        time.sleep(57)
    else:
        Off() 
        time.sleep(60)

ssd1306.py

Save it to your device without changing the name.

Credits

maresaku
1 project • 0 followers

Comments