USI and neopixel not working in Gemma

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
inventor
 
Posts: 9
Joined: Sat Jun 29, 2013 8:12 pm

USI and neopixel not working in Gemma

Post by inventor »

Hi

I'm trying to use this library to recommend this post

http://www.adafruit.com/blog/2013/09/30 ... e-trinket/

USI or neopixel work well separately, but not in set, neopixel not working with USI active

Help

Thanks

Google Translate

User avatar
egutting
 
Posts: 297
Joined: Wed Nov 14, 2012 12:57 am

Re: USI and neopixel not working in Gemma

Post by egutting »

It looks like the USI runs off of pins 0 & 1, do you have the neo pixels on one of those pins as well?

User avatar
inventor
 
Posts: 9
Joined: Sat Jun 29, 2013 8:12 pm

Re: USI and neopixel not working in Gemma

Post by inventor »

I have Neopixel in D2

User avatar
egutting
 
Posts: 297
Joined: Wed Nov 14, 2012 12:57 am

Re: USI and neopixel not working in Gemma

Post by egutting »

Could you post the code you are using with the </> button to see if there may be something there?

User avatar
inventor
 
Posts: 9
Joined: Sat Jun 29, 2013 8:12 pm

Re: USI and neopixel not working in Gemma

Post by inventor »

Yes, i have a Gemma working 8Mhz :)

Code: Select all

/* UsiSerial by [email protected]
 *  
 * UsiSerial is a simple wrapper around the code from AVR307 so that Arduino can use USI to implement a hardware serial port
 *
 * This is a simple echo example.
 *
 * The USI class works almost exactly like HardwareSerial
 * So you can use print and println and other functions like that
 *
 * PORTB0 is DI, thus it is RX
 * PORTB1 is DO, thus it is TX
 * default baud rate is 19200, which can only be changed in USI_UART_config.h
 * only some baud rates will work, depending on CPU frequency
 * buffers are small to save memory, since this library is designed for ATtiny
 * testing was done using a 16 MHz Trinket
 *
 * Important note: requires Timer1 and PCINT to be occupied
 

#include <UsiSerial.h>
#include <Adafruit_NeoPixel.h>

#define PIN 2 //marked D2 on GEMMA

// Parameter 1 = number of pixels in strip
// Parameter 2 = 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_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(48, PIN, NEO_GRB + NEO_KHZ800);

int sine[] = {4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28, 36, 35, 34, 33, 32, 47, 46, 45, 44}; //these are the pixels in order of animation-- 27 pixels in total

void setup()
{
  UsiSerial.begin();
  
  strip.begin();
  strip.setBrightness(40); //adjust brightness here
  strip.show(); // Initialize all pixels to 'off'
}

void loop()
{

  for(int i=0; i<36; i++) { 
    strip.setPixelColor(sine[i], strip.Color(75, 250, 100)); //change RGB color value here
    delay(40);
    for (int j=0; j<25; j++){
      strip.setPixelColor(sine[(j+i+4)%36], strip.Color(0, 0, 0));
    }
    strip.show(); 
  }

  if (UsiSerial.available() > 0) {
    UsiSerial.write(UsiSerial.read());
  }  
}


Thanks

User avatar
egutting
 
Posts: 297
Joined: Wed Nov 14, 2012 12:57 am

Re: USI and neopixel not working in Gemma

Post by egutting »

This may be the issue...in the NeoPixel library it turns off interrupts: Line 97 of Adafruit_NeoPIxel.cpp: noInterrupts(); // Need 100% focus on instruction timing
The hardware serial mentions in the read_me file: Important note: requires Timer1 and PCINT to be occupied.

You need interrupts for the hardware serial to work, but need them turned off for NeoPixels due to the timing.

User avatar
inventor
 
Posts: 9
Joined: Sat Jun 29, 2013 8:12 pm

Re: USI and neopixel not working in Gemma

Post by inventor »

Then they would not work together? or there would be a solution?

Thank you for your help

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: USI and neopixel not working in Gemma

Post by adafruit_support_bill »

You would not be able to use them at the same time. Neopixel updates and interrupts are fundamentally incompatible.

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”