Open Source PLC digital write not working

I’m working on a project with the Open source PLC (wrapped around an Arduino Mega) and trying to use the output pins. The hardware I’m using is described here. However, I have not gotten the pins to work. Since the output pins are D38-D45, I would try writing a line like

digitalWrite(40, HIGH);

to get the device to send voltage to pin D40. The line compiles and runs just fine. But when I measure the output with a volt meter, it gives a reading of <100mV, and more importantly, not significantly different than the output of

digitalWrite(40, LOW);

.
I tried measuring the voltage against both the common for the digital outputs, and the ground of the device- no difference in reading. I also tried wiring the common to the ground- still no difference. I tried looking for if I have the wrong number on the pin. I tried replacing the “40” with “D40”, in case that was a library-defined name for the pin, but it wasn’t, so that threw a compiler error. I tried this with multiple of the pins- did not make a difference.
I tried with and without the line
pinMode(40, OUTPUT);-
still no difference
I know the analog and digital inputs are working because I’ve been successfully using them. Same with the RS-232 pins and the relays.

Should this work, or is there something that I’m missing? Is there something special I need to do to make digitalWrite work? I’m open to suggestions.

Did you set the pin to output in setup() (pinMode(pin, OUTPUT)? I would not have to ask if you post all of your code as requested in the stickies. Pins are INPUT by default after reset. You must make them OUTPUT.

Yes I did. That also didn't work. I've edited my post to mention that as well. All of my code contains a lot more than just a digitalWrite call.

swenger: All of my code contains a lot more than just a digitalWrite call.

Then that gives you a good opportunity to downsize the code to the bare minimal and check to see if the error remains ;)

Because the error is certainly NOT in what you posted ;)

The outputs seem to be open collector from my brief look. They will need pullup resistors or a load connected from Vcc to the output. The output will only sink current, if I am interpreting the data sheet correctly. Try 10K from output to Vcc.

Hi,
As groundFungus has said, D40 is OC (Open Collector) digital output.
plc.jpg
Tom.. :slight_smile:

plc.jpg