Trinket M0 DotStar via SPI - not responding

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
tgmcnaughton
 
Posts: 12
Joined: Sat Mar 10, 2012 10:13 pm

Trinket M0 DotStar via SPI - not responding

Post by tgmcnaughton »

I want to control the onboard DotStar LED (ideally via hardware SPI) on trinket M0.
I'm running an unmodified Trinket M0 in Arduino 2.0.1 with fresh library updates (Adafruit DotStar 1.2.1) on Windows10.

The following code uploads fine: the onboard DotStar LED cycles from Green to Violet, the onboard LED "Blinks" and the Serial.Print monitor line works. But the onboard DotStar just stays Violet.

I've tried enabling Hardware SPI by commenting out the line2 (#include <SPI.h>) and 10 and uncommenting line 11 and I get the same behavior. Another unusual thing I notice is that I must reselect the port each time I upload - and it changes from say Port9 to Port10 and back.

I see the same behavior on a different Win10 laptop with fresh Arduino 2.0.1 install.

Code: Select all

#include <Adafruit_DotStar.h>
#include <SPI.h>         // software SPI

//#include <avr/power.h> // ENABLE THIS LINE FOR GEMMA OR TRINKET 
      // if uncommented, this gives: Compilation error: avr/power.h: No such file or directory

#define NUMPIXELS 1 // Number of LEDs in strip
#define DATAPIN    7
#define CLOCKPIN   8
Adafruit_DotStar strip(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);  // software SPI
//Adafruit_DotStar strip(NUMPIXELS, DOTSTAR_BRG);  // hardware SPI

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  strip.begin(); // Initialize pins for output
  strip.show();  // Turn all LEDs off ASAP
}

void loop() {
  Serial.println("M0");
  digitalWrite(LED_BUILTIN, HIGH);
  strip.setPixelColor(0, 0x00FF0000); 
  strip.show();                     
  delay(200);                      
  digitalWrite(LED_BUILTIN, LOW);  
  strip.setPixelColor(0, 0x0000FF00); 
  strip.show();                     
  delay(200);                       
}

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Trinket M0 DotStar via SPI - not responding

Post by adafruit_support_carter »

Can you clarify which one is happening? Is the DotStar LED cycling color?
the onboard DotStar LED cycles from Green to Violet
or not?
the onboard DotStar just stays Violet

User avatar
tgmcnaughton
 
Posts: 12
Joined: Sat Mar 10, 2012 10:13 pm

Re: Trinket M0 DotStar via SPI - not responding

Post by tgmcnaughton »

During upload, the DotStar cycles from Violet, briefly Red, Green, and then after upload, the DotStar just stays solid Violet.
The red onboard LED goes from blinking to rapid flashing with upload and then just blinks on/off each 200ms.

I also tried calling setPixelColor with 4 params as follows:

Code: Select all

strip.setPixelColor(0, 255, 0, 0); //strip.Color(255,0,0)); 
  strip.show();
and I tried this line in setup() to try to ensure switch to hardware SPI.

Code: Select all

strip.updatePins();
So here is current sketch - expecting DotStar to blink Red then Green each 200ms. What I see after upload is the red BuiltIn LED blinking and the DotStar stays solid Violet

Code: Select all

#include <Adafruit_DotStar.h>
//#include <SPI.h>         // software SPI

//#include <avr/power.h> // ENABLE THIS LINE FOR GEMMA OR TRINKET
//  if uncommented, gives: Compilation error: avr/power.h: No such file or directory

#define NUMPIXELS 1 // Number of LEDs in strip
#define DATAPIN    7
#define CLOCKPIN   8
//Adafruit_DotStar strip(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);  // software SPI
Adafruit_DotStar strip(NUMPIXELS,DOTSTAR_BRG);  // hardware SPI

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  strip.begin(); // Initialize pins for output
  strip.updatePins();
  strip.show();  // Turn all LEDs off ASAP
}

void loop() {
  Serial.println("M0");
  digitalWrite(LED_BUILTIN, HIGH);
  strip.setPixelColor(0, 255, 0, 0); //strip.Color(255,0,0)); 
  strip.show();                     
  delay(200);                      
  digitalWrite(LED_BUILTIN, LOW);  
  strip.setPixelColor(0, 0, 255, 0);  //strip.Color(0,255,0)); 
  strip.show();                     
  delay(200);                       
}

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Trinket M0 DotStar via SPI - not responding

