USB device not recognized

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
Beamz
 
Posts: 9
Joined: Mon Apr 11, 2022 2:58 pm

USB device not recognized

Post by Beamz »

Hello,

I am having trouble with transferring code from Metro M4 Express to other boards. I potentially do not know what I am doing so hopefully I am just missing some key information.

I have code that works well on a Metro M4 Express in Arduino IDE, even though the UF2 bootloader has not been updated. I want to save mass so I have tried to use the same code on other boards without success. (Itsy Bitsy 5V 32u4, Metro Mini, Feather M4 Express, and Itsy Bitsy M4 Express.)

When I use the code on Itsy Bitsy 5V 32u4 and Metro Mini, the serial ports do not seem to be communicating do I do not see the expected data in my serial monitor.

When I use Feather M4 Express, and Itsy Bitsy M4 Express, both boards give me the following error:
USB Malfunction.png
USB Malfunction.png (85.08 KiB) Viewed 139 times
I did update the bootloader on the Itsy Bitsy M4 Express to see if that is the issue but I received the same error.

Thank you for any help!

User avatar
Beamz
 
Posts: 9
Joined: Mon Apr 11, 2022 2:58 pm

Re: USB device not recognized

Post by Beamz »

Here is the code that is only working on the Metro M4 Express:

Code: Select all

// Last updated by: Mark DeLoura
// UPDATED: 12/17/2021

#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include <TRSim_Up.h>

/* UP Launch demo
 *   This simple demo reads data coming from the Future Engineers TechRise web-based simulator.
 *   It is designed to run on a Metro M4 Express and uses the on-board Neopixel.
 *   The demo runs a simple update loop, and does three actions:
 *     1 - Keeps track of the number of telemetry packets received
 *     2 - Monitors for new events and prints a message each time one occurs
 *     3 - Prints out every 100th telemetry packet
 */

// pin mappings
#define PIN_NEOPIXEL     40

// neopixel constants
#define NEOPIXEL_QUANTITY 1
#define NEOPIXEL_BRIGHTNESS 0.2

// Set up events
#define EVENTS_QUANTITY 8
typedef struct _eventDetails {
  uint16_t value;
  const char* description;
  uint32_t color;
} EventDetails;
EventDetails events[] = {
  {TRSim_Up::EVENT_LIFTOFF, "Liftoff", 0xff0000},
  {TRSim_Up::EVENT_BURNOUT, "Booster Burnout", 0x00ff00},
  {TRSim_Up::EVENT_DESPIN, "De-spin Deployment", 0x0000ff},
  {TRSim_Up::EVENT_MICROGRAVITY_START, "Microgravity Start", 0xffff00},
  {TRSim_Up::EVENT_SEPARATION, "Separation From Booster", 0xff00ff},
  {TRSim_Up::EVENT_MICROGRAVITY_END, "Microgravity End", 0x00ffff},
  {TRSim_Up::EVENT_DROGUE, "Drogue Deployed", 0xff7777},
  {TRSim_Up::EVENT_MAIN, "Main Chutes Deployed", 0x7777ff}
};


// Set up Neopixels
Adafruit_NeoPixel pixels(NEOPIXEL_QUANTITY, PIN_NEOPIXEL); // , NEO_GRB + NEO_KHZ800);

// Set up Simulator
TRSim_Up::Simulator TRsim;

// Variables for tracking events
uint16_t currEvents = 0;
uint16_t prevEvents = 0;
uint16_t newEvents = 0;
// Variable for tracking number of full telemetry packets received
int numPackets = 0;

unsigned char* data;

char outputString[120];

void serialPrintPacket();

// setup()
//   Initialization functions
//
void setup() {
  // Serial = USB
  // FESim = Serial1 = UART
  Serial.begin(115200);
  TRsim.init(2,3); 

  Serial.println("Running UP Launch demo");

  // Neopixels
  pixels.begin();
  pixels.setBrightness(255*NEOPIXEL_BRIGHTNESS);
  pixels.fill(0x777777, 0, NEOPIXEL_QUANTITY);
  pixels.show();
}

// loop()
//   Do forever
//
void loop() {
  // Update the simulator to catch serial input
  TRsim.update();

  // If there is a new full telemetry packet, do some operations on it
  if (TRsim.isStreaming() == true) {
    if (TRsim.isNewData() == true) {
      // Got a new telemetry packet!
      numPackets += 1;

      // Grab new data - NOTE this sets isNewData to false!
      data = TRsim.getData();

      // If a new event has fired, identify it and print it out
      currEvents = TRsim.getEvents();
      if (currEvents != prevEvents) {
        newEvents = currEvents ^ prevEvents;
        // Find events in event structure (there may be multiple!)
        for (int i=0; i<EVENTS_QUANTITY; i++) {
          if (TRsim.getEvents()== events[i].value) {
            Serial.print("Event: ");
            Serial.println(events[i].description);

            pixels.fill(events[i].color, 0, NEOPIXEL_QUANTITY);
            pixels.show();
          } 
        }
        prevEvents = currEvents;
      }
      
      // Print every 100th packet to verify data
      if ((numPackets % 100) == 1) {
        serialPrintPacket();
      }
    }
  }

  delay(10);
  
}


void serialPrintPacket() {
  serialPrintHexString(data);

// Next two were not included in the simulation
  //Serial.print("String: ");
  //Serial.println(TRsim.dataString());

//Packets originally included but // to exclude it from serial monitor.
  //Serial.print("packetNumber ");
  //Serial.println(TRsim.getPacketNumber());
  //Serial.print("time ");
  //Serial.println((unsigned long)TRsim.getTime());
  //Serial.print("bootNumber ");
  //Serial.println(TRsim.getBootNumber());
  //Serial.print("ordnanceVoltage ");
  //Serial.println(TRsim.getOrdnanceVoltage());
  //Serial.print("controllerVoltage ");
  //Serial.println(TRsim.getControllerVoltage());
  //Serial.print("avionicsTemperature ");
  //Serial.println(TRsim.getAvionicsTemperature());
  //Serial.print("pressure ");
  //Serial.println(TRsim.getPressure());
  //Serial.print("accelerationX ");
  //Serial.println(TRsim.getAccelerationX());
  //Serial.print("accelerationY ");
  //Serial.println(TRsim.getAccelerationY());
  //Serial.print("accelerationZ ");
  //Serial.println(TRsim.getAccelerationZ());
  //Serial.print("payloadVoltage ");
  //Serial.println(TRsim.getPayloadVoltage());
  //Serial.print("payloadTemperature ");
  //Serial.println(TRsim.getPayloadTemperature());
}

void serialPrintHexString(unsigned char* buff) {
  int cursor = 0;
  
  for (int i=0; i<45; i++) {
    sprintf(&(outputString[cursor]), "%02x", buff[i]);
    cursor += 2;
  }
  outputString[cursor] = 0;
  
  Serial.println(outputString);  
}

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

Return to “Itsy Bitsy Boards”