STM32F103C8T6 + neopixels

Post Reply
Jakub_Szubzda
Posts: 10
Joined: Wed Jun 10, 2020 4:10 pm

STM32F103C8T6 + neopixels

Post 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
by GonzoG » Thu Aug 20, 2020 1:46 pm
Adafruit library works only with STM32 core.
Go to full post
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: STM32F103C8T6 + neopixels

Post 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).
Jakub_Szubzda
Posts: 10
Joined: Wed Jun 10, 2020 4:10 pm

Re: STM32F103C8T6 + neopixels

Post 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.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: STM32F103C8T6 + neopixels

Post by stevestrong »

viewtopic.php?f=2&t=301
Which core do you use?
Jakub_Szubzda
Posts: 10
Joined: Wed Jun 10, 2020 4:10 pm

Re: STM32F103C8T6 + neopixels

Post by Jakub_Szubzda »

This one
Attachments
Annotation 2020-08-20 125319.png
Annotation 2020-08-20 125319.png (9.66 KiB) Viewed 14221 times
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: STM32F103C8T6 + neopixels

Post by stevestrong »

Have you tried to g**gle stm32 + neopixel + library
One of the results: https://github.com/rogerclarkmelbourne/ ... 2_Libmaple
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: STM32F103C8T6 + neopixels

Post by GonzoG »

Adafruit library works only with STM32 core.
Jakub_Szubzda
Posts: 10
Joined: Wed Jun 10, 2020 4:10 pm

Re: STM32F103C8T6 + neopixels

Post 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.
Jakub_Szubzda
Posts: 10
Joined: Wed Jun 10, 2020 4:10 pm

Re: STM32F103C8T6 + neopixels

Post 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
Attachments
Annotation 2020-08-21 151430.png
Annotation 2020-08-21 151430.png (35.59 KiB) Viewed 14162 times
ozcar
Posts: 143
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: STM32F103C8T6 + neopixels

Post 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).
Post Reply

Return to “STM32F1 based boards”