Firebeetle MicroPython Badge

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

Ā 

Firebeetle MicroPython Badge

Things used in this project

Ā 

Hardware components

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

Software apps and online services

Ā 

DFRobot upycraft IDE

Ā 

MicroPython

Ā 

Hand tools and fabrication machines

Ā 

Soldering iron (generic)

Ā 

Story

Ā 

Background

Ā 

DFRobot recently release a new line of development boards called Firebeetle. Fortunately I had a chance to try the Firebeetle ESP32 IoT board and the dot matrix cover. Then something popped up in my mind to build a wearable device from those two pieces of hardware.

Ā 

Ā 

The Project

Ā 

So, I came up with this interactive badge that could be programmed using MicroPython. The Firebeetle has a Jst connector for lipo battery and I have a lipo battery lying around that I can use. Because the ESP3288 has the capability to connect to the WiFi, this badge also could grab the data from openweather API to give information about the weather.

Ā 

Ā 

Ā 

Ā 

You can tweak the code to make the badge display any kind information you want, just make sure you have enough memory space.

Schematics

Ā 

firebeetle esp32

Ā 

Code

Ā 

ht1632.py

MicroPython

copy this file/library to your firebeetle to make the dotmatrix run perfectly

CODE
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

CODE
#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)

The article was first published in hackster, December 21, Ā 2017

cr: https://www.hackster.io/hendra/firebeetle-micropython-badge-d1a0e5

author: Firebeetle MicroPython Badge

Ā 

License
All Rights
Reserved
licensBg
0