[ADAFRUIT_F405_EXPRESS] neopixel port advice

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
CarlFK
Posts: 11
Joined: Sun Aug 16, 2020 6:18 am

[ADAFRUIT_F405_EXPRESS] neopixel port advice

Post by CarlFK » Sun Aug 16, 2020 6:36 am

I have one of these:
Adafruit STM32F405 Feather Express
https://learn.adafruit.com/adafruit-stm ... s/overview

It has a red LED and a Neopixel.
If I load CircuitPython onto the board, the neopixel module works.

Am I correct that MicroPython currently has no support for the Neopixel?

If so, has anyone started?

TIps from #CircuitPython:

You could copy how we do it (low-level bitbanging, or, on nRF52, we use PWM).
ESP32 has special-purpose hw that is ideal for it). See the low-level neopixel_write module in ports/*/common-hal/neopixel_write
making digitalio calls may be too slow
The nRF boards use PWM (much more memory hungry) because turning off interrupts like neopixel_write does is not good for BLE timing.

My plan is to copy the files around and try to change as little as possible.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: [ADAFRUIT_F405_EXPRESS] neopixel port advice

Post by OutoftheBOTS_ » Sun Aug 16, 2020 10:31 am

If you are confident in understanding how MP works you could implement the Neoplixel driver I made using a timer interupt to send the data. See here https://github.com/OutOfTheBots/STM32_NEOpixels_timer

It has been tested on a STM32F407 there might be a few small tweeks for it to do eactly what you want it to do.

Edit

I have just had a close look at the schematics for that board and it seems the neopixel is connected to pin PC0 which doesn't have a timer attached to it so it can't be driven by a timer. In fact when I look at that pin it doesn't have a SPI either so SPI method can't be used either. It has to be driven as a GPIO pin bit bang getting timing right by using NOPs
Capture.JPG
Capture.JPG (39.86 KiB) Viewed 7054 times

CarlFK
Posts: 11
Joined: Sun Aug 16, 2020 6:18 am

Re: [ADAFRUIT_F405_EXPRESS] neopixel port advice

Post by CarlFK » Sun Aug 16, 2020 10:13 pm

Thanks for looking into this.

So A) it has to be bit banged, but B) that is how CircuitPython does it, so C) the code and timing are all there, right?

(I did load up CP and do a few tests to make sure it worked.)

ilium007
Posts: 37
Joined: Tue Feb 16, 2021 10:29 am

Re: [ADAFRUIT_F405_EXPRESS] neopixel port advice

Post by ilium007 » Sat Feb 20, 2021 12:18 am

CarlFK wrote:
Sun Aug 16, 2020 10:13 pm
Thanks for looking into this.

So A) it has to be bit banged, but B) that is how CircuitPython does it, so C) the code and timing are all there, right?

(I did load up CP and do a few tests to make sure it worked.)
Did you ever get this to work?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: [ADAFRUIT_F405_EXPRESS] neopixel port advice

Post by dhylands » Sat Feb 20, 2021 1:51 am

I got the neopixel on the STM32F405 Express to work. I checked out PR #5318 and then rebased to the latest master. You'll need to rebuild the firmware. So something like this:

Code: Select all

cd micropython
git checkout master
git pull
git checkout dee49682d690898dc58397e2975e3944aa2d9d61
git checkout -b neopixel
git rebase master
git submodule update --init --recursive
cd ports/stm32
make BOARD=ADAFRUIT_F405_EXPRESS
You should now have a branch in your local repository called neopixel which is based off the latest master. Put your board in DFU mode (connect B0 to 3.3v and reset the board) and flash your custom firmware using:

Code: Select all

make BOARD=ADAFRUIT_F405_EXPRESS deploy
You can verify that you have the correct firmware by verifying that there is a neopixel_write in the pyb module. At the REPL you can type pyb.neo and press TAB and it should expand to neopixel_write (or do a dir(pyb) and see if neopixel_write is there).

You'll find a neopixel.py file in the micropython/drivers/neopixel directory. Copy it to your board (I put it in the /flash directory using rshell). Then from the REPL you can do:

Code: Select all

>>> import neopixel
>>> np = neopixel.NeoPixel(pyb.Pin('NEOPIXEL'), 1)
>>> np[0] = (1, 0, 0)
>>> np.write()
and the neopixel should come on as a dim red.

The 3-tuple is (R,G,B) where each color can vary from 0-255. I found anything above 10 to be rather bright. You'll always use np[0] since there is only a single neopixel in the chain.

ilium007
Posts: 37
Joined: Tue Feb 16, 2021 10:29 am

Re: [ADAFRUIT_F405_EXPRESS] neopixel port advice

Post by ilium007 » Sat Feb 20, 2021 1:53 am

Thats great, so should this make its way into a release at some stage?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: [ADAFRUIT_F405_EXPRESS] neopixel port advice

Post by dhylands » Sat Feb 20, 2021 2:01 am

I expect it will eventually. @dpgeorge created the driver. You can view the PR here: https://github.com/micropython/micropython/pull/5318
so I suspect it's just a matter of time.

ilium007
Posts: 37
Joined: Tue Feb 16, 2021 10:29 am

Re: [ADAFRUIT_F405_EXPRESS] neopixel port advice

Post by ilium007 » Sat Feb 20, 2021 2:47 am

dhylands wrote:
Sat Feb 20, 2021 1:51 am

Code: Select all

cd micropython
git checkout master
git pull
git checkout dee49682d690898dc58397e2975e3944aa2d9d61
git checkout -b neopixel
git rebase master
git submodule update --init --recursive
cd ports/stm32
make BOARD=ADAFRUIT_F405_EXPRESS
Didn't quite work for me:

Code: Select all

❯ git checkout dee49682d690898dc58397e2975e3944aa2d9d61
fatal: reference is not a tree: dee49682d690898dc58397e2975e3944aa2d9d61

ilium007
Posts: 37
Joined: Tue Feb 16, 2021 10:29 am

Re: [ADAFRUIT_F405_EXPRESS] neopixel port advice

Post by ilium007 » Sat Feb 20, 2021 2:01 pm

I assume this is because commit dee49682d690898dc58397e2975e3944aa2d9d61 is in @dpgeorge's fork of micropython. I would have cloned this repo but it seems to be 1227 commits behind micropython:master. Not sure what to do.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: [ADAFRUIT_F405_EXPRESS] neopixel port advice

Post by dhylands » Sat Feb 20, 2021 4:54 pm

Whoops. Sorry about that.

Try this command:

Code: Select all

git fetch -fu origin pull/5318/head:neopixel
git checkout neopixel
That should replace these 2 commands:

Code: Select all

git checkout dee49682d690898dc58397e2975e3944aa2d9d61
git checkout -b neopixel
I actually use a script called git-pr which I got from here: https://gist.github.com/jhnns/d654d9d6da6d3b749986
If you put that in your PATH and make it executable, then you can replace the above with:

Code: Select all

git pr 5318

Post Reply