Footage Counter on a Sewer Camera

Copy and paste the two lines that print the count. Change the label to feet and replace counter with counter*175. What the actual number is, you'll need to find out.

[code]
// Rotary Encoder Inputs
#define CLK 2
#define DT 3
#define SW 4

int counter = 0;
int currentStateCLK;
int lastStateCLK;
String currentDir = "";
unsigned long lastButtonPress = 0;

void setup() {

  // Set encoder pins as inputs
  pinMode(CLK, INPUT);
  pinMode(DT, INPUT);
  pinMode(SW, INPUT_PULLUP);

  // Setup Serial Monitor
  Serial.begin(9600);

  // Read the initial state of CLK
  lastStateCLK = digitalRead(CLK);
}

void loop() {

  // Read the current state of CLK
  currentStateCLK = digitalRead(CLK);

  // If last and current state of CLK are different, then pulse occurred
  // React to only 1 state change to avoid double count
  if (currentStateCLK != lastStateCLK  && currentStateCLK == 1) {

    // If the DT state is different than the CLK state then
    // the encoder is rotating CCW so decrement
    if (digitalRead(DT) != currentStateCLK) {
      counter --;
      currentDir = "CCW";
    } else {
      // Encoder is rotating CW so increment
      counter ++;
      currentDir = "CW";
    }

    Serial.print("Direction: ");
    Serial.print(currentDir);
    Serial.print(" | Counter: ");
    Serial.println(counter);
  }

  // Remember last CLK state
  lastStateCLK = currentStateCLK;

  // Read the button state
  int btnState = digitalRead(SW);

  //If we detect LOW signal, button is pressed
  if (btnState == LOW) {
    //if 50ms have passed since last LOW pulse, it means that the
    //button has been pressed, released and pressed again
    if (millis() - lastButtonPress > 50) {
      Serial.println("Button pressed!");
    }

    // Remember last button press event
    lastButtonPress = millis();
  }

  // Put in a slight delay to help debounce the reading
  delay(1);
}
[/code]`Preformatted text`

ok thanks wildbill...

You might want to have another go at the code tags.

oh dear, Im gonna get kicked off

Oops - math fail. Try Counter/175.

Thank you sir...we are beginning to cook with some fire now... :wink:

You will most definitely need an unspooling adjustment.
The calculus is muddied because the spool does not single stack. Fortunately, there's an easier way.

  1. Unspool 1 rotation and measure how much was unspooled and record
  2. Continue unspooling 1 rotation at a time, measuring the amount unspooled, and recording, until you have it all unspooled
  3. Store these values in order in an array
  4. Take your number of tick from the encoder, divide by 175, plug that value into the array as an index and you have a very accurate measurement, likely to be accurate to within 1 rotation's length.

To increase accuracy you can

  1. Modulate your reading by 175 to get a remainder from the division
  2. Take the value from the index above
  3. The value from the same index - 1
  4. Subtract the value from step 7 from the value from step 6, to get the value of the current rotation
  5. Multiply your remainder from step 5 by the value from step 8
  6. Divide that by 175 to get the measurement between rotations
  7. Add that to the value from step 4 and you will have a very accurate measurement

I know it reads like a set of stereo instructions. I will better illustrate later when I have a moment.

On the frame of the cable reel, there is a guide that the cable goes through keeping the distance from the center of the reel to where the cable unspools at a constant 6". Shouldnt this be easy to calculate? Im no math guru, but it seems to me, that once I calculate how much one click of the encoder moves that cable leaving the reel at that guide, I should be able to enter that number into the counter section of the serial print, am I correct? Or am I overlooking something? :slight_smile:

Try it and see. If there's a cable tensioner arrangement that keeps that constant radius, it sounds like the calc is trivial, but only experiments will tell you for sure.

Possibly, but given the stakes I would be triply sure.

Why is the number 175 important in this calculation? Thanks

It isn't. It's a place holder for whatever number you discover for clicks per foot.

Cable reels don't have equal footage per turn, it varies as the reel empties, so you can't count rotations of the reel and get anything but very rough estimate. A separate pulley for the cable to run through would be needed to actually measure length.

Or you could add some sort of calibration system to account for the reel diameter changing as it dispenses.

Oh I see. Thanks again sir!

That should have been click per rotation, a fixed number throughout the process.

Thank you :slight_smile:

No worries. There are a lot of steps, does it make sense how to do it and why it's necessary?
Also, the number may not be 175 and you'll need to figure out what the number of clicks per rotation actually is.

Yes, those steps you listed make sense and Im slowing picking them up (although Im a bit slow). But with everyone's help I do think I will get there. Thanks again!

Absolutely. Reply to a comment of mine or @ my username if you need help implementing them after you've tried.