I'm having trouble connecting a step motor controller (with STEP/DIR outputs) to a motor driver (with CW/CCW inputs) using an Arduino-bootloaded ATMega328P, and the root of the problem seems to be that I am also attempting to use an optoisolator to keep this particular motor/driver separate from three others one the same controller. (They use STEP/DIR input drivers so they're all set...)
I have tried several permutations of the NPN phototransistor section, like pulling the Ardiuno pin down instead of up, reversing the connections to pins 4 and 5, and probably others, but I'm obviously not understanding something important because I am consistently unable to change the state of digital input 10.
The "stepping motor controller" DIR and STEP are outputs? You show the LED side connected to the board that way. The LEDs make the phototransistor turn on, not the other way round.
Where's pin 10 in your drawing? Pin 0? Pin 13?
[The H11AA1 is for an "AC input". (It's OK to use it for DC, too, just "underutilised".)]
Hi, and thanks for the reply. I'm sorry if my drawing was confusing- the motor controller is an interface board that is connected to a PC parallel port. I'm using the STEP and DIR signals that the board subsequently provides to trigger the optoisolator, and that part seems to be working fine. It's the output of the opto that isn't being interpreted correctly (OK, at all) by the microcontroller. Pin 16 (digital pin 10) is the one connected to the output of the opto, and digital 0 and 13 are running the LEDs.
I was at a different computer when I posted, so I re-wrote the code instead of pasting it. Here is what I'm actually using:
I believe that at any given time, digitalRead() returns a Boolean value, does it not? So I thought I was using the IF this way:
If (direction pin is HIGH) {
//indicate this by lighting one of the LEDs
}
else {
//light the other LED
}
Lastly, the reason that I need the isolation is that one of the four step motors hanging off the controller (the one on the CW/CCW input driver) runs off a separate (24V) power supply. The other three are at around 65V.
Thanks again, and I hope I answered everything...!
Patrick
Hey there, Pancake...thanks. You were right- when I declared a variable and had digitalRead() return its value to it, the if statement works as expected.
Now the only question is "in what programming language IS it possible to use a function without first declaring a return variable?" Seems to me that in the past I have gotten away with this, but I don't recall the circumstances.
That programming language would be C You can indeed use it as you were. digitalRead returns HIGH or LOW which are 1 and 0 respectively so you can test for them in an if. Depending on how much it bothers you depending on those values never changing in later versions of the IDE, you may prefer to do this: