0

Grand Central Express M4s Not Behaving Normally
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Grand Central Express M4s Not Behaving Normally

by Baylordawg on Mon Oct 05, 2020 5:12 pm

Hello,

I have a pair of Adafruit Grand Central Express M4 boards. They are acting really weird, I'll try to describe as best as I can. I created a function and my looping code is literally a call of the function then delay for 4000 milliseconds. It looks like the code is running in a loop with no delay. I added some millis timing to the function to see if that would help and that does not help at all. I can upload this same exact code to my Adafruit Metro board and it works as expected. In order to upload the code to the Grand Central express boards, I almost always have to hit the reset button twice to get it into boot loader mode and then the code will upload. What is really weird as well, is as soon as I upload code, Windows says "usb device not recognized" and I am not able to see any serial information as the "Port" is grayed out" within Arduino IDE. I am able to upload simple (as in not many lines) code to the Grand Central Express and it works. But it seems as soon as I have more than 50 lines of code it doesn't work. For example I had a short program working with some Serial.print statements. I literally added one more print statement and I got the USB device not recogonized error and even though the IDE said it uploaded, the program didn't appear to be running.

In short, I can get the code to upload to the Grand Central but its like its corrupt and doesn't' do anything or just keeps looping disregarding any millis or delay calls. If I try to upload longer code, the code uploads but then the Grand Central doesn't' appear to be doing anything. All the code I am trying I can use perfectly fine on the Adafruit Metro so 99% sure its not my code.

I am using Arduino IDE 1.8.13. I have updated the Adafruit boards and libraries within the IDE. I also have updated the Grand Central Express bootloader from here: https://circuitpython.org/board/grandcentral_m4_express.

Not sure what else to try, kind of at my wits end. Any help would be appreciated.

David Warren

Baylordawg
 
Posts: 15
Joined: Thu Dec 20, 2018 4:24 pm

Re: Grand Central Express M4s Not Behaving Normally

by Baylordawg on Mon Oct 05, 2020 5:42 pm

Just saw this thread: viewtopic.php?f=63&t=165225#p811107

I was running an old bootloader version while trying to upload code... then I tried new bootloader. When I updated bootloader I was able to verify I was on the new one.. I shouldn't need to rewrite the bootloader manually then would I?

David

Baylordawg
 
Posts: 15
Joined: Thu Dec 20, 2018 4:24 pm

Re: Grand Central Express M4s Not Behaving Normally

by RCohenQubiq on Tue Oct 06, 2020 11:52 am

Hi David,

I don't know if you are using a J-Link to load your code into the GCM4. If you are, then try disconnecting it after loading the image, and restarting the GCM4. If the delay() and millis() are now working properly, then you are having the same problem that I have discussed in the thread linked below.

https://forums.adafruit.com/viewtopic.php?f=63&t=167384

Take care...

RCohenQubiq
 
Posts: 12
Joined: Wed Jul 15, 2020 1:38 pm

Re: Grand Central Express M4s Not Behaving Normally

by Baylordawg on Tue Oct 06, 2020 2:37 pm

Thanks for the reply. Unfortunately I am not using a J-link to load the code. I am loading it using Arduino IDE through the USB port. I can get the code to load, I have debugger on and I can get a successful upload. However then the serial monitor won't open or the code doesn't run normally like it would from another controller.

Baylordawg
 
Posts: 15
Joined: Thu Dec 20, 2018 4:24 pm

Re: Grand Central Express M4s Not Behaving Normally

by Baylordawg on Tue Oct 06, 2020 3:54 pm

I changed my bootloader to CircuitPython. I then uploaded this simple code:

import time

initial = time.monotonic()

while True:
now = time.monotonic()
print("starting while statement")
if now - initial > 5:
print("done")
else:
initial = now

When I try to run this the serial freezes on me just like when I try to run it with Arduino IDE. I think my Grand Central M4s are hosed. Is there anything I can do??

Baylordawg
 
Posts: 15
Joined: Thu Dec 20, 2018 4:24 pm

Re: Grand Central Express M4s Not Behaving Normally

by adafruit_support_carter on Wed Oct 07, 2020 4:44 pm

It seems like there might be some confusion between the bootloader and the CircuitPython firmware. You are going to the correct place for both:
https://circuitpython.org/board/grandce ... 4_express/

The CircuitPython firmware (linked from top of page) would be the UF2 file with a name like: adafruit-circuitpython-grandcentral_m4_express-en_US-5.3.1.uf2

The bootloader (linked near bottom of page) would be the UF2 file with a name like: update-bootloader-grandcentral_m4-v3.10.0.uf2

Just to make sure - can you still get into bootloader mode by double pressing the reset button?

adafruit_support_carter
 
Posts: 20609
Joined: Tue Nov 29, 2016 2:45 pm

Re: Grand Central Express M4s Not Behaving Normally

by Baylordawg on Wed Oct 07, 2020 5:22 pm

Correct, I can get into bootloader mode by pressing reset twice. I was just switching btw Arduino bootloader and Circuitpython bootloader just for something to try.

I played with it a little more today and it seems like it will run short basic code. I can upload short code to the controller and it works fine. I can even upload additional code without pushing the reset button twice. If I upload programs with more code (we are talking 50 lines, not THAT much code in all reality), Arduino IDE says it is uploaded, but then Windows says there was a problem with your USB device, the serial stops working and I cannot upload additional code without getting back into bootloader mode. Even though Arduino says the code is uploaded, it doesn't work right. Its like the controller locks up.

Baylordawg
 
Posts: 15
Joined: Thu Dec 20, 2018 4:24 pm

Re: Grand Central Express M4s Not Behaving Normally

by adafruit_support_carter on Wed Oct 07, 2020 6:08 pm

I was just switching btw Arduino bootloader and Circuitpython bootloader just for something to try.

There's no difference in the bootloader between Arduino and CircuitPython. Can you clarify what you are doing here?

adafruit_support_carter
 
Posts: 20609
Joined: Tue Nov 29, 2016 2:45 pm

Re: Grand Central Express M4s Not Behaving Normally

by Baylordawg on Wed Oct 07, 2020 6:35 pm

I originally had the ardiuno bootloader on the Grand Central so I was uploading C code via Ardiuno IDE. I thought I would try CircuitPython to see if it behaved the same. So I used Adafruit instructions to change the boot loader to circuitpython, which worked. The drive now shows up as circuitpxxx or whatever it is with code.py on the drive. I upload some python code to the Grand Central which it accepts but still has a problem like with when I uplaoded the code via Arduino IDE. I actually reverted back to the Arduino IDE so I can upload code via Arduino IDE but same problems happen.

That make sense?

Baylordawg
 
Posts: 15
Joined: Thu Dec 20, 2018 4:24 pm

Re: Grand Central Express M4s Not Behaving Normally

by adafruit_support_carter on Thu Oct 08, 2020 12:08 pm

It sounds like you are changing the firmware, not the bootloader here:
So I used Adafruit instructions to change the boot loader to circuitpython,

If you got the CIRCUITPY drive to show up, then it worked. And the board is then running CircuitPython.

If you then upload an Arduino sketch, the Arduino sketch will replace the CircuitPython firmware. You will no longer see the CIRCUITPY folder.

The bootloader does not change.

It sounds like basic Arduino sketches are working OK. Can you post the complete code listing for the sketch you are having issues with.

adafruit_support_carter
 
Posts: 20609
Joined: Tue Nov 29, 2016 2:45 pm

Re: Grand Central Express M4s Not Behaving Normally

by Baylordawg on Thu Oct 08, 2020 3:42 pm

As I mentioned, I can upload basic-ish code and it seems to work. I can run this program below. I am able to see the serial output and the LEDs on the controller behaves as I would expect.

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>

#define MASK1_PIN (88)    // data pin of neopixel strip
Adafruit_NeoPixel mask_string1 = Adafruit_NeoPixel(1, MASK1_PIN, NEO_RGB);

