DIY Chain Counter - Again!!!

Andrew_Trayfoot

Active member
Joined
11 Oct 2007
Messages
671
Visit site
I don’t know whether this is feasible or not but is there not some kind of RFID chip you could fix to the chain at say 5m intervals and then use a reader to log the RFID ID each time one passes and therefore know what multiple of 5m length has been deployed. Each chip would have a unique ID so no counting in the normal sense would be required
Big issues with that approach are the harshness of the environment generally and getting the tages safely post the chain gypsy
 
  • Like
Reactions: vas

Andrew_Trayfoot

Active member
Joined
11 Oct 2007
Messages
671
Visit site
I'm currently on a ferry crossing Biscay on the way home from the boat. I will write a full reply when I get home. I haven't used Github before so this seems a good place to start. That way, I can publish it as a complete project including code.
A couple of weeks ago, we were in the boatyard and unloaded all 150m of our anchor chain. So that was a good opportunity to check the accuracy of the chain counter. And, yes, it works well over long chain with lots of stopping and starting.
Very pleased with the result. Finally I have made a reliable DIY chain counter.
Many thanks I shall look forward to it.

My approach will be slightly different. I plan to measure time up and down converted in metres (rated in the windlass spec) rather than adding a sensor to the gypsy.


Will see how it goes in terms of accuracy.
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
One possible update may be to look at MQTT for publishing updates to the network. There are lots of tools available for monitoring, manipulating and displaying such data.

Could probably send a few sentences like:
/boat/hardware/windlass/up_switch off
/boat/hardware/windlass/down_switch on
/boat/hardware/windlass/current_chain_deployed_m 54
My code was written using node.js
Specifically, it uses a node.js library that employs low level interrupts thus ensuring that I don't loose any inputs.
Node.js can also be used as a single page web server.
Everything is geared around not "blocking" the CPU.
I guess I could send some simple sentences out but my solution is simple.
The software creates a simple web server that ANY device can access using a web browser.
I have dedicated SWMBO's very old Samsung Android phone which automatically connects to the RPi when booted.
My onboard PC also connects at the same time.
All this works with or without internet.
I think this simple approach is easier than sending
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
Many thanks I shall look forward to it.

My approach will be slightly different. I plan to measure time up and down converted in metres (rated in the windlass spec) rather than adding a sensor to the gypsy.


Will see how it goes in terms of accuracy.
I think that approach would be a mistake.
Part of my debugging on this latest approach was to account for windlass overrun.
Just not precise enough - the windlass actually takes quite a long time to "spool down" after the power is removed.
Then there is the speed of deployment vs recovery.
And how would yo cope with a manual deployment (not using the windlass motor - the chain deployment would get faster as the chain deploys).

Just add a sensor to the gypsy.
Covers all angles and this process is what the windlass manufacturers use anyway.
Most manufacturers supply them and they aren't very expensive.
Mine actually came with the windlass but is is available as a separate part.

Having had three goes at making a DIY chain counter, I have "form".
 
  • Like
Reactions: vas

vas

Well-known member
Joined
21 Jun 2011
Messages
8,082
Location
Volos-Athens
Visit site
I think that approach would be a mistake.
Part of my debugging on this latest approach was to account for windlass overrun.
Just not precise enough - the windlass actually takes quite a long time to "spool down" after the power is removed.
Then there is the speed of deployment vs recovery.
And how would yo cope with a manual deployment (not using the windlass motor - the chain deployment would get faster as the chain deploys).

Just add a sensor to the gypsy.
Covers all angles and this process is what the windlass manufacturers use anyway.
Most manufacturers supply them and they aren't very expensive.
Mine actually came with the windlass but is is available as a separate part.

