This project is my record of getting the NeoFlashC from M5Stack working in their UIFlow programming environment.
There are demo code samples for running the NeoFlashC using the Arduino programming environment but, I struggle with it and so tend to prefer to use the UIFlow environment ( I am writing a book on it so it makes sense). The first challenge I needed to face was that there was no code in the UIFLow firmware to drive the board.
After a long search I found the source Micropython code for the firmware and created a new file by duplicating the RGB Multi code.
import unit
import machine
class Rgb_multi:
def __init__(self, port, number=143):
self.port = port
self.pin = port[0]
self.number = number
self.np = machine.Neopixel(self.pin, self.number)
self.np.brightness(10)
def setColor(self, num, color_in):
self.np.set(num, color_in)
def setColorFrom(self, begin, end, color_in):
begin = min(self.number, max(begin, 1))
end = min(self.number, max(end, 1))
for i in range(begin, end+1):
self.np.set(i, color_in, update=False)
self.np.show()
def setColorAll(self, color_in):
for i in range(1, self.number+1):
self.np.set(i, color_in, update=False)
self.np.show()
def setBrightness(self, brightness):
brightness = min(255, max(0, brightness))
self.np.brightness(brightness)
def deinit(self):
self.np.deinit()
Once I had this I needed to edit it for the NeoFlashC. The editing (or so I thought) was easy and just required a little change to the beginning of the file:
class NeoFlashC:
def __init__(self, port, number=143):
self.port = port
self.pin = port [0]
self.number = number
self.np = machine.NeoFlashC(self.pin, self.number)
self.np.brightness(10)
I saved the file to the M5SickC using VSCode and switched back to usflow to run the demo code.
from m5stack import *
from m5ui import *
from uiflow import *
from neoflashc import *
NeoFlashC = unit.get(unit.NEOPIXEL, NeoFlashC.pin, 126)
NeoFlashC.setColorAll(0xff0000)
But this is where I hit my first issue "NeoFlashC.Pin Not Defined" This had me scratching my head for ages. The issue turned out to be that the pin and port definitions in unit.py was overriding the setting and preventing me from accessing the "Hat" port on the M5StickC.
Being completely new to this, I did what I thought would work and deleted the "from unit import *" line and tried again. I'm sure you can guess what happened, Yup, Simon Cowel and his big fat red X!
Remembering something I had read in the distant past I added the following to the source file
from machine import Pin
Different error message what next? I then realised that the define in the file was also wrong and so changed:
def __init__(self, port, number=143):
self.port = port
self.pin = port[0]
To this:
def __init__(self, pin, number=143):
self.port = port
self.pin = pin[26]
And got rid of another error but regained the "NeoFlashC.Pin Not Defined" error.
At this point I gave up on the library file and moved back to my demo to play.
The next day I typed this:
from m5stack import *
from m5ui import *
from uiflow import *
from neoflashc import *
From machine import Pin
setScreenColor(0x111111)
NeoFlashC.pin = (26,36)
NeoFlashC = unit.get(unit.NEOPIXEL, NeoFlashC.pin, 126)
NeoFlashC.setColorAll(0xff0000)
in to the Micropython environment and run it on the M5StickC and it worked!
After a while of looking at the screen blankly I realised what the issue was.
Thin pin still wasn't defined, but once I defined it in the demo program. the code worked and the NeoFlashC sprang to life.
27 - November - 2019
I have the core Library and base code working in UIFlow's Micropython Environment and now need to create the blocks needed to drive the NeoFlashC. I'm sure the code changes are still wrong and need cleaning up but, for now it works and does what I need it for.
My First project once the code is complete will be a small programmable camera light.
My deadline for this is February 2020 as I will need it for my holiday in March 2020.
Comments
Please log in or sign up to comment.