Certain pin names cause the Pico to disconnect.

Posted on
  • I am running a try {} block in which i test each possible pin name to see if it will respond to a digitalWrite.

    var pins = [A0,A1,A2,A3,A4,A5,A6,A7,A8,A10,
    var i; for (i = 0; i < pins.length; i++) {
      var pintrial = true;
      try {
      } catch(e) {
        pintrial = false; console.log(e);
      } finally {

    Neither B2 or A9 exist on the pico board, but B2 is accepted by this pin testing approach and A9 causes the device to disconnect itself.

    Does anybody have an explanation for this? I can work around it, but I'm curious nonetheless.

  • I think I'm going to answer my own question...

    Pin A9 of the on-board STM32 microcontroller is always connected to the fused USB 5V voltage reference.
    The digitalWrite function essentially connects the USB voltage pin to GND, thus creating a short circuit on the USB port. This means there is no longer power going to the board AT ALL. It has been "disconnected".


  • Yeah, the 'other' pins are all shown here, with what they're connected to (if you hover over the tags): http://www.espruino.com/Pico#pinout

    Setting A9's not going to be great for the chip - it's just left available in case someone wants to use it (eg if USB isn't connected). In the absolute latest revision of the board it's actually connected via a resistor to minimize damage though.

    digitalWrite won't throw an exception unless you give it an invalid pin name like "foo" - it'll just tell the hardware what to set the pin to - whether or not the hardware will actually do that or not depends on how it's set up and is pretty complex :) In the case of the IO brought out on pins it should 'just work'.

  • Is there away to programatically list all physical pins, (or better) all global variables?

  • What use would that have outside of testing? Or are you writing tests for Espruino to validate modified builds or something?

  • You can just do Object.keys(global) I think. The pins themselves aren't listed, but you could try getPinMode(0)/1/2/... all the way up until you get an exception (since getPinMode won't change pin state)

    But again, if you just try what you did above with all pins you could damage your board (and will definitely break USB), as you have no idea what they're connected to when you set them to something.

  • Hmm good point DrAzzy. I'm attempting to make a virtual pin registry for in case I want to use multiplexers and shift registers in tandem with each other. In a custom wrapper for espruino, those devices could be used as a source of pins, by switching the selector pins in the background to accommodate calls to a virtual pin. I have already created a workaround without too many lines. But I will try Object.keys(global) . I totally forgot about javascript being rooted in Java where everything stems from the Object object lol. And thanks for getPinMode Gordon. It's definitely worth it to leave pins such as A9 usable by any project.

    My workaround so far is such that I create virtual pin objects starting with 'Z0' through 'Z7' when initiating a 74HC595 shift register, then slapping them with a "digital output only" flag.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Certain pin names cause the Pico to disconnect.

Posted by Avatar for user66772 @user66772