Help using pins D6 and D7 (Serial/uart) on esp32s3 as GPIO output

Hello, I’m having dificulty using pins D6 and D7 as GPIO output in my project. I’ve included my code below, which should cycle through D5-9, turning each one high for 1 second, but pins D6 and D7 stay high all the time. I think this is due to them being used by serial, but I’m not sure. I’ve tried using serial.end(), and I’ve tried disabling USB CDC on boot, neither seem to have done anything. Any help or tips would be appreciated!

/*
  Keyboard Message test

  For the Arduino Leonardo and Micro.

  Sends a text string when a button is pressed.

  The circuit:
  - pushbutton attached from pin 0 to ground
  - 10 kilohm resistor attached from pin 0 to +5V

  created 24 Oct 2011
  modified 27 Mar 2012
  by Tom Igoe
  modified 11 Nov 2013
  by Scott Fitzgerald

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/KeyboardMessage
*/
#ifndef ARDUINO_USB_MODE
#error This ESP32 SoC has no Native USB interface
#elif ARDUINO_USB_MODE == 1
#warning This sketch should be used when USB is in OTG mode
void setup() {}
void loop() {}
#else

#include "USB.h"
#include "USBHIDKeyboard.h"
USBHIDKeyboard Keyboard;

void setup() {
    Serial1.end();
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);
    
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    // initialize control over the keyboard:
    Keyboard.begin();
    USB.begin();
}

void loop() {
    for (int c = 5; c < 10; c++) {
        digitalWrite(c, HIGH);
         delay(1000);
        digitalWrite(c, LOW);
    }
}
#endif /* ARDUINO_USB_MODE */
1 Like

Keeping this posted in case anyone else finds this problem, had to use pin reference 43 for D6 and 44 for D7, from this post.