Having had three goes at making a DIY chain counter, I have "form".
+1 on Mike's points. No way this is going to be more accurate than measuring in your mind as you're dropping the chain tbh. Not to mention that retrieving will have different speeds at the beginning with chain in the seabed, then v.v.slow when it's trying to free the (hopefully) nicely and deeply set anchor and then another speed as all is free coming up.
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
do you also need to employ a debouncing routine as well Mike, or interrupts alone are OK?
I got lucky, Vas.
The guy who wrote the low level interrupt software also included some debounce routines.
So all the difficult work had been done - the beauty of Open Source Software.
See here:-
GitHub - fivdi/onoff: GPIO access and interrupt detection with Node.js
Simply install Node.js and then use the NPM packet manager to install his onoff library.
Dead easy so on a Raspberry Pi you simply do the following:-
sudo apt-get update
sudo apt-get install -y nodejs
sudo apt-get -f install npm
sudo npm install onoff

And then you can write your code - just include what debounce you want and it does it all for you.

As I say, when I get time, I will write it all up in the form of a Git project with full reference to that onoff library.

And, as I say, the final software seems to be working well.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,082
Location
Volos-Athens
Visit site
thanks Mike, but you're not helping :)
I'm on arduino IDE, due to other restrictions (said microcontroller does a dozen other things as well as chain counting) and as such have to source debouncing libs.
Got a couple, got all the code running fine, got a decent delay so when lifting it will continue for a couple of secs to count up instead of starting to count down (using the windlass up button to trigger inverting measurements so freefall and controlled fall via the windlass all count up turns) basically all's fine expect for the blasted debouncing.
Have a v.long and elaborate code I'm using on the rpm counter on the generator (no alternator and no other pickup point) and trying to avoid using it but will probably end up doing just that (100+ lines of code)

cheers

V.
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
thanks Mike, but you're not helping :)
I'm on arduino IDE, due to other restrictions (said microcontroller does a dozen other things as well as chain counting) and as such have to source debouncing libs.
Got a couple, got all the code running fine, got a decent delay so when lifting it will continue for a couple of secs to count up instead of starting to count down (using the windlass up button to trigger inverting measurements so freefall and controlled fall via the windlass all count up turns) basically all's fine expect for the blasted debouncing.
Have a v.long and elaborate code I'm using on the rpm counter on the generator (no alternator and no other pickup point) and trying to avoid using it but will probably end up doing just that (100+ lines of code)

cheers

V.
Ahh - thats why I moved to the RPi
Actually, the best bit is having a proper full operating system available - with all that lovely open source software!!

I've just looked back at one of my old Chain Counter Projects (one of the many that didn't work!!) and guess what?
I used an Arduino and in the depths of my project there were loads of attempts at getting debounced interrupts working.
Here's a photo from that old Arduino project - the add on board with the Opto Isolators.

Board Layout.resized.JPG

I thoroughly recommend that you consider using a RPi and then using a full up to date Linux environment to manage it.

To debug my chain counter, I simply SSH into it - everything I need is there - even the internet.
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
thanks Mike, but you're not helping :)
I'm on arduino IDE, due to other restrictions (said microcontroller does a dozen other things as well as chain counting) and as such have to source debouncing libs.
Got a couple, got all the code running fine, got a decent delay so when lifting it will continue for a couple of secs to count up instead of starting to count down (using the windlass up button to trigger inverting measurements so freefall and controlled fall via the windlass all count up turns) basically all's fine expect for the blasted debouncing.
Have a v.long and elaborate code I'm using on the rpm counter on the generator (no alternator and no other pickup point) and trying to avoid using it but will probably end up doing just that (100+ lines of code)

cheers

V.
My chain counting logic is very simple.

I consider the chain to be deploying unless the "up button" is being pressed - in which case, I consider the chain is being recovered.
So if you decide to let the anchor deploy by releasing the clutch, this logic still works.

No need for any complicated logic.
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,082
Location
Volos-Athens
Visit site
My chain counting logic is very simple.

I consider the chain to be deploying unless the "up button" is being pressed - in which case, I consider the chain is being recovered.
So if you decide to let the anchor deploy by releasing the clutch, this logic still works.

