Adafruit ItsyBitsy nRF52840 Express - Not working

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
bobzai2015
 
Posts: 8
Joined: Tue Nov 15, 2022 11:39 pm

Adafruit ItsyBitsy nRF52840 Express - Not working

Post by bobzai2015 »

I have an Adafruit ItsyBitsy nRF52840 Express. In the first few days of playing with the microcontroller, I would upload code from the Arduino IDE and the code would be on-board. The red LED on the board would be glowing, indicating that the board was on/powered and that BLE was enabled. However, recently, I have tried uploading code and after uploading the new code, the LED powers off, despite being connected to the computer. When I disconnect from the computer and power with an external power supply, the LED no longer turns on.

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

Re: Adafruit ItsyBitsy nRF52840 Express - Not working

Post by adafruit_support_carter »

Can you get the basic Blink example to work?

Code: Select all

#if defined(USE_TINYUSB)
#include <Adafruit_TinyUSB.h> // for Serial
#endif

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

User avatar
bobzai2015
 
Posts: 8
Joined: Tue Nov 15, 2022 11:39 pm

Re: Adafruit ItsyBitsy nRF52840 Express - Not working

Post by bobzai2015 »

Hi, yes the Blink script works - the BLE LED is also on. The code we are trying to run on the microcontroller is below:

Code: Select all

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 5, 7, 9, 10);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(160);
  // initialize the serial port:
  pinMode(5, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  digitalWrite(11, HIGH);
  digitalWrite(12, HIGH);
}

void loop() {
  // step one revolution  in one direction:
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  myStepper.step(-stepsPerRevolution);
  delay(500);
}
Is it possibly the USB stack?

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

Re: Adafruit ItsyBitsy nRF52840 Express - Not working

Post by adafruit_support_carter »

However, recently, I have tried uploading code and after uploading the new code, the LED powers off, despite being connected to the computer.
Which LED are you referring to here? There's nothing in your example code that is driving an LED.

User avatar
bobzai2015
 
Posts: 8
Joined: Tue Nov 15, 2022 11:39 pm

Re: Adafruit ItsyBitsy nRF52840 Express - Not working

Post by bobzai2015 »

Sorry, I was referring to the BLE LED.

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

Re: Adafruit ItsyBitsy nRF52840 Express - Not working

Post by adafruit_support_carter »

Is your code working OK otherwise? It looks like it's driving a stepper motor. Since the code is not doing anything specific with the LEDs, then don't worry about what the LEDs are doing / not doing.

User avatar
bobzai2015
 
Posts: 8
Joined: Tue Nov 15, 2022 11:39 pm

Re: Adafruit ItsyBitsy nRF52840 Express - Not working

Post by bobzai2015 »

The issue is that when the board's BLE LED is off (even when powered and no bluetooth code is being implemented), the board has to be reset before I can upload code again.

There are times when I have uploaded BLE-code (like the code below [modified from example code]) and the board will work, but then other times when the same exact code causes the board to become unresponsive (not working and BLE LED is off, needs to be reset). Is this a common occurrence? Is it possible this has to do with how I am uploading the code?

Code: Select all

/*********************************************************************
 This is an example for our nRF52 based Bluefruit LE modules

 Pick one up today in the adafruit shop!

 Adafruit invests time and resources providing this open source code,
 please support Adafruit and open-source hardware by purchasing
 products from Adafruit]\

 MIT license, check LICENSE for more information
 All text above, and the splash screen below must be included in
 any redistribution
*********************************************************************/

#include <bluefruit.h>

// OTA DFU service
BLEDfu bledfu;

// Uart over BLE service
BLEUart bleuart;

// Function prototypes for packetparser.cpp
uint8_t readPacket (BLEUart *ble_uart, uint16_t timeout);
float   parsefloat (uint8_t *buffer);
void    printHex   (const uint8_t * data, const uint32_t numBytes);

// Packet buffer
extern uint8_t packetbuffer[];

void setup(void)
{
  Serial.begin(115200);
  while ( !Serial ) delay(10);   // for nrf52840 with native usb

  Serial.println(F("Adafruit Bluefruit52 Controller App Example"));
  Serial.println(F("-------------------------------------------"));

  Bluefruit.begin();
  Bluefruit.setTxPower(4);    // Check bluefruit.h for supported values

  // To be consistent OTA DFU should be added first if it exists
  bledfu.begin();

  // Configure and start the BLE Uart service
  bleuart.begin();

  // Set up and start advertising
  startAdv();

  Serial.println(F("Please use Adafruit Bluefruit LE app to connect in Controller mode"));
  Serial.println(F("Then activate/use the sensors, color picker, game controller, etc!"));
  Serial.println();  

  pinMode(7, OUTPUT); 
  pinMode(11, OUTPUT);
}

void startAdv(void)
{
  // Advertising packet
  Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
  Bluefruit.Advertising.addTxPower();
  
  // Include the BLE UART (AKA 'NUS') 128-bit UUID
  Bluefruit.Advertising.addService(bleuart);

  // Secondary Scan Response packet (optional)
  // Since there is no room for 'Name' in Advertising packet
  Bluefruit.ScanResponse.addName();

  /* Start Advertising
   * - Enable auto advertising if disconnected
   * - Interval:  fast mode = 20 ms, slow mode = 152.5 ms
   * - Timeout for fast mode is 30 seconds
   * - Start(timeout) with timeout = 0 will advertise forever (until connected)
   * 
   * For recommended advertising interval
   * https://developer.apple.com/library/content/qa/qa1931/_index.html   
   */
  Bluefruit.Advertising.restartOnDisconnect(true);
  Bluefruit.Advertising.setInterval(32, 244);    // in unit of 0.625 ms
  Bluefruit.Advertising.setFastTimeout(30);      // number of seconds in fast mode
  Bluefruit.Advertising.start(0);                // 0 = Don't stop advertising after n seconds  
}

