Go Down

Topic: Neopixels and Attiny85 (Read 3540 times) previous topic - next topic

b8el018

Dec 02, 2014, 08:33 pm Last Edit: Dec 02, 2014, 08:36 pm by b8el018 Reason: Forgot to put code into code tag
I would like to program the attiny85 with my Arduino Uno, I would like to program it to control the Neopixels.

I have the WS2812B neopixels.


I think the problem I am having is wiring it up, I just want to put the strand test code on.

Thank you :)

Here is the code, any idea how I would wire it up?

Code: [Select]
#include <Adafruit_NeoPixel.h>

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
  // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); // White
  theaterChase(strip.Color(127,   0,   0), 50); // Red
  theaterChase(strip.Color(  0,   0, 127), 50); // Blue

  rainbow(20);
  rainbowCycle(20);
  theaterChaseRainbow(50);
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();
     
      delay(wait);
     
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
        }
        strip.show();
       
        delay(wait);
       
        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, 0);        //turn every third pixel off
        }
    }
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Helmuth

#1
Dec 02, 2014, 08:52 pm Last Edit: Dec 02, 2014, 08:58 pm by Helmuth
First of all you need to specifiy a pin that exists - something between 0 and 4 at an ATtiny.

Code: [Select]
#define PIN 4

Connect your leds to that pin.

60 leds means 180 byte just for the framebuffer. You have only 512 Byte RAM.

So start with a small number like 10 and if that works you increase the number of leds you are going to control.

Code: [Select]
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);

b8el018

So i have connected the

LED Strip ground to arduino ground
LED strip DI to leg 3 of ATTiny85
LED Strip +5 to the +5 of Arduino

also I added power to the chip and added the capacitor on reset and ground

What do I do, because all I have is the ground and +5 coming from Arduino, I don't know where the arduino output is for it to actually program the Attiny85

Helmuth

#3
Dec 03, 2014, 01:24 am Last Edit: Dec 03, 2014, 01:26 am by Helmuth
Ahh, your question is basically not about leds but about programming an ATtiny with an Arduino Uno.

So check out one of the countless available tutorials about that.

http://42bots.com/tutorials/how-to-program-attiny85-with-arduino-uno-part-1/

b8el018

Yeah, sorry if if was unclear

Thank you :)

b8el018

So I've done the blink sketch on the Attiny85, but I still can't work out how to program the Attiny85 with the neopixels.

The code itself is fine and works with the arduino, so there's something wrong with the way I'm connecting it up


I'm confused as to where each wire goes from the Arduino and into the Attiny85.

I have read the datasheets but I just don't get it can someone explain how it gets connected?


Thank you

Helmuth

#6
Dec 08, 2014, 05:45 pm Last Edit: Dec 08, 2014, 08:56 pm by Helmuth
Quote
So I've done the blink sketch on the Attiny85, but I still can't work out how to program the Attiny85 with the neopixels.
And blink works on the ATtiny? If so: good. How did you test it? Write the other sketch exactely the same way to the ATtiny.

Keep in mind to select a speed like 8 MHz, just to make sure to be fast enough for the leds. I´m not familiar with the Neopixel lib but at 1 MHz it will not work for sure.

Quote
I'm confused as to where each wire goes from the Arduino and into the Attiny85.
??? As described in the link above.

Quote
The code itself is fine and works with the arduino
It means nothing, that the code works on an Uno. The Uno has more RAM, more pins and is faster.

Again: did you specifiy the right pin? Did you go down with the number of leds for the beginning?

Quote
there's something wrong with the way I'm connecting it up
What could it be? You specify one pin and connect the Din from the pixels to that pin. Ground ATtiny to ground leds.

You don´t have the Uno AND the leds connected to the ATtiny, right?!

Show us a photo of your setup.

b8el018

#7
Dec 09, 2014, 08:46 pm Last Edit: Dec 09, 2014, 08:49 pm by b8el018
I have defined pin 4 using '#define PIN 4' in code. Is it pin 4 on arduino or attiny85 and what does it mean, does it tell the arduino where to output or what?

Also I have set the arduino board setting up with the 8MHz internal oscillator BOD disabled
Also I have put the brown wire into pin 4 on arduino not 2.




Helmuth

#8
Dec 09, 2014, 09:00 pm Last Edit: Dec 09, 2014, 09:17 pm by Helmuth
I would just repeat myself. Sorry, but I am running out of patience.

The link I gave you contains a picture showing the wiring AND a text describing the wiring. It says:

Quote
Connect ATtiny Pin 1 (with the little dot) to Arduino Pin 10.
Connect ATtiny Pin 5 to Arduino Pin 11.
Connect ATtiny Pin 6 to Arduino Pin 12.
Connect ATtiny Pin 7 to Arduino Pin 13.
Connect the ground and 5v from the Arduino to the breadboard.
Connect ATtiny Pin 4 to ground.
Connect ATtiny Pin 8 to 5 volts.
In the picture I see 6 wires between the Uno and the ATtiny. On your Photo I see just 2.

And look at the capacitor again: how does it look like in the tutorial? How does your setup look like?
What is the difference? WHY?

Quote
I have defined pin 4 using '#define PIN 4' in code. Is it pin 4 on arduino or attiny85 and what does it mean, does it tell the arduino where to output or what?
I wrote you:

Quote
specify one pin and connect the Din from the pixels to that pin
What is unclear about that? If you say in the sketch "pin 4" it means that you have to connect your leds to PIN 4 of the ATtiny after programming the ATtiny.

Quote
So I've done the blink sketch on the Attiny85
Aha. But for sure not with the wiring you present us here.


b8el018

Okay, this extremely simple task has been over complicated in my head. Thanks anyway I don't know what I was on about but sorry.



Helmuth

Never mind. Did you get it working now?

b8el018

No, I gave up. I will try again with a completely fresh start tomorrow.

Go Up