{"id":16304,"date":"2020-05-26T22:51:19","date_gmt":"2020-05-27T02:51:19","guid":{"rendered":"https:\/\/scruss.com\/blog\/?p=16304"},"modified":"2020-05-27T13:48:46","modified_gmt":"2020-05-27T17:48:46","slug":"weact-f411-micropython-neopixels","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2020\/05\/26\/weact-f411-micropython-neopixels\/","title":{"rendered":"WeAct F411 + MicroPython + NeoPixels"},"content":{"rendered":"\n<p>Further to the <a href=\"https:\/\/scruss.com\/blog\/2020\/05\/20\/canaduino-stm32-boards-with-micropython\/\">Canaduino STM32 boards with MicroPython<\/a> writeup, I thought I&#8217;d start showing how you&#8217;d interface common electronics to the <a href=\"https:\/\/www.universal-solder.ca\/product\/stm32-pro-black-pill-stm32f411ceu6-128m-extra-flash-100mhz-512k-internal-flash-128k-ram-no-soldering\/\">WeAct F411<\/a> boards. First off, NeoPixels!<\/p>\n\n\n\n<p>Rather than use the <a href=\"https:\/\/www.adafruit.com\/category\/168\">Adafruit<\/a> trade name, these are more properly called WS2812 LEDs. Each one contains a tiny microcontroller and it only takes three connections to drive a long chain of addressable colour LEDs. The downside is that the protocol to drive these is a bit of a bear, and really needs an accurate, fast clock signal to be reliable.<\/p>\n\n\n\n<p>The STM32F411 chip does have just such a clock, and the generic <a href=\"https:\/\/github.com\/JanBednarik\/micropython-ws2812\/pulls\">micropython-ws2812<\/a> library slightly misuses the SPI bus to handle the signalling. The wiring&#8217;s simple: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>F411 GND to WS2812 GND;<\/li><li>F411 3V3 to WS2812 5V;<\/li><li>F411 <s>PA7 (<em>SPI1_MOSI<\/em>)<\/s> PB15 (<em>SPI2_MOSI<\/em>) to WS2812 DIn<\/li><\/ul>\n\n\n\n<p>Next, copy <a href=\"https:\/\/github.com\/JanBednarik\/micropython-ws2812\/blob\/master\/ws2812.py\">ws2812.py<\/a> into the WeAct F411&#8217;s flash. Now create a script to drive the LEDs. Here&#8217;s one to drive 8 LEDs, modified from the library&#8217;s advanced example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# -*- coding: utf-8 -*-\n\nimport time\nimport math\n\nfrom ws2812 import WS2812\n\nring = WS2812(spi_bus=2, led_count=8, intensity=0.1)\n\ndef data_generator(led_count):\n    data = &#x5B;(0, 0, 0) for i in range(led_count)]\n    step = 0\n    while True:\n        red = int((1 + math.sin(step * 0.1324)) * 127)\n        green = int((1 + math.sin(step * 0.1654)) * 127)\n        blue = int((1 + math.sin(step * 0.1)) * 127)\n        data&#x5B;step % led_count] = (red, green, blue)\n        yield data\n        step += 1\n\nfor data in data_generator(ring.led_count):\n    ring.show(data)\n    time.sleep_ms(100)\n<\/pre><\/div>\n\n\n<p>Previously I said you&#8217;d see your WS2812s flicker and shimmer from the SPI bus noise. I thought it was cool, but I suspect it was also why the external flash on my F411 board just died. By pumping data into PA7,  I was also hammering the <a href=\"https:\/\/stm32-base.org\/boards\/STM32F411CEU6-WeAct-Black-Pill-V2.0#Generic-EEPROM\">flash chip&#8217;s DI line<\/a> \u00e2\u20ac\u00a6<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Further to the Canaduino STM32 boards with MicroPython writeup, I thought I&#8217;d start showing how you&#8217;d interface common electronics to the WeAct F411 boards. First off, NeoPixels! Rather than use the Adafruit trade name, these are more properly called WS2812 LEDs. Each one contains a tiny microcontroller and it only takes three connections to drive [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[150,3094,3232,3231,3233],"class_list":["post-16304","post","type-post","status-publish","format-standard","hentry","category-computers-suck","tag-led","tag-micropython","tag-neopixel","tag-weact_f411","tag-ws2812"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-4eY","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/16304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=16304"}],"version-history":[{"count":2,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/16304\/revisions"}],"predecessor-version":[{"id":16307,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/16304\/revisions\/16307"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=16304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=16304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=16304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}