STM32F103C8T6 + neopixels
-
- Posts: 10
- Joined: Wed Jun 10, 2020 4:10 pm
STM32F103C8T6 + neopixels
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
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
Adafruit library works only with STM32 core.
Go to full postRe: STM32F103C8T6 + neopixels
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).
#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).
-
- Posts: 10
- Joined: Wed Jun 10, 2020 4:10 pm
Re: STM32F103C8T6 + neopixels
sorry i sent pure example, but of course I changed pin. It still doesn't work.
-
- Posts: 502
- Joined: Fri Dec 27, 2019 4:53 pm
- Location: Munich, Germany
- Contact:
Re: STM32F103C8T6 + neopixels
viewtopic.php?f=2&t=301
Which core do you use?
Which core do you use?
-
- Posts: 10
- Joined: Wed Jun 10, 2020 4:10 pm
Re: STM32F103C8T6 + neopixels
This one
- Attachments
-
- Annotation 2020-08-20 125319.png (9.66 KiB) Viewed 17722 times
-
- Posts: 502
- Joined: Fri Dec 27, 2019 4:53 pm
- Location: Munich, Germany
- Contact:
Re: STM32F103C8T6 + neopixels
Have you tried to g**gle stm32 + neopixel + library
One of the results: https://github.com/rogerclarkmelbourne/ ... 2_Libmaple
One of the results: https://github.com/rogerclarkmelbourne/ ... 2_Libmaple
Re: STM32F103C8T6 + neopixels
Adafruit library works only with STM32 core.
-
- Posts: 10
- Joined: Wed Jun 10, 2020 4:10 pm
Re: STM32F103C8T6 + neopixels
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.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
-
- Posts: 10
- Joined: Wed Jun 10, 2020 4:10 pm
Re: STM32F103C8T6 + neopixels
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 (35.59 KiB) Viewed 17663 times
Re: STM32F103C8T6 + neopixels
You mentioned this is another thread ( viewtopic.php?f=21&t=493 ).Jakub_Szubzda wrote: ↑Fri Aug 21, 2020 1:05 pmyes 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.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
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).