Using Portenta H7 GPIOs via Portenta Hat Carrier

Hello,
I recently acquired the Portenta H7 and the Hat Carrier. I followed the tutorial (https://docs.arduino.cc/tutorials/portenta-h7/setting-up-portenta/), and the LED_BUILTIN blinking works fine, but now I would like to test the Push Button (PB1) available on the Hat Carrier, which is connected to GPIO1. The issue is that I can't seem to find the pin number of GPIO1 associated with this button (const int buttonPin = ??). The schematic of the Hat Carrier shows that GPIO1 is connected to pin 48 of the high-density connector J2 (see image below). However, I tested with const int buttonPin = 48 and it doesn't work, so I think the declaration is not that simple. So, I went to find the name of the microcontroller port, which is PC15 (see ABX00042-full-pinout.pdf). Is this what should be used? Thanks in advance for your help!

Basic code I'm trying to get to work:

const int buttonPin = ?; // the number of the pushbutton (PB1) pin connected to GPIO1 
int buttonState = 0;

void setup() {
  // initialize the LED pin as an output:
  pinMode(LED_BUILTIN, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    digitalWrite(LED_BUILTIN, LOW); 
    delay(1000);                     
    digitalWrite(LED_BUILTIN, HIGH); 
    delay(1000);                     
  } else {
    digitalWrite(LED_BUILTIN, HIGH); 
  }
}

Sorry, I played with one of these several months ago. I setup my own excel document
but I don't think I mapped the button pin in it...

It sounds like it is on signal: PC15?

If so you might try:
pinMode(PC_15, INPUT);

digitalRead(PC_15);

Note: this is using pin names, not numbers:
void pinMode(PinName pin, PinMode mode)

Good luck

Hello, could you explain me that? Thanks for your reply.

I should mention, I have not spent much time with the Portenta. I purchased one like you have to see how it compared to the GIGA I have.

With some of the newer boards (maybe mainly MBED boards), it appears like they added two parallel ways to talk to IO pins. The main Arduino way which is by a number, and another way by using logical Pin Names, that which then map through to either calling off with the corresponding Arduino IO pin or go through to use MBED to do the work.

You can see the top level of this code in their cores\Arduino\wiring_digital.cpp file

They use a table that is built into the variant (variant.cpp, which maps pin Numbers to Names (or you can search through table for name, to find the index).

And you mentioned PC15, which in their naming is PC_15... Which is in that table...
Not sure if it is the right pin... Although does match my raw Excel file where I tried to go through and map all of the Connector pins of the Portenta to the underlying H7 processor pins and Arduino IO pins and what functions each of these pins can do...

One page starts off like:

Expand Arduino HAT Standard Port AF0 AF1 AF2 AF3 AF4 AF5 AF6 AF7 AF8 AF9 AF10 AF11 AF12 AF13 AF14 AF15
J2-73, J1-34 15/A0 PH01 ANALOG_A0 PA0 - TIM2_CH1/
TIM2_ETR
TIM5_CH1 TIM8_ETR TIM15_BKIN - - USART2_
CTS/USAR
T2_NSS
UART4_TX SDMMC2_
CMD
SAI2_SD_B ETH_MII_
CRS
- - - EVENT
OUT
J2-75 16/A1 PH02 ANALOG_A1 PA1 - TIM2_CH2 TIM5_CH2 LPTIM3_
OUT
TIM15_
CH1N
- - USART2_
RTS/
USART2_
DE
UART4_RX QUADSPI_
BK1_IO3
SAI2_MCLK
_B
ETH_MII_
RX_CLK/
ETH_RMII_
REF_CLK
- - LCD_R2 EVENT
OUT
J1-35 13 RPI29 UART1_RX PA10 - TIM1_CH3 HRTIM_
CHC2
LPUART1_
RX
- - - USART1_
RX
- FDCAN1_
TXFD_
MODE
OTG_FS_
ID
MDIOS_
MDIO
LCD_B4 DCMI_D1 LCD_B1 EVENT
OUT
J1-28 USB D- PA11 - TIM1_CH4 HRTIM_
CHD1
LPUART1_
CTS
- SPI2_NSS/
I2S2_WS
UART4_RX USART1_
CTS/
USART1_
NSS
- FDCAN1_
RX
OTG_FS_
DM
- - - LCD_R4 EVENT
OUT
J1-26 USB0 D+ PA12 - TIM1_ETR HRTIM_
CHD2
LPUART1_
RTS/
LPUART1_
DE
- SPI2_SCK/
I2S2_CK
UART4_TX USART1_
RTS/
USART1_
DE
SAI2_FS_B FDCAN1_
TX
OTG_FS_
DP
- - - LCD_R5 EVENT
OUT
J1-75 JTAG2 SWDIO PA13 JTMS/
SWDIO
- - - - - - - - - - - - - - EVENT
OUT
JI-77 JTAG4 SWCK PA14 JTCK/
SWCLK
- - - - - - - - - - - - - - EVENT
OUT
PA15 JTDI TIM2_CH1/
TIM2_ETR
HRTIM_FL
T1
- CEC SPI1_NSS/
I2S1_WS
SPI3_NSS/
I2S3_WS
SPI6_NSS UART4_
RTS/UART
4_DE
- - UART7_TX - DSI_TE - EVENT
OUT

And the line for J2-48 shows
J2-48 GPIO_1 PC15 - - - - - - - - - - - - - - - "EVENT
OUT"

And the your sketch, slightly modified appears to work:

const PinName buttonPin = PC_15;  // the number of the pushbutton (PB1) pin connected to GPIO1
int buttonState = 0;

void setup() {
  // initialize the LED pin as an output:
  pinMode(LED_BUILTIN, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
  } else {
    digitalWrite(LED_BUILTIN, HIGH);
  }
}
1 Like

It works! Thanks for your help.