uint32_t purple = Adafruit_NeoPixel::Color(76,0,153);
uint32_t green = Adafruit_NeoPixel::Color(0,204,0);
uint32_t yellow = Adafruit_NeoPixel::Color(255,255,0);
uint32_t blue = Adafruit_NeoPixel::Color(0,0,153);
uint32_t white = Adafruit_NeoPixel::Color(255,255,255); 
uint32_t red = Adafruit_NeoPixel::Color(255,0,0); 
uint32_t orange = Adafruit_NeoPixel::Color(255,128,0); 
uint32_t off = Adafruit_NeoPixel::Color(0,0,0);
long previousMillis;

void setup() {
 mask_string1.begin();
 Serial.begin(9600);

}

void loop() {


 unsigned long currentMillis = millis();

 Serial.print("currentMillis:   ");
 Serial.println(currentMillis);
 Serial.print("previousMillis:   ");
 Serial.println(previousMillis);
  Serial.print("currentMillis - previousMillis:   ");
 Serial.println(currentMillis - previousMillis);

if (currentMillis - previousMillis < 10000) {

  mask_string1.fill(red);
  mask_string1.show();
 
}

if (currentMillis - previousMillis > 10000  && currentMillis - previousMillis < 20000) {

   mask_string1.fill(green);
   mask_string1.show();
 
}

if (currentMillis - previousMillis > 20000) {

   mask_string1.fill(blue);
  mask_string1.show();
  delay(5000);
  previousMillis = millis();
 
}
 

}



However, if I start creating code any longer than this, the Grand Central stops working. Here is a little more complex code that I can't get working. As soon as I upload this code I get an error on my Windows machine saying USB device is no longer recolonized and I can't get to the serial monitor anymore. The IDE says the code is uploaded but its like its corrupt or something. I can put this same exact code on a Metro and it behaves as I would expect, my set of lights change every 20 seconds. When I run this on the Grand Central, I once had nothing happen, no lights. Another time the lights were flickering so fast it was like they were changing everytime the controller looped through and ignoring the millis function.

Thanks

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>

#define PIN_MASK_FOUR       7 // Marked D1 on GEMMA
#define NUM_LEDS_MASK_FOUR 60    //<------------------------------------------------------------------ dont forge
Adafruit_NeoPixel strip_mask_four = Adafruit_NeoPixel(NUM_LEDS_MASK_FOUR, PIN_MASK_FOUR, NEO_GRB);

#define PIN_MASK_FOUR_2       8
#define NUM_LEDS_MASK_FOUR_2 60    //<------------------------------------------------------------------ dont forget
Adafruit_NeoPixel strip_mask_four_2 = Adafruit_NeoPixel(NUM_LEDS_MASK_FOUR_2, PIN_MASK_FOUR_2, NEO_GRB);

#define PIN_MASK_FOUR_3       9
#define NUM_LEDS_MASK_FOUR_3 60    //<------------------------------------------------------------------ dont forget
Adafruit_NeoPixel strip_mask_four_3 = Adafruit_NeoPixel(NUM_LEDS_MASK_FOUR_3, PIN_MASK_FOUR_3, NEO_GRB);


uint32_t purple = Adafruit_NeoPixel::Color(76,0,153);
uint32_t green = Adafruit_NeoPixel::Color(0,204,0);
uint32_t yellow = Adafruit_NeoPixel::Color(255,255,0);
uint32_t blue = Adafruit_NeoPixel::Color(0,0,153);
uint32_t white = Adafruit_NeoPixel::Color(255,255,255); 
uint32_t red = Adafruit_NeoPixel::Color(255,0,0); 
uint32_t orange = Adafruit_NeoPixel::Color(255,128,0); 
uint32_t off = Adafruit_NeoPixel::Color(0,0,0);





//////////////////////////////Mask count and length variables/////////////////////////////////////
//could change this to a multiple dimensional array but leave as is for now


int maskOneLEDCount;                         
int maskTwoLEDCount;
int maskThreeLEDCount;
int maskFourLEDCount;

int startingMaskOneLED;
int startingMaskTwoLED;
int startingMaskThreeLED;
int startingMaskFourLED;


