Portenta Machine Control, Help with Pin mapping

Can anyone advise where I can find a pin map for the Portenta Machine Control unit for the mapping of the Digital Outputs and Programmable I/Os when using the PLC IDE?

To summaries my issue I'm having with the PLC IDE;

I have a Portenta Machine Control (PMC) unit which I am attempting to use the digital outputs to control a stepper motor. I've used the standard Arduino IDE to upload code to the built in Portenenta H7 to test that the digital outputs could control a stepper and it worked satisfactorily. The test was using the the code below to continuously rotate the stepper. The purpose of the test was sufficient to know that a similar code should work using the PLC IDE.

For reference, the stepper is controlled via a TB6600 immation controller and here's the code I used.

#include <Arduino_PortentaMachineControl.h>

void setup() {
  MachineControl_DigitalOutputs.write(0, HIGH); 
}

void loop() {
   MachineControl_DigitalOutputs.write(1, HIGH);
  delayMicroseconds(500);
  MachineControl_DigitalOutputs.write(1, LOW);
  delayMicroseconds(500);

}

I've chosen to use the PLC IDE to run the stepper so that it can interact with functions in a Ladder Diagram (LD) which are easier to setup/modify and debug far easier than using a basic Arduino Uno board. It's also far easier to update and change the code as it grows and requires additional capabilities.

I've managed to do something similar with the Arduino OPTA so that a sketch looks for a LD contact state change and then responded by activates one of the LEDs via a sketch, (rather than using a coil to turn on that LED). This was done using the pinmap outputs as shown here.

Heres my Opta example:

void setup()
{
pinMode(LED_D3, OUTPUT);    // LED_D3 is the 4th LED on the front of the unit.
}

void loop() {
testLoop1();
}
 
void testLoop1() { 
    if (PLCOut.outLedTest == true){    // checks the status of the shared variable in the LD
    PLCIn.inLedTest = true; // updates the shared variable in the LD for proof that its was communicating
    digitalWrite (LED_D3, HIGH); // turns on the LED on the front of the Opta
        } else { PLCIn.inLedTest = false;  
     }
}

Replicating this on the PMC is proofing difficult for me. Although there is a pin map for the PMC here there are too many similarities between the pin numbers for them to be used (unless I'm miss-reading it). For the inputs, outputs and programmable I/Os they all go from 00 to either 07 or 12 without a prefix that determines their location or type.

I've tried a lot of variations of different pin numbers, names and variable tags similiar to what you may find/create when setting up the Local IO Mapping, but cant get it to work in any way. I have tested the sketch using some shared variables which acts as a switch on a LD rung with a coil to turn on/off an I/O, but this is a bodge of sorts that I dont accept to be the correct way of doing things.

Can someone tell me what im doing wrong or link the pin map that would have a list of working pinouts?

Also, it appears that all the online examples and tutorials are for code that's uploaded via the Normal IDE and so uses coding with prefix such as "MachineControl_DigitalOutputs.write" and not meant for uploading into the PLC IDE.

Thanks in advance.

Hi @autoadam I think this tutorial is what you're looking for. I don't have a PMC or do PLC (I have a GIGA) but it appears you create your own pin maps with this platform - cool
https://docs.arduino.cc/software/plc-ide/tutorials/plc-ide-pin-mapping/

Hi @steve9, thanks for the response.

I've seen that guide before and given it another test. The pinmap that it creates allows you to name local I/O "digitalOut01" and there are essentially two different ways of doing, I can't tell how one is different over the other without further testing.

The variable works in Structural Text (ST) format to be turned on and off, as per their example, but I can't get the same results using the variable name in a sketch. Unfortunately, I don't know enough about ST to do much else with it.

Anyway, I've written it us shown, the compiler seems to accept it and it can be downloaded without an issue, but nothing will happen.

bool digitalOut01;

void setup() {
pinMode (digitalOut01, OUTPUT);
}

void loop() {
   digitalWrite (digitalOut01, HIGH); 
}

With the Opta it works in the same way, the variable name cant be used in the sketch but the pin number can be used (which was LED_D3, for one of the from LEDs) .
I'm pretty much out of ideas from here.....well nearly.

Probably time to dig into the source code . This is the repo

This looks useful

That's exactly what I was after. And it works......I think....well close enough. More testing and reading is required. But in the mean time, my initial test was to use the pin PJ_9 (for digital output pin no. 02) and set it to the following;

void setup() {
pinMode (PJ_9, OUTPUT);
}

void loop() {
  digitalWrite (PJ_9, LOW); 
  delay(2000);
  digitalWrite (PJ_9, HIGH); 
 delay(2000);
}

This had an unusual outcome. The led on output no. 2 flashed on for maybe half a second before going off. Which it continued to do on a 4 second loop. So its was carrying out the loop and keeping time but not able to keep the led on.

Changing pin PJ_9 to permanently high without anything to pull it down has a similar effect, of a single flash for half a second and then its off again until you restart.

Bit more tinkering but with a stepper lead me to this:

#define stepPin PJ_9 //output 02
#define dirPin PH_9 //out pin 01

void setup(){
pinMode (stepPin, OUTPUT);
pinMode (dirPin, OUTPUT);

digitalWrite (dirPin, HIGH);
}

void loop() {
  digitalWrite (stepPin, LOW); 
  delayMicroseconds(500);
  digitalWrite (stepPin, HIGH); 
 delayMicroseconds(500);
}

This works to continuously rotate the stepper, even though the output pin PH_9 (renamed to dirPin) doesn't look like its on, it must be doing something. Currently can't test is too much until i get some resistors on the 24v outputs or its gonna burn out the stepper signal circuit.

Got a lot of reading to get through on and a holiday looming, I'll let you know how this develops in the new few weeks.

@steve9 thanks for your help in the matter, really appreciate it.