No need for any complicated logic.
yep, that's exactly the logic I described and I'm using, all is down unless the up button is triggered (plus 1 or 2 revs up when the up button is released as at least in mine it does a couple of turns even on up).
 
Last edited:

vas

Well-known member
Joined
21 Jun 2011
Messages
8,082
Location
Volos-Athens
Visit site
Ahh - thats why I moved to the RPi
Actually, the best bit is having a proper full operating system available - with all that lovely open source software!!

I've just looked back at one of my old Chain Counter Projects (one of the many that didn't work!!) and guess what?
I used an Arduino and in the depths of my project there were loads of attempts at getting debounced interrupts working.
Here's a photo from that old Arduino project - the add on board with the Opto Isolators.

View attachment 155454

I thoroughly recommend that you consider using a RPi and then using a full up to date Linux environment to manage it.

To debug my chain counter, I simply SSH into it - everything I need is there - even the internet.
lol, that's an old uno board most likely, I have a couple living in a drawer, nothing to do with them anymore.
My teensy are much more powerful than the pi and are the only things I can use for the N2K comms I need. All my custom work creates PGNs that feed back to the N2K bus of the boat.
This particular teensy board (1/4th of the pi) sits on my custom PCB and does:
fresh/black/fuel tanks -> N2K (fresh fuel are pressure sensors at the bottom, black is IR from the top)
NMEA0183 -> N2k wind data (have an old NASA on the hardtop)
analogue Rudder sensor -> N2K
inside/outside (OneWire) temp and humidity -> N2K
OneWire fridges temp -> N2K

so a fair amount of work.

I know you're more reasonable and splits tasks, having dedicated bits of kit per job, I seem to enjoy mixing them all up :)
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
yep, that's exactly the logic I described and I'm using, all is down unless the up button is triggered (plus 1 or 2 revs up when the up button is released as at least in mine it does a couple of turns even on up).
Ahh - yes I see.
When I mentioned the debugging in #44, thats exactly the problem I found.
There was an inaccuracy creeping in during "up" (recovery).
It turned out to be the windlass "over running" after the button had been released.
If the reed switch had been triggered at that time, my interrupting software detected the the reed switch but missed the "up button".
Rather than resolving it your way, I introduced a timer that triggers after the "up switch" has been released - to count the chain correctly during the "up overrun" period.

I hope that makes sense.

It obviously works.
When the boat was in the boatyard earlier this month we (a couple of posters from this forum and I) laid out all 150m of chain.
And we stopped/started the windlass loads of times whilst the chain was recovered.
In fact, SWMBO wanted the chain all tidy in the locker so she got me to start and stop it about every 5m
The end result when the whole 150m was recovered was just one revolution out - which could have been me hand feeding the bitter end of the chain back in.
So, I'm really pleased with the final accuracy.
 
  • Like
Reactions: vas

vas

Well-known member
Joined
21 Jun 2011
Messages
8,082
Location
Volos-Athens
Visit site
Ahh - yes I see.
When I mentioned the debugging in #44, thats exactly the problem I found.
There was an inaccuracy creeping in during "up" (recovery).
It turned out to be the windlass "over running" after the button had been released.
If the reed switch had been triggered at that time, my interrupting software detected the the reed switch but missed the "up button".
Rather than resolving it your way, I introduced a timer that triggers after the "up switch" has been released - to count the chain correctly during the "up overrun" period.

I hope that makes sense.

