So this is now figured out. Wasn't baud rate or anything so simple, it was having things in the Interrupt Service Routine (ISR) that shouldn't have been. Namely, things like sending things out via serial.print() and millis() that can't be in there because they use interrupts as well (should have read the attachInterrupt() documentation more closely, because that's spelled out quite clearly). In my defense, I took what was supposedly working code snippets from other projects that did those things.
Anyway, I looked at my wave form output from my hall effect sensor with an oscilloscope and it does not appear to need debouncing, which removed any need for the millis() stuff that was inside the ISR. So that's gone. Then I simply removed the serial output during the ISR, which I also didn't need but was in there for debugging purposes (yeah, debugging code adding the bug). Now it works. Here's the revised code:
//
// AutoLoc Linear Actuator Control Software
//
// AutoLoc linear actuators use a DC motor and simple polarity reversing to extend
// and retract. They also feature a hall effect sensor that sends pulses as it moves.
//
// http://www.carid.com/images/autoloc/vertical-doors/pdf/la24-installation-instructions.pdf
//
// This code taken from:
// http://forum.arduino.cc/index.php?topic=236470.0
// which originally took the code from here:
// http://learn.robotgeek.com/demo-code/123-arduino-linear-actuator-tutorial-preset-position-button-control.html
//
//
const int relay1 = 7; // extend relay output pin connection
const int relay2 = 4; // retract relay output pin connection
const int reedSwitch = 2; // interupt pin connection - See attachInterrupt() docs for your board
volatile int counter = 0;
int counterState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
long lastDebounce0 = 0;
long debounceDelay = 10; // Ignore bounces under 10ms
volatile int CurrentPosition = 0;
int goalPosition = 0;
boolean Extending = false;
boolean Retracting = false;
int incomingByte; // a variable to read incoming serial data into
void actuatorExtend(){
digitalWrite(relay1, HIGH); // Always turn one off and then the other on
digitalWrite(relay2, LOW); // so that there are never two relays on (BIG!)
}
void actuatorRetract(){
digitalWrite(relay2, HIGH); // Always turn one off and then the other on
digitalWrite(relay1, LOW); // so that there are never two relays on (BIG!)
}
void actuatorStop() {
digitalWrite(relay2, HIGH);
digitalWrite(relay1, HIGH);
}
void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(reedSwitch, INPUT); // reedSwitch is an input
attachInterrupt(1, trigger0, RISING); // See attachInterrupt() doc for YOUR BOARD
// Leanardo needs "1" for pin 2
// Never see the output below on the Serial Monitor
Serial.println("Repetition counter");
Serial.print("Start");
Serial.print("\t");
Serial.println("End");
// Set both output pins
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
// Initialize both relays to off (make sure whatever relay setup you use defaults
// to OFF since there may be some delay between power-up and this code executing!
digitalWrite(relay2, HIGH);
digitalWrite(relay1, HIGH);
}
void loop() {
if (Extending == true && CurrentPosition > goalPosition ) {
//we have reached our goal, shut the relays off
actuatorStop();
Extending = false;
Serial.println("IDLE");
}
if (Retracting == true && CurrentPosition < goalPosition) {
//we have reached our goal, shut the relay off
actuatorStop();
Retracting = false;
Serial.println("DELI");
}
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
if (incomingByte == 'A') {
goalPosition = 50;
if (goalPosition > CurrentPosition) {
Retracting = false;
Extending = true;
actuatorExtend ();
Serial.println("AExtending");
}
else if (goalPosition < CurrentPosition) {
Retracting = true;
Extending = false;
actuatorRetract();
Serial.println("ARetracting");
}
}
if (incomingByte == 'B') {
goalPosition = 1;
if (CurrentPosition < goalPosition ) {
Retracting = false;
Extending = true;
actuatorExtend ();
Serial.println("BExtending");
}
else if (goalPosition < CurrentPosition) {
Retracting = true;
Extending = false;
actuatorRetract();
Serial.println("BRetracting");
}
}
if (incomingByte == 'S') {
actuatorStop();
Serial.println("Stop");
}
}
}
// Once we start a relay, we should start getting pulses from the sensor as the
// actuator moves. When we get a RISING edge and interrupt will be generated and
// we will jump to the following function.
void trigger0() {
if ( Extending == true) {
counter++;
CurrentPosition = counter;
}
if ( Retracting == true ) {
counter--;
CurrentPosition = counter;
}
}
There's still work to turn this into the full control code I want, but it moves the actuator back and forth between the specified positions just fine. Onward and upward...
(And I ultimately solved this by pairing down my code to just what was needed to listen to the hall effect sensor and when that didn't work I posted in the sensors forum here and someone pointed out the serial printing wouldn't work. Already posted there that this is fixed and how it was done, too.)
--Donnie