Assistance Configuring 12VIO Pins

Hello,

I’m a bit confused on setting up the input and output pins. First thing I am trying to do is configure a 12V output pin with a pwm signal to simulate a speed sensor signal. Using the M2_12VIO library, I believe the following short lines of code are all I need to set the pin at a 100hz, 50% duty cycle.

// Required libraries
#include “variant.h”
#include <M2_12VIO.h>
#include <pins_arduino.h>
#include <Arduino.h>
#include “M2_IO.h”
#include <pwm_lib.h>
M2_12VIO M2IO;

void setup() {

M2IO.Init_12VIO(); // Initialize the M2I/O library
M2IO.Setpin_12VIO(2, ON, SOURCE, PWM_PIN, 100, 50);
}
void loop() {
}

Or am I missing something here? I don’t seem to be getting it to work like I would expect…

And the next thing I am trying to do is read a switch. Can the 12V input pins be configured as input pullup? Other end of the switch is connected to ground. Would I be using the following functions for this, if my switch is connected to input 2?

InitButton_12VIO(2);
GetButton_12VIO(2);

Sorry for the basic questions, I’m still learning Arduino as I go.

Has anyone used the 12v functions? Even seeing the sketch that was used to run the tachometer in the installation documents would be helpful.

What I have so far is an input “button” sketch that works, this would work for my reverse output, but not ideal. It works with a voltage input to the input pin. Is there a way to use a ground input instead (with coding, not hardware)?

Another note, it appears Led1 is the red LED? I thought it was 5 based on the same sketches I have seen. Led5 is the green LED.

// Required libraries
#include “variant.h”
#include <M2_12VIO.h>
#include <pins_arduino.h>
#include <Arduino.h>
#include “M2_IO.h”
#include <pwm_lib.h>
M2_12VIO M2IO;

int test = false;

void setup() {

pinMode(Led5, OUTPUT);
digitalWrite(Led5, LOW); // turn the GREEN LED ON by making the PIN LOW

pinMode(Led1, OUTPUT); // Set the RED LED PIN as an OUTPUT
digitalWrite(Led1, HIGH); // Init RED LED PIN as High so led is off

M2IO.Init_12VIO(); // Initialize the M2I/O library

M2IO.InitButton_12VIO(1);

}

void loop() {

test = M2IO.GetButton_12VIO(1);

if (test == 1) {
digitalWrite(Led1, LOW); // turn the RED LED ON by making the PIN LOW
}
else {
digitalWrite(Led1, HIGH);
}
}

I believe I found my problem… If I had USB connected to the Arduino, but not 12V when it rebooted (downloaded a new sketch), the 12V IO system wasn’t initialized… I decided to wire up pin 23 on the 26 pin connector with a 10k resistor to make my input a pull up so I can use a ground for the switch. I would like to switch this to a software solution if the M2 board supports it.