Post by adafruit_support_carter »

Why do you need the DotStar to be driven by hardware SPI? The only defined hardware SPI interface is on pins 6, 4, and 3:
https://github.com/adafruit/ArduinoCore ... #L128-L130

The DotStar is not connected to those pins.

User avatar
tgmcnaughton
 
Posts: 12
Joined: Sat Mar 10, 2012 10:13 pm

Re: Trinket M0 DotStar via SPI - not responding

Post by tgmcnaughton »

Ok, thanks. I thought it was connected to SPI - I see the pinout showing MOSI/SCK connected to 7 and 8.
Now I'm feeling sheepish as I tried the following code (thanks for the link) and it just crashes the Trinket. Requires double click reset to reconnect. This seems about as simple as it can get - yet doesn't work = trinket bricks and DotStar just stays solid violet.
Should it be working as written? Don't we need an #include SPI.h?

Code: Select all

#include <Adafruit_DotStar.h>

Adafruit_DotStar strip = Adafruit_DotStar(1, INTERNAL_DS_DATA, INTERNAL_DS_CLK, DOTSTAR_BGR);

void setup() {
  strip.begin();
}

void loop() {
  strip.setPixelColor(0, 64, 0, 0); strip.show(); delay(1000); //red
  strip.setPixelColor(0, 0, 64, 0); strip.show(); delay(1000); //green
  strip.setPixelColor(0, 0, 0, 64); strip.show(); delay(1000); //blue
}

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Trinket M0 DotStar via SPI - not responding

Post by adafruit_support_carter »

That code looks fine. Just tested it here and it ran fine. Trinket DotStar cycles between red/green/blue forever.

Are you seeing the reset behavior with even the basic Blink example here?
https://learn.adafruit.com/adafruit-tri ... nk-2854174

Is there anything else attached to the Trinket M0?

User avatar
tgmcnaughton
 
Posts: 12
Joined: Sat Mar 10, 2012 10:13 pm

Re: Trinket M0 DotStar via SPI - not responding

Post by tgmcnaughton »

The Blink sketch uploads and runs, but, it still requires reselecting the com port prior to each upload.
There is some unusual behavior - when I select Tools->Port it lists both pIRKey and Trinket M0 as attached to the same port:Com5 - (I don't have a pIRKey). If I select port5 through Tools->Port it uploads fine.
When I select the boardselect dropdown it gives me options for pIRKey on Com5 (or Com6 if I've just rebooted the Trinket) and Trinket on Com1. If I select Com1 - it doesn't find a board at upload time, and if I select Com5 (pIRKey) it uploads blink but then crashes the port and requires reset.

I tried connecting an Arduino Uno at the same time as the trinket. It shows as Com7 and when I upload Blink, it works perfectly and does NOT need the port to be reselected after upload. So basically the Uno works exactly as I'm used to.

So, some weird stuff going on in port assignment with my Trinket M0

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Trinket M0 DotStar via SPI - not responding

Post by adafruit_support_carter »

OK, I think what you're seeing is just expected behavior on Windows.

The Trinket M0 has "native USB" - the USB connection is hosted and run by firmware on the main processor, the same one that runs your user sketch code. As part of uploading a sketch, the board resets after the sketch is uploaded. That causes the USB stuff to also reset. The Windows PC sees that as a disconnect / reconnect, and for some reason, Windows likes to bounce between two COM ports.

The UNO has a dedicated USB chip, separate from the chip that runs the sketch. So when the main chip resets, there is no associated USB disconnect seen by the PC.

User avatar
tgmcnaughton
 
Posts: 12
Joined: Sat Mar 10, 2012 10:13 pm

Re: Trinket M0 DotStar via SPI - not responding

Post by tgmcnaughton »

Thanks much. I have ordered some more Tinket M0s and will test them out to see if my problem is environment or maybe I've got a dud Trinket.
Thx

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

Return to “Trinket ATTiny, Trinket M0”