/**************************************************************************/
/*!
    @brief  Constantly poll for new command or response data
*/
/**************************************************************************/
void loop(void)
{
  // Wait for new data to arrive
  uint8_t len = readPacket(&bleuart, 500);
  if (len == 0) return;

  // Got a packet!
  // printHex(packetbuffer, len);

  // Color
  if (packetbuffer[1] == 'C') {
    uint8_t red = packetbuffer[2];
    uint8_t green = packetbuffer[3];
    uint8_t blue = packetbuffer[4];
    Serial.print ("RGB #");
    if (red < 0x10) Serial.print("0");
    Serial.print(red, HEX);
    if (green < 0x10) Serial.print("0");
    Serial.print(green, HEX);
    if (blue < 0x10) Serial.print("0");
    Serial.println(blue, HEX);
  }

  // Buttons
  if (packetbuffer[1] == 'B') {
    uint8_t buttnum = packetbuffer[2] - '0';
    boolean pressed = packetbuffer[3] - '0';
    Serial.print ("Button "); Serial.print(buttnum);
    if (pressed) {
      Serial.println(" pressed");
      if (buttnum == 5){
        digitalWrite(7, HIGH);
        digitalWrite(11, LOW);
      } else if (buttnum == 6){
        digitalWrite(7, LOW);
        digitalWrite(11, HIGH);
      } else {
        digitalWrite(7, LOW);
        digitalWrite(11, LOW);
      }
    } else {
      Serial.println(" released");
      digitalWrite(7, LOW);
      digitalWrite(11, LOW);
    }    
  }

  // GPS Location
  if (packetbuffer[1] == 'L') {
    float lat, lon, alt;
    lat = parsefloat(packetbuffer+2);
    lon = parsefloat(packetbuffer+6);
    alt = parsefloat(packetbuffer+10);
    Serial.print("GPS Location\t");
    Serial.print("Lat: "); Serial.print(lat, 4); // 4 digits of precision!
    Serial.print('\t');
    Serial.print("Lon: "); Serial.print(lon, 4); // 4 digits of precision!
    Serial.print('\t');
    Serial.print(alt, 4); Serial.println(" meters");
  }

  // Accelerometer
  if (packetbuffer[1] == 'A') {
    float x, y, z;
    x = parsefloat(packetbuffer+2);
    y = parsefloat(packetbuffer+6);
    z = parsefloat(packetbuffer+10);
    Serial.print("Accel\t");
    Serial.print(x); Serial.print('\t');
    Serial.print(y); Serial.print('\t');
    Serial.print(z); Serial.println();
  }

  // Magnetometer
  if (packetbuffer[1] == 'M') {
    float x, y, z;
    x = parsefloat(packetbuffer+2);
    y = parsefloat(packetbuffer+6);
    z = parsefloat(packetbuffer+10);
    Serial.print("Mag\t");
    Serial.print(x); Serial.print('\t');
    Serial.print(y); Serial.print('\t');
    Serial.print(z); Serial.println();
  }

  // Gyroscope
  if (packetbuffer[1] == 'G') {
    float x, y, z;
    x = parsefloat(packetbuffer+2);
    y = parsefloat(packetbuffer+6);
    z = parsefloat(packetbuffer+10);
    Serial.print("Gyro\t");
    Serial.print(x); Serial.print('\t');
    Serial.print(y); Serial.print('\t');
    Serial.print(z); Serial.println();
  }

  // Quaternions
  if (packetbuffer[1] == 'Q') {
    float x, y, z, w;
    x = parsefloat(packetbuffer+2);
    y = parsefloat(packetbuffer+6);
    z = parsefloat(packetbuffer+10);
    w = parsefloat(packetbuffer+14);
    Serial.print("Quat\t");
    Serial.print(x); Serial.print('\t');
    Serial.print(y); Serial.print('\t');
    Serial.print(z); Serial.print('\t');
    Serial.print(w); Serial.println();
  }
}

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

Re: Adafruit ItsyBitsy nRF52840 Express - Not working

Post by adafruit_support_carter »

The on/off state of the LED is potentially a red herring. Since nothing in the code is directly controlling the pin the LED is attached to, its behavior is coincidental.

Sometimes the running sketch can get in a bad state which does cause the board to become unresponsive to new uploads. The sketch being in a bad state prevents the board from being software reset to reset to accept a new sketch upload. Manually resetting is the work around for this.

But that does not determine why the original sketch got in a bad state in the first place. Determining that can be tricky. See if you can better correlate when the board gets in that state with a given sketch. Ideally, see if you can come up with the smallest simplest sketch that can demonstrate the issue.

User avatar
bobzai2015
 
Posts: 8
Joined: Tue Nov 15, 2022 11:39 pm

Re: Adafruit ItsyBitsy nRF52840 Express - Not working

Post by bobzai2015 »

The code I posted above is from the BLE example library and doesn't pose problems on its own. When I add in the digitalWrite lines, however, we sometimes experience problems and sometimes do not have issues. Is there something about digitalWrite for the ItsyBitsy firmware that is not compatible?

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

Re: Adafruit ItsyBitsy nRF52840 Express - Not working

Post by adafruit_support_carter »

If the problems only occur "sometimes" then it can be tricky to determine the cause. It helps to be able to somehow determine a correlation with something. There's weak correlation to usage of digitalWrite. However, there generally should not be any issue using that method. So it may be related, but the real issue is something else.

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

Return to “Itsy Bitsy Boards”