It obviously works.
When the boat was in the boatyard earlier this month we (a couple of posters from this forum and I) laid out all 150m of chain.
And we stopped/started the windlass loads of times whilst the chain was recovered.
In fact, SWMBO wanted the chain all tidy in the locker so she got me to start and stop it about every 5m
The end result when the whole 150m was recovered was just one revolution out - which could have been me hand feeding the bitter end of the chain back in.
So, I'm really pleased with the final accuracy.
sorry, my description was misleading. I also used a delay timer for a couple of secs I'm not actually removing 2 turns just like that as sometimes it may not do these turns or do only one or whatnot.
It's almost never a case where you lift chain and immediately drop it again (maybe only when cleaning it and bringing it home at the bow roller.
I think it's enough with all that, pretty sure we'll bore ppl to death with such detail.
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
sorry, my description was misleading. I also used a delay timer for a couple of secs I'm not actually removing 2 turns just like that as sometimes it may not do these turns or do only one or whatnot.
It's almost never a case where you lift chain and immediately drop it again (maybe only when cleaning it and bringing it home at the bow roller.
I think it's enough with all that, pretty sure we'll bore ppl to death with such detail.
Great minds think alike - I actually set my timer to 3 seconds.
As you say, how often would you instantly go from Up to Down and exactly at the same time as the reed switch is being operated during an over run?
I think I set 3 seconds to test it - with the idea of making it 1 second later.
But 3 seconds works so I left it.
 
  • Like
Reactions: vas

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
I decided not to put my chain counter on Github.
Rather than create a full blown project, I have simply put my project files on my internet server.
So, if anyone is interested this is the address/URL
Index of /chaincounter
In that directory you will find my notes file (called ChainCounterNotes.txt)

I write notes for everything I do - all my computer installations and any projects I do, have a notes file.
The notes file is always written using a simple text editor.
No particular format but I use tabs to "indent in" within a subject.
I will often keep my notes file open whilst working on a project (installing Linux for example) and update the notes as I go along.
In the case of this Chain Counter Project, the notes should be "self explanatory" - there are also links to stuff that I used in the project.
So, if you are interested, the file ChainCounterNotes.txt is probably the best place to start.

OptoDiag.jpg is, effectively, the circuit diagram for the Opto Isolator interface (home made Raspberrt Pi Hat)

SampleDisplay.jpg is a sample display that you will get on a mobile device.

The sub directory CodeVersion1.5 contains the actual software.
Written using node.js so it isn't compiled - the code itself is the source code.
Within that directory, the actual code is in a file called chain.js which is extensively documented - I hope the comments are understandable.
All the other files in that sub directory are referenced within chain.js
For example ChainMultiplier.conf contains a decimal integer that equates to the distance the chain travels in mm for a full turn of the windlass.
The HTML files are split versions of the final HTML page served - see the code in chain.js to see how it works.

Finally, I use a BIG fiddle to get it all working.
You will see from the HTML that the page will reload every 1 second (this line http-equiv="refresh" content="1")
This instructs the remote device (mobile phone etc) to reload the page every second.
I believe this is a very naughty approach - maybe I should use something like Web Sockets to transfer the data but reloading every second works for me.
Importantly, it doesn't seem to disturb the low level interrupt routines.

The application stores the amount of chain deployed on the Raspberry Pi's microSD card.
So if the power is removed whilst the boat is at anchor, the correct amount of chain deployed will be displayed when the power is restored.

I hope some people will find this interesting.
After having had so many disappointments in the past, I'm really quite pleased with the results from this project.
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
I really must have a go at this.... just a few more jobs to do around the house next week then I will dig out one of my RPi's..! Await a call Mike ;-)
I remember when I did the project, you said you might have a go.
So I wrote the notes with you in mind.
When I write notes for myself, I often don't understand them later!!!
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,082
Location
Volos-Athens
Visit site
I remember when I did the project, you said you might have a go.
So I wrote the notes with you in mind.
When I write notes for myself, I often don't understand them later!!!
+1 and with this in mind, now my code linecount is 1/3comments, the rest code.
And still I'm currently at the boat trying to figure out what I'm missing and the chain counter works but doesn't broadcast the values to nmea0183 😟
Pretty sure on replacing the broken optoisolator today, I messed something... Oh well.

V
 
Top