int maskOneLEDCount_2;                         
int maskTwoLEDCount_2;
int maskThreeLEDCount_2;
int maskFourLEDCount_2;

int startingMaskOneLED_2;
int startingMaskTwoLED_2;
int startingMaskThreeLED_2;
int startingMaskFourLED_2;
 
int maskOneLEDCount_3;                         
int maskTwoLEDCount_3;
int maskThreeLEDCount_3;
int maskFourLEDCount_3;

int startingMaskOneLED_3;
int startingMaskTwoLED_3;
int startingMaskThreeLED_3;
int startingMaskFourLED_3;




long previousMillsChangeMaskColor;
int runLightningProgram;
uint32_t randomChoosenColor;
int changeMaskColorTime;



//-------------------------------------------------------------------------------------
//                                         BEGIN SETUP                                -
//-------------------------------------------------------------------------------------

void setup() {

  Serial.begin(9600);
  randomSeed(analogRead(2));

 
  strip_mask_four.begin();
  strip_mask_four.show();            // Initialize all pixels to 'off'
  strip_mask_four.setBrightness(40); // 40/255 brightness (about 15%)
 
  strip_mask_four_2.begin();
  strip_mask_four_2.show();            // Initialize all pixels to 'off'
  strip_mask_four_2.setBrightness(40); // 40/255 brightness (about 15%)
 
  strip_mask_four_3.begin();
  strip_mask_four_3.show();            // Initialize all pixels to 'off'
  strip_mask_four_3.setBrightness(40); // 40/255 brightness (about 15%)


  maskOneLEDCount = 14;                         
  maskTwoLEDCount = 16;
  maskThreeLEDCount = 14;
  maskFourLEDCount = 16;
 
  maskOneLEDCount_2 = 14;                         
  maskTwoLEDCount_2 = 16;
  maskThreeLEDCount_2 = 16;
  maskFourLEDCount_2 = 14;
 
  maskOneLEDCount_3 = 14;                         
  maskTwoLEDCount_3 = 16;
  maskThreeLEDCount_3 = 16;
  maskFourLEDCount_3 = 14;


   
  startingMaskOneLED = maskOneLEDCount - maskOneLEDCount;
  startingMaskTwoLED = maskOneLEDCount;
  startingMaskThreeLED = maskOneLEDCount + maskTwoLEDCount;
  startingMaskFourLED = maskOneLEDCount + maskTwoLEDCount + maskThreeLEDCount;

  startingMaskOneLED_2 = maskOneLEDCount_2 - maskOneLEDCount_2;
  startingMaskTwoLED_2 = maskOneLEDCount_2;
  startingMaskThreeLED_2 = maskOneLEDCount_2 + maskTwoLEDCount_2;
  startingMaskFourLED_2 = maskOneLEDCount_2 + maskTwoLEDCount_2 + maskThreeLEDCount_2;
 
   startingMaskOneLED_3 = maskOneLEDCount_3 - maskOneLEDCount_3;
  startingMaskTwoLED_3 = maskOneLEDCount_3;
  startingMaskThreeLED_3 = maskOneLEDCount_3 + maskTwoLEDCount_3;
  startingMaskFourLED_3 = maskOneLEDCount_3 + maskTwoLEDCount_3 + maskThreeLEDCount_3;

 


  runLightningProgram = 0;
  changeMaskColorTime = 12000;

}



//-------------------------------------------------------------------------------------
//                                         BEGIN LOOP                                -
//-------------------------------------------------------------------------------------

void loop() {

Serial.println("--Start of LOOP--");
normalMaskProgram();

 

}



//-------------------------------------------------------------------------------------
//                                     NormalMaskProgram                            -
//-------------------------------------------------------------------------------------


