In this guide I will show you how to program and control the M5Piano on the M5Core using the M5Stack UIFlow (not UIFLOW2) programming IDE in order to make noise.
The M5Piano is currently marked EOL (End Of Line) and has been discontinued for a while but, with the increase in interest in synthesisers and music generation and ned units like the midi unit https://shop.m5stack.com/products/midi-synthesizer-unit-sam2695?ref=pfpqkvphmgr
There has been a renewed interest in using this add-on. Unfortunately as it was created a while ago, documentation on it is missing and meaning it has taken me time to create the documentation.
One of the biggest problems is that the schematics and circuit diagrams are now lost and so I have had to create a partial schematic for this guide.
The M5Piano consists of 29 SK6812 RGB LEDS connected to GPIO and 2X TS20 capacitive touch sensors connected to GPIO26 (SDA) and GPIO5 (SCL).
The addresses of the TS20 chips is set by pulling the ADD pin to 3v3 volts for 0x6A or GND for 0x7A.
The Left hand side of the keyboard is controlled with Address 0x6A and has 12 keys where as the righthand side is controlled by 0x7A and has 13 keys.
The chips send values over the I2C address and the values are returned in Decimal on register 0x02 as show below:
However, the actual values are hexadecimal 3 bytes but can be simplified by requesting 1 byte values from registers 0x02, 0x03 and 0x04.
So my understanding of the control registers was wrong and it turns out that the control registers run slightly different. Each register returns 8 bits per request which when converted to decimal gives the strange values shown in the image above
Control register 1 (0x04) monitors channels 0 to 7 (8 channels) with 1 bit assigned to each channel when contact is detected which results in the keys having the value of:
A♭ = 00000001 = Channel 0
A = 00000010 = Channel 1
B♭ = 00000100 = Channel 2
B = 00001000 = Channel 3
C = 00010000 = Channel 4
D♭ = 00100000 = Channel 5
D = 010000000 = Channel 6
Not Assigned = 10000000 = Channel 7
Control register 2 (0x03) monitors channels 8 to 14 (8 channels) with 1 bit assigned to each channel when contact is detected which results in the keys having the value of:
E♭ = 00000001 = Channel 8
E = 00000010 = Channel 9
Not Assigned = 00000100 = Channel 10
Not Assigned = 00001000 = Channel 11
Not Assigned = 00010000 = Channel 12
Not Assigned = 00100000 = Channel 13
Not Assigned = 01000000 = Channel 14
Not Assigned = 10000000 = Channel 15
We then have a big jump to control register 3 (0x04) monitors channels 15 to 20 (6 channels) but with two additional bits set to 0 to make up the bits giving us the key values of:
No Channel = 00000001 = Channel 16
No Channel = 00000010 = Channel 17
F = 00000100 = Channel 18
G♭ = 00001000 = Channel 19
G = 00010000 = Channel 20
As mentioned previously, the first TS20 0x6A is only using 12 channels and so channels 12 to 20 will always return 0. I was trying to read values in hex and not bytes which is leading to my total confusion.
So far I can only get one of the TS20 to respond at a time which is quite puzzling and so my code only read the first 12 keys connected to device 0x6A.
Update 29-02-2024
Finialy got the whole keyboard to read and it was a challenge as I had to move some things around and duplicate a massive section of code.
Hear you can see that I mover around the init section and moved some stuff like the set slave address into the loop. The secret to using the whole keyboard was to duplicate all the blocks from the Set Slave Address onwards and then change the slave address from 0x6A to 0x7A on the second set.
This result is some massively long code but at least I can see it works now.
As you can see in the screenshot the code is long and filled with if statements in order to map the values to keys.
I still have to set the correct note values and work out how to switch the wave type but it's a start on a new music project.
This project is still ongoing as I'm struggling to get both TS20's to communicate at the same time but, I am also having issues with UIFlow2's I2C communications and so the project is currently stuck to UIFLow 1.
This project is sponsored by M5Stack but was only started due to the amazing annoying talent of Lookmumnocomputer and Thismeuseumisnotobsolete.
Go check out the YouTube channels.
Comments