Neopixel with attiny45 didn't work

I want to interfacing attiny45 with ws2812. I use neopixel to control the ws2812. It didn't work, but it works when I tried my code with Arduino. How to fix this?

#include <Adafruit_NeoPixel.h>

#define PIN PB1
#define NUMPIXELS 1

const byte button1 = 0;
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  pinMode(PIN, OUTPUT);
  pinMode(button1, INPUT_PULLUP);
}

void loop() {
  pixels.clear();
  pixels.setBrightness(255);

  if (!digitalRead(button1)){
    pixels.setPixelColor(0, pixels.Color(255, 0, 0));
    pixels.show();
    delay(100);
  }

  else{
    pixels.setPixelColor(0, pixels.Color(0, 0, 0));
    pixels.show();
    delay(100);
  }
}

Sorry for not providing a solution, but perhaps I can help to get a step further (or backwards).

The ATtiny is not officially supported by Arduino and the ATtiny85 is the most used.
First of all, there is a "core" or "build environment" to select, for example one of these:

Then you have to select a NeoPixel library that is known to be compatible with that core.

Suppose the "damellis" version is selected with FastLED on a ATtiny85, then Wokwi can simulate it: attiny85-fastled.ino - Wokwi Arduino and ESP32 Simulator
Click on the start button.

You can copy-paste your own sketch in it, and it will stay dark. If you want to make your own Wokwi project and store it, then you have to log in (it's free).

As far as i know adafruit_neopixel actually is supposed to support AVR's as well. The first thing is to tell us which core you are using, and have you set the clock speed by doing 'burn bootloader' to set the fuses ?
I have never used a ATtiny45, but i think i've managed to get it working on an 85, which means it should work on a 45 just as well. In fact i've found the sketch and it looks very similar to yours (albeit a bit more elaborate) and i've found the project which is battery powered.
I use SpenceKonde's ATtiny core 1.5.2 (for as long as it takes before the update to 2.0 is ready)
Just include

#ifdef __AVR__
  #include <avr/power.h>
#endif

and make sure you do 'burn bootlaoder at 8MHz internal, and let me know.

Please show schematics and describe “did not work” in detail.

#ifdef __AVR__
#include <avr/power.h>
#endif

I was using this, but still it didn't work.

I'm running the simulation using Proteus. Now it works by setting the CKSEL Fuses to PLL CLOCK. I don't know it would or wouldn't works if I burn my code to the ATtiny.

Screenshot (381)

That's the schematic.
It wasn't working due the wrong set of CKSEL Fuses. It works after I set the CKSEL Fuses to PLL CLOCK.

Yeah 'burn bootloader' still i have mine working on 8MHz internal as well, which means you can run it also at lower voltages. adafruit_neopixel checks for CPU speed and compiles accordingly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.