Hendra Kusumah
Published © GPL3+

Firebeetle MicroPython Badge

A badge with dot matrix cover that could be programmed using MicroPython..

BeginnerShowcase (no instructions)3 hours820

Things used in this project

Hardware components

DFRobot Firebeetle Esp32
×1
DFRobot FireBeetle Covers-24×8 LED Matrix (White)
×1
3.7 V LiPo Battery
×1

Software apps and online services

DFRobot upycraft IDE
MicroPython
MicroPython

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

firebeetle esp32

Code

ht1632.py

MicroPython
copy this file/library to your firebeetle to make the dotmatrix run perfectly
from machine import Pin
import framebuf

DFROBOT_HT1632_READ = const(0x06)
DFROBOT_HT1632_WRITE = const(0x05)
DFROBOT_HT1632_COMMAND = const(0x04)
DFROBOT_HT1632_SYS_DIS = const(0x00)
DFROBOT_HT1632_SYS_EN = const(0x01)
DFROBOT_HT1632_LED_OFF = const(0x02)
DFROBOT_HT1632_LED_ON = const(0x03)
DFROBOT_HT1632_BLINK_OFF = const(0x08)
DFROBOT_HT1632_BLINK_ON = const(0x09)
DFROBOT_HT1632_SLAVE_MODE = const(0x10)
DFROBOT_HT1632_MASTER_MODE = const(0x14)
DFROBOT_HT1632_INT_RC = const(0x18)
DFROBOT_HT1632_EXT_CLK = const(0x1C)
DFROBOT_HT1632_PWM_CONTROL = const(0xA0)
DFROBOT_HT1632_COMMON_8NMOS = const(0x20)
DFROBOT_HT1632_COMMON_16NMOS = const(0x24)
DFROBOT_HT1632_COMMON_8PMOS = const(0x28)
DFROBOT_HT1632_COMMON_16PMOS = const(0x2C)

class HT1632C():
  def __init__(self,DATA,CLK,CS):
    self.width = 240
    self.height = 8
    self.CS = Pin(CS,Pin.OUT)
    self.DATA = Pin(DATA,Pin.OUT)
    self.CLK = Pin(CLK,Pin.OUT)
    self.CS.value(1)
    self.pages = self.height // 8
    self.buffer = bytearray(self.pages * self.width)
    self.framebuf = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MVLSB)
    self.begin()
  def begin(self):
    for cmd in (
      DFROBOT_HT1632_SYS_EN,
      DFROBOT_HT1632_LED_ON,
      DFROBOT_HT1632_BLINK_OFF,
      DFROBOT_HT1632_MASTER_MODE,
      DFROBOT_HT1632_INT_RC,
      DFROBOT_HT1632_COMMON_16NMOS,
      DFROBOT_HT1632_PWM_CONTROL | 0xF
    ):
      self.writeCommand(cmd)

  def writeCommand(self, cmd):
    val = (DFROBOT_HT1632_COMMAND<<9) | (cmd <<1)
    self.CS.value(0)
    self.writeBits(val,12)
    self.CS.value(1)

  def show(self):
    self.CS.value(0)
    self.writeBits(DFROBOT_HT1632_WRITE,3)
    self.writeBits(0,7)
    for i in range(24):
      val = self.buffer[23-i]
      val <<= 8
      self.writeBits(val,16)
    self.CS.value(1)


  def writeBits(self,data,length):
    while length:
      self.CLK.value(0)
      if(data & (1<< length-1)):
        self.DATA.value(1)
      else:
        self.DATA.value(0)
      self.CLK.value(1)
      length-=1

  def fill(self,vol):
    self.framebuf.fill(vol)

  def pixel(self, x, y, col):
    self.framebuf.pixel(x, y, col)

  def scroll(self, dx, dy):
    self.framebuf.scroll(dx, dy)

  def text(self, string, x, y, col=1):
    self.framebuf.text(string, x, y, col)

badge.py

MicroPython
#hardware platform: FireBeetle-ESP8266

import ht1632
import time



DATAPIN=10
CLKPIN =13
CSPIN  =25

led=ht1632.HT1632C(DATAPIN,CLKPIN,CSPIN)




def write1():
  led.text("Firebeetle Badge",0,0)
  led.show()
  
  for i in range(145):
    led.scroll(-1,0)
    led.show()
    time.sleep(0.005)


def write2():
  led.text("Have a nice day",1,0)
  led.show()
  
  for i in range(170):
    led.scroll(-1,0)
    led.show()
    time.sleep(0.01)
        
while True:
  write1()
  write2()
  #time.sleep(1)

Credits

Hendra Kusumah

Hendra Kusumah

15 projects • 68 followers
Love hacking and making new things from IoT to robotics

Comments