Go Down

Topic: First Project using a Micro controller (Trinket) Feel like I'm flying blind (Read 481 times) previous topic - next topic

Withencroft

I'm following along guides as best as possible but I feel completely in over my head. I've worked with LEDs before but it's always been simple circuits that go on or off but for this project the customer wanted special effects so I've now involved a micro controller.

As far as I can tell all my solder is good, shiny and chrome, I've wired it all to match the arrows on the LED strips, the powerboost and the battery both work. When I connect the Trinket to the computer and upload the sketch it says upload complete with no problems. But the LEDs don't come on at all.

I know that the default pin setting is 6 and I changed it to 1 in the code, at least I did in the beginning I'm not sure if I need to change more than once in the code.

I'm not sure where to begin to find the problem. Is the the code? The Trinket? Somewhere in the wires? Having never done this before I'm immensely concerned I will have to completely dismantle it and start all over.

pert

Post a drawing of your wiring schematic.

Please post your full sketch. If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's ok to add it as an attachment. Don't put your code in some external file service like dropbox, etc. We shouldn't need to go to an external website just to help you. I do feel it's reasonable to post a link to code hosted on GitHub or similar code hosting sites since that's an platform specifically designed for this sort of thing

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor then you will not  have access to this useful tool. I recommend using the standard Arduino IDE instead.

When your code requires a library that's not included with the Arduino IDE please post a link(using the chain links icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger(Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

Withencroft

Code: [Select]

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

#define PIN 1

// 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)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
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() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  // End of trinket special code


  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
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  // 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 (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t 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 (uint16_t 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 (uint16_t 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) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

 This is the code. It's strandtest from the Adafruit Neopixel library with the only edit being me changing the pin 6 to a 1

I am using IDE and I don't have a specific sketch of my wiring schematic but I can show you the one I was following as an example.

Withencroft

Here's the schematic, I used the same layout except no second switch on the Trinket because I don't need two light modes for the lights.

pert

I know that the default pin setting is 6 and I changed it to 1 in the code, at least I did in the beginning I'm not sure if I need to change more than once in the code.
That's fine if you have the data line of the LED strip connected to pin 1 the only change you needed to make is altering the value of PIN from 6 to 1, as you did.

Here's the schematic

It doesn't follow the Adafruit best practices guide:
https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices
In that there is no 1000 uF capacitor on the power lines and no 300-500 Ohm resistor on the data line. Certainly it's possible to get away without those but it's something to consider, especially when things aren't working correctly.

I recommend starting with the most simple possible code before trying something more advanced like that strandtest sketch. Try this:
Code: [Select]
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 1

#define NUMPIXELS 1

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif

  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {
  pixels.setPixelColor(0, pixels.Color(0, 150, 0)); // Moderately bright green color.
  pixels.show(); // This sends the updated pixel color to the hardware.
  delay(1000);
  pixels.setPixelColor(0, pixels.Color(0, 0, 0)); // off
  pixels.show(); // This sends the updated pixel color to the hardware.
  delay(1000);
}

That should just blink the first LED on the strip green on and off at 0.5 Hz.

You need to keep in mind that the Trinket doesn't have a lot of memory so you're a bit limited in what you can do. For controlling a lot of LEDs you might be better to use a different microcontroller but it can be fun to see just how much you can do with limited resources if you're into that sort of thing.

Withencroft

That's fine if you have the data line of the LED strip connected to pin 1 the only change you needed to make is altering the value of PIN from 6 to 1, as you did.

It doesn't follow the Adafruit best practices guide:
https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices
In that there is no 1000 uF capacitor on the power lines and no 300-500 Ohm resistor on the data line. Certainly it's possible to get away without those but it's something to consider, especially when things aren't working correctly.

I recommend starting with the most simple possible code before trying something more advanced like that strandtest sketch. Try this:
Code: [Select]
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 1

#define NUMPIXELS 1

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif

  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {
  pixels.setPixelColor(0, pixels.Color(0, 150, 0)); // Moderately bright green color.
  pixels.show(); // This sends the updated pixel color to the hardware.
  delay(1000);
  pixels.setPixelColor(0, pixels.Color(0, 0, 0)); // off
  pixels.show(); // This sends the updated pixel color to the hardware.
  delay(1000);
}

That should just blink the first LED on the strip green on and off at 0.5 Hz.

You need to keep in mind that the Trinket doesn't have a lot of memory so you're a bit limited in what you can do. For controlling a lot of LEDs you might be better to use a different microcontroller but it can be fun to see just how much you can do with limited resources if you're into that sort of thing.
I'll keep that in mind about the resistors. The person in the guide I was following mentioned them but said that they haven't ever really needed them.

As for a different micro controller I can't really do that. The lights I'm doing are for a prop from Fallout called the alien blaster. So a bunch of lights, wires, the micro proccessor, power boost, and battery all have to fit into something slightly bigger than an average gun. The body is more round which has allowed adequate space for what I do have but I'm not sure I could even fit the next size up which is the Pro Trinket.

I only need the lights to do a pulsing effect so I hoped the Trinket could at least manage that.

Grumpy_Mike

Quote
The person in the guide I was following mentioned them but said that they haven't ever really needed them
Yes yet another idiot writing a guide when he has no idea about what he is doing. And what do you think "needed them" means? It is not a case of it will not work without them but will work with them. If you need them and don't have them your LEDs are toast.


Go Up