int normalMaskProgram()  {
unsigned long currentMillisChangeMaskColor = millis();

Serial.println("--Start of Normal Mask Program--");

Serial.print("currentMillisChangeMaskColor:    ");
Serial.println(currentMillisChangeMaskColor);

Serial.print("previousMillsChangeMaskColor:    ");
Serial.println(previousMillsChangeMaskColor);


Serial.print("currentMillisChangeMaskColor - previousMillsChangeMaskColor:    ");
Serial.println(currentMillisChangeMaskColor - previousMillsChangeMaskColor);


if ((currentMillisChangeMaskColor - previousMillsChangeMaskColor) > 20000){

 Serial.println("--CHANGING MASK COLOR--");   

  randomChoosenColor = randomColorProgram(); 
  strip_mask_four.fill(randomChoosenColor, startingMaskOneLED, maskOneLEDCount); 
  randomChoosenColor = randomColorProgram();
  strip_mask_four.fill(randomChoosenColor, startingMaskTwoLED, maskTwoLEDCount);
  randomChoosenColor = randomColorProgram();
  strip_mask_four.fill(randomChoosenColor, startingMaskThreeLED, maskThreeLEDCount);
  randomChoosenColor = randomColorProgram();
  strip_mask_four.fill(randomChoosenColor, startingMaskFourLED, maskFourLEDCount);
  strip_mask_four.show();

  randomChoosenColor = randomColorProgram(); 
  strip_mask_four_2.fill(randomChoosenColor, startingMaskOneLED_2, maskOneLEDCount_2);
  randomChoosenColor = randomColorProgram(); 
  strip_mask_four_2.fill(randomChoosenColor, startingMaskTwoLED_2, maskTwoLEDCount_2);
  randomChoosenColor = randomColorProgram();     
  strip_mask_four_2.fill(randomChoosenColor, startingMaskThreeLED_2, maskThreeLEDCount_2);
  randomChoosenColor = randomColorProgram();       
  strip_mask_four_2.fill(randomChoosenColor, startingMaskFourLED_2, maskFourLEDCount_2);
  strip_mask_four_2.show();

  randomChoosenColor = randomColorProgram(); 
  strip_mask_four_3.fill(randomChoosenColor, startingMaskOneLED_3, maskOneLEDCount_3);
  randomChoosenColor = randomColorProgram(); 
  strip_mask_four_3.fill(randomChoosenColor, startingMaskTwoLED_3, maskTwoLEDCount_3);   
  randomChoosenColor = randomColorProgram();   
  strip_mask_four_3.fill(randomChoosenColor, startingMaskThreeLED_3, maskThreeLEDCount_3);
  randomChoosenColor = randomColorProgram(); 
  strip_mask_four_3.fill(randomChoosenColor, startingMaskFourLED_3, maskFourLEDCount_3);
  strip_mask_four_3.show();
 
previousMillsChangeMaskColor = currentMillisChangeMaskColor;

}

}



//-------------------------------------------------------------------------------------
//                                     RandomColorProgram                             -
//-------------------------------------------------------------------------------------


int randomColorProgram()  {
  Serial.println("-----------------------RUNNING RANDOM COLOR PROGRAM------------------------");
 

  int tempRandomColor = random(1,7);
  uint32_t tempChoosenColor;
 
 
  if (tempRandomColor == 1) {
    tempChoosenColor = purple;   
  }
  if (tempRandomColor == 2) {
    tempChoosenColor = orange;   
  }

   if (tempRandomColor == 3) {
    tempChoosenColor = white;   
  }
  if (tempRandomColor == 4) {
    tempChoosenColor = green;   
  }
  if (tempRandomColor == 5) {
    tempChoosenColor = blue;   
  }
   if (tempRandomColor == 6) {
    tempChoosenColor = yellow;   
  }


return tempChoosenColor;


}

Baylordawg
 
Posts: 15
Joined: Thu Dec 20, 2018 4:24 pm

Re: Grand Central Express M4s Not Behaving Normally

by adafruit_support_carter on Mon Oct 12, 2020 7:11 pm

Try running the code with the NeoPixel strips disconnected. Does this still happen?
As soon as I upload this code I get an error on my Windows machine saying USB device is no longer recolonized and I can't get to the serial monitor anymore.


Also check to see if Windows is re-assigning the COM port number after a sketch upload / reset.

adafruit_support_carter
 
Posts: 20609
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.