Page 1 of 1

STM32F103C8T6 + neopixels

Posted: Wed Aug 19, 2020 10:15 pm
by Jakub_Szubzda
so I'd like to drive neopixels using STM32F103C8T6's PA10 pin with Adafruit_NeoPixel library, and arduino ide as you can do with arduino uno, but i have no idea how, so i'd be very glad if someone helped me with this. :?:

i also attach example:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 16 // Popular NeoPixel ring size

// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels

void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.

pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}

void loop() {
pixels.clear(); // Set all pixel colors to 'off'

// The first NeoPixel in a strand is #0, second is 1, all the way up
// to the count of pixels minus one.
for(int i=0; i<NUMPIXELS; i++) { // For each pixel...

// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
// Here we're using a moderately bright green color:
pixels.setPixelColor(i, pixels.Color(0, 150, 0));

pixels.show(); // Send the updated pixel colors to the hardware.

delay(DELAYVAL); // Pause before next pass through loop
}
}









i think that changing this parts would help:

#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif



and


#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif

Re: STM32F103C8T6 + neopixels

Posted: Wed Aug 19, 2020 11:14 pm
by GonzoG
Just change
#define PIN 6
to
#define PIN PA10

But Adafruit library isn't optimized for STMs and on F103 it takes over 1ms to send data for 8 LEDs (about 280-300us on Arduino UNO/nano).

Re: STM32F103C8T6 + neopixels

Posted: Thu Aug 20, 2020 1:34 am
by Jakub_Szubzda
GonzoG wrote: Wed Aug 19, 2020 11:14 pm Just change
#define PIN 6
to
#define PIN PA10

But Adafruit library isn't optimized for STMs and on F103 it takes over 1ms to send data for 8 LEDs (about 280-300us on Arduino UNO/nano).
sorry i sent pure example, but of course I changed pin. It still doesn't work.

Re: STM32F103C8T6 + neopixels

Posted: Thu Aug 20, 2020 9:25 am
by stevestrong
viewtopic.php?f=2&t=301
Which core do you use?

Re: STM32F103C8T6 + neopixels

Posted: Thu Aug 20, 2020 10:55 am
by Jakub_Szubzda
This one

Re: STM32F103C8T6 + neopixels

Posted: Thu Aug 20, 2020 1:05 pm
by stevestrong
Have you tried to g**gle stm32 + neopixel + library
One of the results: https://github.com/rogerclarkmelbourne/ ... 2_Libmaple

Re: STM32F103C8T6 + neopixels

Posted: Thu Aug 20, 2020 1:46 pm
by GonzoG
Adafruit library works only with STM32 core.

Re: STM32F103C8T6 + neopixels

Posted: Fri Aug 21, 2020 1:05 pm
by Jakub_Szubzda
stevestrong wrote: Thu Aug 20, 2020 1:05 pm Have you tried to g**gle stm32 + neopixel + library
One of the results: https://github.com/rogerclarkmelbourne/ ... 2_Libmaple
yes i have downloaded this library before and it works, but unfortunatelly uses spi, which in my project is already used by nrf24l01 module. Both cannot work together on one spi bus. I tried to use second one, but on spi_2 you can generate max twice slower than needed.

Re: STM32F103C8T6 + neopixels

Posted: Fri Aug 21, 2020 1:18 pm
by Jakub_Szubzda
GonzoG wrote: Thu Aug 20, 2020 1:46 pm Adafruit library works only with STM32 core.
:o :o :o :o :o :o
Oh man so simple, still so hard. Thank you so much it really helps me to complete this project.

if anyone has problem with finding upper mentioned core you just have to go: File > Preferences > Additional boards Menager URLs and paste this link there:
https://raw.githubusercontent.com/stm32 ... index.json


next go to board > boards Manager and search "stm32"


then download this core

Re: STM32F103C8T6 + neopixels

Posted: Sat Aug 22, 2020 11:09 pm
by ozcar
Jakub_Szubzda wrote: Fri Aug 21, 2020 1:05 pm
stevestrong wrote: Thu Aug 20, 2020 1:05 pm Have you tried to g**gle stm32 + neopixel + library
One of the results: https://github.com/rogerclarkmelbourne/ ... 2_Libmaple
yes i have downloaded this library before and it works, but unfortunatelly uses spi, which in my project is already used by nrf24l01 module. Both cannot work together on one spi bus. I tried to use second one, but on spi_2 you can generate max twice slower than needed.
You mentioned this is another thread ( viewtopic.php?f=21&t=493 ).

As I said there, Roger's core and WS2812B library seemed to work on SPI2, provided I changed the SPI divider as set in the library.

Disclaimer - I did not have any LEDs connected, but the timing of the pulses looked good (certainly less variable than I got with the ST core and the Adafruit library).