AJB2K3
Published © CC BY-NC-SA

M5Piano

How to Program and control the M5Piano using M5Stacks UIFlow IDE

IntermediateProtip2 hours185
M5Piano

Things used in this project

Story

Read more

Schematics

Partial Schematic

Code

First test code

MicroPython
from m5stack import *
from m5ui import *
from uiflow import *
import i2c_bus
import unit

setScreenColor(0x222222)
neopixel_0 = unit.get(unit.NEOPIXEL, (2,2), 29)

label0 = M5TextBox(1, 93, "label0", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(2, 130, "label1", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(5, 198, "label2", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(186, 58, "label3", lcd.FONT_Default, 0xFFFFFF, rotate=0)
title0 = M5Title(title="M5Piano", x=128, fgcolor=0xFFFFFF, bgcolor=0x0000FF)

i2c0 = i2c_bus.easyI2C((26, 5), 0x00, freq=115200)
i2c0.addr=(0x6A)
while True:
  speaker.setVolume(0.05)
  neopixel_0.setColorAll(0x000000)
  label0.setText(str(i2c0.scan()))
  label1.setText(str(i2c0.read_reg(0x20, 3)))
  label2.setText(str(int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')))
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 1:
    neopixel_0.setColor(9, 0xff0000)
    speaker.sing(208, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 2:
    neopixel_0.setColor(10, 0xff0000)
    speaker.sing(220, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 4:
    neopixel_0.setColor(11, 0xff0000)
    speaker.sing(233, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 8:
    neopixel_0.setColor(12, 0xff0000)
    speaker.sing(247, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 16:
    neopixel_0.setColor(1, 0xff0000)
    speaker.sing(131, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 32:
    neopixel_0.setColor(2, 0xff0000)
    speaker.sing(139, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 64:
    neopixel_0.setColor(3, 0xff0000)
    speaker.sing(147, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 128:
    neopixel_0.setColor(29, 0xff0000)
    speaker.sing(440, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 256:
    neopixel_0.setColor(4, 0xff0000)
    speaker.sing(156, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 512:
    neopixel_0.setColor(5, 0xff0000)
    speaker.sing(165, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 262144:
    neopixel_0.setColor(6, 0xff0000)
    speaker.sing(175, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 524288:
    neopixel_0.setColor(7, 0xff0000)
    speaker.sing(185, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 1048576:
    neopixel_0.setColor(8, 0xff0000)
    speaker.sing(196, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 131072:
    neopixel_0.setColor(8, 0xff0000)
    speaker.sing(392, 1)
  wait_ms(2)

Full keyboard

MicroPython
from m5stack import *
from m5ui import *
from uiflow import *
import i2c_bus
import time
import unit


setScreenColor(0x222222)
neopixel_0 = unit.get(unit.NEOPIXEL, (2,2), 29)






label0 = M5TextBox(1, 93, "label0", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(2, 130, "label1", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(0, 153, "label2", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(186, 58, "label3", lcd.FONT_Default, 0xFFFFFF, rotate=0)
title0 = M5Title(title="M5Piano", x=128, fgcolor=0xFFFFFF, bgcolor=0x0000FF)


i2c0 = i2c_bus.easyI2C((26, 5), 0x00, freq=115200)
wait_ms(100)
while True:
  i2c0.addr=(0x6A)
  wait_ms(100)
  i2c0.write_u8(0x20, 0x00)
  speaker.setVolume(0.05)
  neopixel_0.setColorAll(0x000000)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 1:
    neopixel_0.setColor(9, 0xff0000)
    speaker.sing(208, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 2:
    neopixel_0.setColor(10, 0xff0000)
    speaker.sing(220, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 4:
    neopixel_0.setColor(11, 0xff0000)
    speaker.sing(233, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 8:
    neopixel_0.setColor(12, 0xff0000)
    speaker.sing(247, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 16:
    neopixel_0.setColor(1, 0xff0000)
    speaker.sing(131, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 32:
    neopixel_0.setColor(2, 0xff0000)
    speaker.sing(139, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 64:
    neopixel_0.setColor(3, 0xff0000)
    speaker.sing(147, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 128:
    neopixel_0.setColor(29, 0xff0000)
    speaker.sing(440, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 256:
    neopixel_0.setColor(4, 0xff0000)
    speaker.sing(156, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 512:
    neopixel_0.setColor(5, 0xff0000)
    speaker.sing(165, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 262144:
    neopixel_0.setColor(6, 0xff0000)
    speaker.sing(175, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 524288:
    neopixel_0.setColor(7, 0xff0000)
    speaker.sing(185, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 1048576:
    neopixel_0.setColor(8, 0xff0000)
    speaker.sing(196, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 131072:
    neopixel_0.setColor(8, 0xff0000)
    speaker.sing(392, 1)
  i2c0.addr=(0x7A)
  wait_ms(100)
  i2c0.write_u8(0x20, 0x00)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 1:
    neopixel_0.setColor(21, 0xff0000)
    speaker.sing(208, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 2:
    neopixel_0.setColor(22, 0xff0000)
    speaker.sing(220, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 4:
    neopixel_0.setColor(23, 0xff0000)
    speaker.sing(233, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 8:
    neopixel_0.setColor(24, 0xff0000)
    speaker.sing(247, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 16:
    neopixel_0.setColor(13, 0xff0000)
    speaker.sing(131, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 32:
    neopixel_0.setColor(14, 0xff0000)
    speaker.sing(139, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 64:
    neopixel_0.setColor(15, 0xff0000)
    speaker.sing(147, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 128:
    neopixel_0.setColor(29, 0xff0000)
    speaker.sing(440, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 256:
    neopixel_0.setColor(16, 0xff0000)
    speaker.sing(156, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 512:
    neopixel_0.setColor(17, 0xff0000)
    speaker.sing(165, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 262144:
    neopixel_0.setColor(18, 0xff0000)
    speaker.sing(175, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 524288:
    neopixel_0.setColor(19, 0xff0000)
    speaker.sing(185, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 1048576:
    neopixel_0.setColor(20, 0xff0000)
    speaker.sing(196, 1)
  if (int.from_bytes((i2c0.read_reg(0x20, 3)), 'little')) == 131072:
    neopixel_0.setColor(8, 0xff0000)
    speaker.sing(392, 1)
  wait_ms(100)
  wait_ms(2)

Credits

AJB2K3

AJB2K3

45 projects • 28 followers
I have always had an interest in electronics but having failed my school exams, it has taken me 20+ years to produce products to share.

Comments