Page 1 of 1

How to use USB pins?

Posted: Sun Apr 19, 2020 10:29 am
by forfrends
Hello. I encountered a restriction on the use of pins. I need to use USB pins (PA11 and PA12) for my own purposes. But if I write a simple sketch, then the pin switching does not happen:

Code: Select all

#define Pin1 PA11
#define Pin2 PA12

void setup() {
    pinMode(Pin1, OUTPUT);
    pinMode(Pin2, OUTPUT);
}

void loop() {
    digitalWrite(Pin1, LOW);
    digitalWrite(Pin2, LOW);
    delay(1000);
    digitalWrite(Pin1, HIGH);
    digitalWrite(Pin2, HIGH);
    delay(1000);
}
It seems that somewhere these pins are used, possibly USB Serial. Can I use these pins somehow?

Re: How to use USB pins?

Posted: Sun Apr 19, 2020 10:49 am
by mrburnette
From: http://docs.leaflabs.com/docs.leaflabs.com/index.html GPIO Information

Pin D23 (PA12) is the USB D+ line, and D24 (PA11) is the USB D- line. To use them as GPIOs, your program will need to disable SerialUSB first. Be aware, however, that disabling SerialUSB means that the bootloader won’t work properly, and you’ll need to use Perpetual Bootloader Mode to make your next upload.
Ray

Re: How to use USB pins?

Posted: Sun Apr 19, 2020 1:15 pm
by forfrends
Thanks!
Can you tell me how to disable SerialUSB?

Re: How to use USB pins?

Posted: Sun Apr 19, 2020 3:38 pm
by stevestrong

Code: Select all

Serial.end();

Re: How to use USB pins?

Posted: Sun Apr 19, 2020 5:31 pm
by forfrends
Thank you, you helped me a lot!