In this guide I will show you how to access the ATECC608b encryption chip used by M5Stack in ID Unit and Core2 AWS using UIFlow. This has been a bit of an issue for several of us in the community and I have found that it is caused but an error in UIFlow where the I2C code is not set up and initialised in the correct order.
After some digging I found that the issue may also be affecting the ID Unit as well as the Core2 AWS and after several days of poking at code, the issue turned out to be with how UIFlow was inserting I2C Master code.
In the above screenshot you can see how UIFlow inserts the I2C functions into the Micropython code. Without Looking at the Micropython widow I would not have found the issue and normally UIFlow looks like this:
For a week I have been looking at this and the code window:
I ran through all the code blocks and code function not seeing the error until I added a label.
Every time I ran this code I kept getting Kernal panics or Guru Meditation faults. After spending two nights looking at this, I drink a bottle of beer (gluten free) and went to bed early.The Fix.
The next morning (while half asleep) I looked at the screen and spotted the issue!
The I2C code was being initialised after the Label was being configured. I had come across a few issues where code was run in the wrong order and so I move the I2C code to the beginning and things all started to work.
I dropped a print function into the code:
And the I2C address started to show up (btw 53 is the decimal address of the ATECC608b which equates to 0x35 in hex.)
Now we have the address showing we can start communicating with the ATECC608b.Communicating with the ATECC608b
This step proved to be a bit more complicated and took several more days of work and messaging to solve.
Now I have the basics after poking away at micropython I import machine and units._ID0
from units import _ID
ID_0 = unit.get(unit.ID, (21,22))
I can now wakeup the ATECC608b by issuing:
To see what the output status of the function is, I put it in a print function to give me some output feedback.
When run in Thonny, this returns a "True" so say the ATECC608b is now active.Generating a Key!
I spent ages typing in several functions into Thonny using REPL and started to get feedback.
returned a byte array of:
gave me a byte array of:
I thought I was on a roll here and so typed:
This unfortunately returned and empty byte array of:
After more reading I found I needed to generate a new key using:
When I re ran print(ID_0.publicKey64Bytes) I now had a byte array filled with a random generated code:
With this success my brain has given up and I need some sleep. until next time keep watching!Stalk/Contact me!
If you would like to reach out you can drop a message here or you can drop a message on our Facebook group here: https://www.facebook.com/groups/m5stack
The Official forums here: https://community.m5stack.com
Via Twitter : https://twitter.com/Cpt_J_Purcell