Nesso N1: Brownout using tone()

After using NessoN1 on the issued USB cable and successfully compiling, uploading and running many sketches, I started working on my "tones" section using tone() in setup() when NessoN1 rebooted and restarted setup().

I tried another tone() sketch and the sketch worked without issue.

the "good" sketch
/*
  sit - SPECIAL INFORMATION TONE

  (Frequency Hz) Cadence (S): (913.8) 0.274 ON (1370.6) 0.274 ON (1776.7) 0.38 ON 1.0 OFF.

  https://en.wikipedia.org/wiki/Special_information_tone
*/

char text[] = { "We're sorry. You have reached a number that has been disconnected or is no longer in service. If you feel you have reached this recording in error, please check the number, and try your call again." };
int textsize = sizeof(text) / sizeof(text[0]);

float sitfreq[] = { 913.8, 1370.6, 1776.7, 0 };
int duration[] = { 274, 274, 380, 1000 };

unsigned long timer;
byte i;

byte slowbaud = 40; // teletype effect

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println();
  pinMode(BEEP_PIN, OUTPUT);
}

void loop() {
  printText();
}

void printText() {
  if (millis() - timer > slowbaud) { // slow text output
    timer = millis();
    if (i == textsize - 1) {
      Serial.println();
      makeTone();  // text complete, now tone
      i = 0;
    }
    Serial.print(text[i]);
    i++;
  }
}

void makeTone() {
  delay(250);
  for (byte i = 0; i < 4; i++) {
    tone(BEEP_PIN, sitfreq[i]);
    delay(duration[i]);
  }
  noTone(BEEP_PIN);
}

I tried a third tone() sketch and got this crash, reboot, and warning...

0E BOD: Brownout detector was triggered


ESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x3 (LP_SW_HPSYS),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x4001974a
SPIWP:0xee
mode:DIO, clock div:2
load:0x40875730,len:0x12e0
load:0x4086b910,len:0xdc8
load:0x4086e610,len:0x3180
entry 0x4086b910
One of the "bad" sketches
// passive buzzer musical scales
// keyboard scale:  https://i.pinimg.com/originals/cf/72/9a/cf729ae2213a849fe6b8cc527a0e7471.png

#include <Arduino_Nesso_N1.h>
#include "freqs.h"  // adapted from pitches.h:  https://gist.github.com/mikeputnam/2820675

int duration, dur = 200;
const int notes = 10;
const int scales = 12;

const int scale[scales][notes] = {
  // N = natural S = sharp
  // O-   W    W    H    W    W    H    W    W    S      // Octave lower, Whole-step, Half-step
  { CN3, CN4, DN4, EN4, FN4, GN4, FN4, EN4, DN4, CN4 },  // C
  { CS3, CS4, DS4, FN4, FS4, GS4, FS4, FN4, DS4, CS4 },  // C#
  { DN3, DN4, EN4, FS4, GN4, AN4, GN4, FS4, EN4, DN4 },  // D
  { DS3, DS4, FN4, GN4, GS4, AS4, GS4, GN4, FN4, DS4 },  // D#
  { EN3, EN4, FS4, GS4, AN4, BN4, AN4, GS4, FS4, EN4 },  // E
  { FN3, FN4, GN4, AN4, AS4, CN5, AS4, AN4, GN4, FN4 },  // F
  { FS3, FS4, GS4, AS4, BN4, CS5, BN4, AS4, GS4, FS4 },  // F#
  { GN3, GN4, AN4, BN4, CN5, DN5, CN5, BN4, AN4, GN4 },  // G
  { GS3, GS4, AS4, CN5, CS5, DS5, CS5, CN5, AS4, GS4 },  // G#
  { AN3, AN4, BN4, CS5, DN5, EN5, DN5, CS5, BN4, AN4 },  // A
  { AS3, AS4, CN5, DN5, DS5, FN5, DS5, DN5, CN5, AS4 },  // A#
  { BN3, BN4, CS5, DS5, EN5, FS5, EN5, DS5, CS5, BN4 }   // B
};

