-1

Minimal working example:

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  noInterrupts();
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
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
}

When uploaded to my Arduino Nano 3.3v BLE from my M1 Mac, this causes the Nano to no longer appear in the ports menu. In order to get it to appear again, I have to double press the reset button on the Nano so that it resets to a default script. After doing this, the Nano is available in the ports menu again.

I also cannot see the Nano via cat /dev/cu.<TAB> when this script is uploaded to it.

Does anyone know why this happens? Or alternatively (if this is intended behaviour) why it is not documented in interrupts() or noInterrupts?

I've looked through some other posts, but I don't think they're duplicates of this one:

Edits in response to answers

So the MWE wasn't quite descriptive enough of my problem and some of the answers got caught up on that (which is my fault). I've included a more detailed description of what I'm doing below to describe what I'm actually doing, but I've also accepted the answer which I think answers the heart of the question "why do interrupts cause the Nano to not appear in port?".

What I'm actually doing is I've got two Arduino Nanos (call them primary and secondary) connected via I2C and Wire.h. Each Arduino nano is reading 15 analog inputs (via a multiplexer). The secondary Nano is then sending its 15 analog readings to the primary over I2C. But I'm getting a lot of noise in the analog readings of the primary Nano, but no noise in the secondary. This noise disappears when I disconnect I2C. So my theory was that digital SCL and SDA wires were causing noise in the analog sensor wires, but I observed the noise would only occur for ~2ms every ~10ms. I thought I'd disable interrupts (and therefor disable Wire.h from pulsing SCL/SDA) while I was reading the primary's analog sensors, and enable interrupts afterwards. This caused the Nano to not appear in the Ports tab, and the rest is the result of this post.

I now think I didn't include the 4.7Ohm pull-up resistor on SDA and SCL which seems to only be included on the official Arduino examples, and never on any random internet examples.

2
  • I have no idea what an MWE and you have edited your question to the point where where my answer was no longer in sync with it.
    – timemage
    Jun 29, 2022 at 12:38
  • Apologies, MWE=Minimum working example.
    – beyarkay
    Jun 29, 2022 at 13:43

1 Answer 1

2

I'm not really an expert on the Nano 3.3v BLE, however it appears that it is directly connected to the USB port and thus disabling interrupts will also disable its ability to respond to USB handshakes, thus it will appear to the host that it has been unplugged.

The original Nano had a separate chip (FT232RL) which handled the USB interface, and thus disabling interrupts on that Arduino would not drop the USB connection.

Or alternatively (if this is intended behaviour) why it is not documented in interrupts() or noInterrupts?

Probably the documentation has not kept up-to-date with later product releases. It is not uncommon for documentation to lag behind what the released products actually do.

As timemage points out in another answer, your attempts to blink LEDs with interrupts turned off will not succeed. In fact, turning interrupts off should only be done for milliseconds, not permanently. I assume that is a demonstration sketch, but still ... if you turn interrupts off only briefly the problem should go away.

4
  • Yeah, I'd tacked on the clarification about the typical time scale about two minutes before this answer came in. So it probably wasn't in there when you were composing. It's a good point about the documentation. So much of it is really oriented toward the early boards.
    – timemage
    Jun 29, 2022 at 12:00
  • Thanks! Yeah the LED part of the MWE wasn't really relevant to the full problem, but you still answered the root question of why this happens. I'm gonna submit a PR to update the docs. Any idea if this is just the Nano, or if it's other boards as well?
    – beyarkay
    Jun 29, 2022 at 12:18
  • It wouldn't surprise me if it related to the more modern boards with the new processors, however I'm not on top of which ones they may be.
    – Nick Gammon
    Jun 29, 2022 at 12:20
  • @NickGammon I got rid of my answer. Their question is apparently about I2C now... or something. Not interested in chasing the redefinition.
    – timemage
    Jun 29, 2022 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.