Referencing pins on Portenta H7 high-density connector

Hi.

Working with the new Portenta H7 high-density connectors, it is unclear to me how each of these pins can be referenced in a sketch. In my experience with other models, pins are referenced either as numerics for digital pins and "A"+numerics for analog pins. For example:

pinMode(1,OUTPUT)

or

pinMode(A1,OUTPUT)

However, in the provided pinout (https://content.arduino.cc/assets/Pinout-PortentaH7_latest.pdf), there is for example GPIO 0, but also PWM 0, and SAI D0, but also CAM D0. Using these 'full' names returns errors "not declared in this scope".

What is the correct way to reference these pins?

Many thanks for any help!

Michiel

You are on the bleeding edge of Arduino devices.
I think you mostly just use the port names with an underscore, eg. PH_10

1 Like

Haha, so it seems. And you are right, using the port name with an underscore before the numeric works.

It's not exactly user friendly to not use that notation in the pinout diagram anywhere...

Thank you!

1 Like

Referencing to the pins, I run into a new issue when using the pin definition in functions. (I guess this is a more broadly applicable question concerning non-numeric definitions.)

For other Arduino's where digital pins are referenced with a numeric value, I could do:

#define PIN_A     10

void myFun (int PIN_A) {
  Serial.println(PIN_A); // this would give "10"
  return;
}

But with the new pin name format this does not work.

#define PIN_A     PH_10

void myFun (int PIN_A) {
  Serial.println(PIN_A); // this does not give "PH_10"
  return;
}

How should this be handled? What declaration other than 'int' should be used, or is there a better, altogether different, approach?

Thanks in advance!

Both ways are wrong. When you declare an int parameter, it would normally make a local variable called PIN_A. But you have already defined it in a macro, so the first example probably won't compile because it says in effect,

void myFun (int 10) {...

Also you can't print variable names. Those are all translated to memory locations in machine code, and the names are discarded after compilation.

Thanks for the quick reply.

So what is then the correct way to pass the value of PIN_A to the function?

MVANNESSELROOIJ:

#define PIN_A     PH_10

void myFun (int PIN_A)

First of all, don't use a macro name as a function parameter name; that's way too confusing and dodgy.
PH_10 is of type PinName, which is an enum type. As an enum it is just maps at compile time to an integer, specifically 0x7A.
If you want the actual "PH_10" text, then you'll have to provide it yourself. eg.

myFun(PH_10, "PH_10");

Or if you prefer a more complicated solution:

struct MyPinType {
  PinName pin;
  const char *text;
};

const MyPinType myLedPin = { PH_10, "PH_10" };

void myFun (const MyPinType &pin) {
  Serial.println(pin.text);
  digitalWrite(pin.pin, HIGH);
}

void setup() {
  myFun(myLedPin);
}

void loop() { }
1 Like

That's very useful, thank you. I don't specifically need the pin name as text, so I think I can solve the issue just by

  • replacing #define with a PinName type declaration
  • using PinName type as input for myFun