void setup() {
  Serial.begin(115200);
  delay(3000);  // Nesso needs a delay to connect before output to Serial Monitor
  Serial.println();
  pinMode(KEY1, INPUT_PULLUP);

  Serial.println("Press KEY1");
  while (digitalRead(KEY1)) {};  // wait for KEY1 press
  delay(500);                    // slight delay

  for (byte j = 0; j < scales; j++) {
    if (j + 1 < 10)
      Serial.print(" ");  // alignment
    Serial.print(j + 1);  // counting numbers
    Serial.print(" of ");
    Serial.print(scales);
    Serial.print(" scales in fifths: ");

    for (byte i = 0; i < notes; i++) {
      Serial.print(i);
      if (i == 0 || i == 9)  // first and last note in scale
        duration = dur * 2;  // double note duration
      else
        duration = dur;
      tone(BEEP_PIN, scale[j][i], duration);
      delay(duration);
    }
    noTone(BEEP_PIN);  // end tone
    Serial.println();
  }
}

void loop() {}

Reading the forum... one solution was "bad USB cable"... not the problem here... another was "setting fuses on the ESP32".... um... would Arduino do that to Nesso?... another was a peripheral was pulling the ESP into brownout... and this one was something with "Wire.h" (maybe interrupts shared with Wire.h and tone()?

Maybe I found the magic "brown-note" (musicians might know about it)... but I want to avoid it. My plan is to step through every note I have tried to produce, looking for that m*.

Sorry for breaking Nesso every day.

I’m wondering if it’s just your battery is getting low due to never being told to charge??

load a sketch that show battery level..

or it’s just too cold, brrr..

strange.. ~q

I never disconnect Nesso from USB, or I two-press RESET/BOOT/OFF verifying a disconnect.

Checking with mazes (battery indicator)...

in the last release of mazes i still had battery charging off, so make sure to turn it on..

~q

Is the "don't use Nesso battery charging" warning over? I thought a warning was sent out.

nope it’s over with that release of the esp32 core that added battery management..

but we still do have to tell it to charge..

~q

!Battery at 3.3v... 8%... Charging enabled (battery.enableCharge();)... up to 3.7v and climbing. Changes seen when KEY1 is pressed. Thank you for this utility. I am now reading up on M5 and Nesso battery code.

Two hours later... update on power display in mazes... charge level at 4.1, but progress bar and % "seem" static at 13% (I think that was when the voltage read 3.7v). Pressing RESET or KEY1 updated and show 4.2v and 14%... but another hour later, remained 4.2/14.

Nesso N1 battery sketch reports... https://docs.arduino.cc/tutorials/nesso-n1/user-manual/#battery-management

Voltage: 4.19 V, Percentage: 100 %, Charging: Yes

M5 battery routine reports... m5-docs
(no camera)

"Bat: 4192mv, Level: 100%, Charging: NO"

did you re-test the tone sketches??

just hope it stops all the brownouts..

~q

Returning to mazes... 4.2v and 100%.

Works like a champ!

Press KEY1
 1 of 12 scales in fifths: 0123456789
 2 of 12 scales in fifths: 0123456789
 3 of 12 scales in fifths: 0123456789
 4 of 12 scales in fifths: 0123456789
 5 of 12 scales in fifths: 0123456789
 6 of 12 scales in fifths: 0123456789
 7 of 12 scales in fifths: 0123456789
 8 of 12 scales in fifths: 0123456789
 9 of 12 scales in fifths: 0123456789
10 of 12 scales in fifths: 0123456789
11 of 12 scales in fifths: 0123456789
12 of 12 scales in fifths: 0123456789

Thank you for your help, again!

From of this issue, and because of your help, I load this Nesso N1 template so I know the Nesso N1 is "running" and the battery does not fully discharge. Thank you.

#include <Arduino_Nesso_N1.h>
NessoBattery battery;  // create battery instance

unsigned long blinkTimer, blinkInterval[] = { 100, 900 };  // ON for 100ms/1000ms
bool blinkState = 0;                                       // state for LED_BUILTIN

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);  // configure LED_BUILTIN
  battery.begin();               // initialize battery instance
  battery.enableCharge();        // Enable charging
}

void loop() {
  if (millis() - blinkTimer >= blinkInterval[blinkState]) {  // test for interval
    blinkTimer = millis();                                   // store timer
    blinkState = !blinkState;                                // toggle state
    digitalWrite(LED_BUILTIN, blinkState);                   // set LED_BUILTIN state
  }
}