DIY Chain Counter - Again!!!

salubrious

New member
Joined
2 Aug 2023
Messages
6
Visit site
Hi @Hurricane , I am just building a Pi based chain counter now. I'm doing it in python. I was just planning on using the reed switch in the gypsy via a pull up resistor to trigger a GPIO interrupt. Is there a reason this would not work which necessitated the usage of the additional chips?

Cheers
Jeff
 

jakew009

Well-known member
Joined
29 May 2012
Messages
428
Visit site
Hi @Hurricane , I am just building a Pi based chain counter now. I'm doing it in python. I was just planning on using the reed switch in the gypsy via a pull up resistor to trigger a GPIO interrupt. Is there a reason this would not work which necessitated the usage of the additional chips?

Cheers
Jeff

Electrically it would work assuming the reed switch is isolated, you may find you get some induced voltages if the sense wires run near any big cables / motors etc.

You still have to get the direction in which the windlass is moving.

These things are really useful for RPI projects with isolated inputs.. Iono Pi - Industrial Raspberry Pi PLC - digital/analog I/O Relays CE FCC
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
Electrically it would work assuming the reed switch is isolated, you may find you get some induced voltages if the sense wires run near any big cables / motors etc.

You still have to get the direction in which the windlass is moving.

These things are really useful for RPI projects with isolated inputs.. Iono Pi - Industrial Raspberry Pi PLC - digital/analog I/O Relays CE FCC
Yep - my previous projects went the way of induced current!!
This one, has Opto Isolators that protect the Pi but, as you say, there are large currents being switched.

To get the Windlass direction, the software "looks" at the switch that operates the windlass.
I only need to detect the "up" (recover anchor) switch.
Any other movement is considered to be deploying the anchor.
That way, the counter will still work when the clutch is used to deploy the anchor/chain.
It took a bit of debugging - the main problem was to write some code that accounts for the time that it takes for the windlass to slow/stop.
You wouldn't have thought that to be a problem - but it was.

The whole application is working reliably and it is surprisingly accurate.
It uses interrupts in order to avoid "missing" an input.
Software is written around Node.js
The software stores the chain count on the Raspberry Pi's microSD card so I can switch it all off once we are anchored and it remembers the amount of chain deployed for when we want to recover it.

As said above, after finishing the counter, it was suggested that a modification to display how much chain was in the water was introduced.
Actually, thats the difference between the deck and the water level but it really does help in the practical world.

For those interested, I took this sequence of photos last month as we left Santa Ponca (Mallorca).
It shows one of my Raymarine Glass Bridge Displays with various stages of anchor recovery.
The photos show the anchor camera's view (top left) and the chain counters display in a separate window.
OpenCPN charts underneath,

Unfortunately, I missed an interesting photo of the anchor on the sea bed - we had drifted right over it and you could clearly see the anchor on the anchor camera window.

This one was taken just before the anchor broke the surface - 3.6m of chain was still deployed - 1.1m of it was still in the water.

20230705_103255.resized.jpg

Then this one was taken as the anchor broke the surface - note 0.0m in the water but there is still chain to recover.

20230705_103302.resized.jpg

Finally a photo of the anchor out of the water and on its way up - still 1.8m to go

20230705_103307.resized.jpg

I meant to post these sooner but I forgot.

This subject is quite topical at the moment.
I've just finished building three Raspberry Pis to work as audio receivers.
I have 3 audio zones on the boat (Cockpit, Flybridge and Saloon).
Each one has an audio receiver connected to an amplifier and speakers.
Music is played from a mobile phone.
The old receivers were playing up this year so I thought I would build my own this time.
The final solution gives a choice of Bluetooth, AirPlay or Spotify
The idea is that friends have a better taste in music than me - so, if they don't like mine, I just get them to play their music.
As of tonight, the Raspberry Pi audio system is all working - and ready to be fitted when we next go out to the boat.
 

salubrious

New member
Joined
2 Aug 2023
Messages
6
Visit site
Cool. Thanks.

Yeh, I'll get the direction in the same fashion as Hurricane. If it is not going up, it is going down.

Are you saying there is potential to damage the Pi from induced current in the reed switch wire? It does have a pretty big run from the anchor to the Pi. I could smooth the voltage via a transister and only pass the 3.3 base from pin 1.
 

jakew009

Well-known member
Joined
29 May 2012
Messages
428
Visit site
Cool. Thanks.

Yeh, I'll get the direction in the same fashion as Hurricane. If it is not going up, it is going down.

Are you saying there is potential to damage the Pi from induced current in the reed switch wire? It does have a pretty big run from the anchor to the Pi. I could smooth the voltage via a transister and only pass the 3.3 base from pin 1.
If you connect the GPIO pin directly to the reed switch, you only have a couple of volts of ‘threshold’ and you may find your readings are all over the place. You also run the risk of blowing the gpio pin on the Pi if a huge spike is induced.

If you run the sense wire at a higher voltage, you can increase the thresholds and make it all more robust.
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
If you connect the GPIO pin directly to the reed switch, you only have a couple of volts of ‘threshold’ and you may find your readings are all over the place. You also run the risk of blowing the gpio pin on the Pi if a huge spike is induced.

If you run the sense wire at a higher voltage, you can increase the thresholds and make it all more robust.
This is my circuit.
Opto Diag.resized.jpg

On projects like this, I like to document it.
If I don't I forget how I did it - its age - brain isn't as good as it used to be!!

You will see from that diagram that I used 24v on the reed switch circuit.
The 4n25s are the Opto Isolators that completely isolate the 24v reed circuit from the 3v3 that the Raspberry Pi uses on its GPIO.

My main reason for using 24v was that I wanted a substantial voltage that couldn't be confused with any stray induced voltage/current.
I did some tests using different current limiting resistors to see what worked best - in the end, I chose 2K2 ohm.
Results were in a spreadsheet.
Again, I keep this documentation so here are those tests.

Screenshot_2023-08-03_09-50-41.resized.png
The red column were the resistors that I tried.
I cant remember the exact test but the green column was the outcome.

The end result is that I don't get any false or lost signals from the reed switch.

One test that we did was in the boatyard when we took all the chain (150m) out of the locker and swapped the ends over.
I set the chain counter during that process.
The chain counter ended up at zero after the whole 150m was back in the locker.
In that instance, I started and stopped the windlass whilst SWMBO flared the chain out in the locker so there was lots of opportunity for a missed/false signal from the reed switch circuit.
 
  • Like
Reactions: vas

salubrious

New member
Joined
2 Aug 2023
Messages
6
Visit site
Thanks for the input Jake and Hurricane.

I was thinking something similar but with transistors. The up switch is at 12V. I was planning on running the 12V through a 7805 then a voltage splitter to get a 3.3 to GPIO interrupt. I origially thought I could just run the reed switch at 3.3 but after your guidance I think I'll run it at 12 then step it to 3.3 as well in the same fashion.

After the 7805 regulated 5V then I'm pretty confident I'll have a decent edge for the interrupt to sense.

I had absolutly not thought about the windlass run on so would have been confused for a bit. Do you worry about a run on in the Up direction? I have never really paid that much attention but I think it stops pretty darn quick.

My general plan is that I want Mr Pi to monitor a whole bunch of things so I will have an application running on Pi startup which stores everyting in a Db and then a website which can access it. I want to be able to activate things (like windlass Up/Down) from my iPhone so I have setup a Flask website with ngninx so I can use Python to easily hit the Gpio's from the web.

Python is a bit of a weird ol' language. I didn't realise until I saw Mr Hurricane's code that you could do it in node.

Thanks for your help guys. I really appreciate it.
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
Thanks for the input Jake and Hurricane.

I was thinking something similar but with transistors. The up switch is at 12V. I was planning on running the 12V through a 7805 then a voltage splitter to get a 3.3 to GPIO interrupt. I origially thought I could just run the reed switch at 3.3 but after your guidance I think I'll run it at 12 then step it to 3.3 as well in the same fashion.

After the 7805 regulated 5V then I'm pretty confident I'll have a decent edge for the interrupt to sense.

I had absolutly not thought about the windlass run on so would have been confused for a bit. Do you worry about a run on in the Up direction? I have never really paid that much attention but I think it stops pretty darn quick.

My general plan is that I want Mr Pi to monitor a whole bunch of things so I will have an application running on Pi startup which stores everyting in a Db and then a website which can access it. I want to be able to activate things (like windlass Up/Down) from my iPhone so I have setup a Flask website with ngninx so I can use Python to easily hit the Gpio's from the web.

Python is a bit of a weird ol' language. I didn't realise until I saw Mr Hurricane's code that you could do it in node.

Thanks for your help guys. I really appreciate it.
Yep - I do think that a higher voltage than the 3v3 is advisable.
But I know someone who is using a Pi Pico to control a crane on the boat and is successfully using the 3v3 signals for his input.

For those who don't know - a Raspberry Pico is just £3.90 inc VAT - doesn't run Linux - just simple Python apps but it is really cheap.
The next range of Raspberry Pis is the Pi Zero - starting at £5 but you would probably use the WiFi one at £17
The main Raspberry Pi these days is the Raspberry Pi Model 4 but the older Model 3B is still available.
The Raspberry Pi Model 4 starts at £35 but you would probably be paying £45 for the 2Gb version.
All the Zeros, the Model Bs and the Model 4s run Linux so you can install most industrial software onto them.

Isn't it great that the Pis are back in production and available to us again.

Windlass run on
Yep - in both directions.
IIRC, I introduced a delay (I think it was 3 seconds) to cover the motor run down.
Like you, I didn't think it would be an issue - as you say, the seem to stop quickly.
Mine was very inaccurate until I wrote the over run software - then it suddenly became very accurate.

My approach is quite different - I tend to use one RPi for each task so as not to over complicate it.
After all, they are only 30 to 40 quid each.
That said, I have wired and WiFi LANs on board so they can all intercommunicate if required.
For example, the main ships computer can easily SSH into any of the Pis.
In some cases, I even use remote desktops to GUI systems.

On this project, node.js was a new one for me but it was quite impressive.
Once you get your head round its single threadedness.
Another benefit with node.js is that it incorporates a simple (single page) web server which is ideal for this kind of thing.
I used a node.js library to handle the interrupts and switch debounces etc
That library (called onoff) was worth its weight in gold.

I hate Python but there are times that you have to use it.
What modern language in this day and age can change an application's whole functionality by simply changing the way that code is "tabbed in"

Finally, my chain counter's web interface cheats.
In order to get a "real time" display of the chain counter, I resubmit the webpage every second.
I should really use Web Sockets or something similar Ajax/Jason or something like that.
But the simple thing was to write the web page with this HTML
<head>
<meta http-equiv="refresh" content="1" />
</head>
Nice and simple - even though it isn't very professional!!

I think I will create a new thread on my latest audio project.
I know this is a boating forum but it seems that some people are interested in these great boat related RPi projects.
 
Last edited:

salubrious

New member
Joined
2 Aug 2023
Messages
6
Visit site
Tabs!!!! I know right. Why???

Anyways i have the code running now. I am a software engineer so it is just another language.

I will post my fulll solution once i get V1 implemented.

Thanks again for your help.

Cheers
Jeff
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,082
Location
Volos-Athens
Visit site
Tabs!!!! I know right. Why???

Anyways i have the code running now. I am a software engineer so it is just another language.

I will post my fulll solution once i get V1 implemented.

Thanks again for your help.

Cheers
Jeff
not a s/w engineer at all, but enjoy playing one at the boat...
implemented the same sort of thing on a teensy 3.5 (programmed using arduino IDE) and I also try to get these small chips do as much as they can.
On the particular one doing the anchor chain counting using interrupts I also had some DS18B20 one-Wire sensors keeping track of a couple of fridges temps on a 30sec rate and sending them via NMEA2000 to a r-pi doing the signalK/influxDB and all sorts of other things.
To cut a long story short, at the start of this season I'd drop (using the motor) 50m of chain it would measure 40 and retrieve 50 :)
temporarily stopped doing the sync reading of these one-wire sensors and last week the discrepancy was down to 0.3m (basically lost one gypsy turn somewhere which I can live with tbh)

So, careful if you overload these things not to start miscalculating signals

V.
 

jakew009

Well-known member
Joined
29 May 2012
Messages
428
Visit site
not a s/w engineer at all, but enjoy playing one at the boat...
implemented the same sort of thing on a teensy 3.5 (programmed using arduino IDE) and I also try to get these small chips do as much as they can.
On the particular one doing the anchor chain counting using interrupts I also had some DS18B20 one-Wire sensors keeping track of a couple of fridges temps on a 30sec rate and sending them via NMEA2000 to a r-pi doing the signalK/influxDB and all sorts of other things.
To cut a long story short, at the start of this season I'd drop (using the motor) 50m of chain it would measure 40 and retrieve 50 :)
temporarily stopped doing the sync reading of these one-wire sensors and last week the discrepancy was down to 0.3m (basically lost one gypsy turn somewhere which I can live with tbh)

So, careful if you overload these things not to start miscalculating signals

V.
A Raspberry Pi (4) is like a supercomputer compared to a single threaded Arduino ;)

I must admit it made me smile when I read Hurricane's concern about whether the RPI can read the gpio pin fast enough :) I think it can read accurately at like 20 KHz (20 thousand reads per second), if you're anchor chains going out that fast I think you have different problems ;)
 

vas

Well-known member
Joined
21 Jun 2011
Messages
8,082
Location
Volos-Athens
Visit site
teensy is indeed single threaded but running its ARM processor at 120MHz, it's a mean machine you know :rolleyes: It's good fun (and lots of swearing!) trying to get it to do complex stuff.
Another one runs my hydraulic stabs reasonably well but could do with a bit more cpu power there 😁
 

GarryF

New member
Joined
6 Nov 2020
Messages
12
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.
Hi Mike, BIG BIG thanks for this post and the serious amount of detail that you have included.
Like yourself, whilst I have a technical background, I have no formal training in coding, but over the years I have 'dabbled' in some very basic scripting. I am a very keen DIYer, both at home and on the boat, preferring the hands on approach wherever possible, and our old boat has offered plenty of opportunity to get my hands dirty, so this post is very much welcomed.
This year, following comments from "the Management", I promised to investigate the various commercial chain counters available for our boat but fortunately before committing to any purchase, I stumbled across your excellent article, and obviously this offers me the opportunity of keeping both of us happy.
Over the winter break I intend to use the article to 'build' a copy of your chain counter for installation next Spring.
Many thanks again. Garry
 

John100156

Well-known member
Joined
31 Oct 2007
Messages
2,651
Location
SANT CARLES DE LA RAPITA
Visit site
Don't forget the Pico W too: I have completed several projects recently using these, one with touch sensors to adjust up/down a heating and cooling HVAC control with a simple LCD display (must buy some OLEDs to play with. In fact, I am likely to change my crane control over to Pico-W soon.

Took me a week to get around coding in microPython instead of Python, but cheap as chips.

What I like is once you complete the code/program you just name it main.py and it runs quickly as soon as its powered up. Lots of ADC, i2C and GPIO pins. I do like opto-couplers but still a bit old-fashioned so tend to use relays to control power side.
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
Don't forget the Pico W too: I have completed several projects recently using these, one with touch sensors to adjust up/down a heating and cooling HVAC control with a simple LCD display (must buy some OLEDs to play with. In fact, I am likely to change my crane control over to Pico-W soon.

Took me a week to get around coding in microPython instead of Python, but cheap as chips.

What I like is once you complete the code/program you just name it main.py and it runs quickly as soon as its powered up. Lots of ADC, i2C and GPIO pins. I do like opto-couplers but still a bit old-fashioned so tend to use relays to control power side.
Most of you will know that John and I are good friends - in fact, I pass his boat on the way to mine.
So, John will take this post in the constructive tone that it is.

Background
There are two main ranges in the Raspberry Pi - lots of products but two main concepts.
The Pico that John is talking about really is "as cheap as chips" starting at £3.90 including VAT!!
Yes under 4 quid.
All the I/O is there on the cheapest Pico but if you want WiFi it is £6.30.
Then you will need a power supply and connectors but these aren't expensive either.
This is a Pico
Pico.resized.png
The other (serious range) is the Raspberry Pi itself.
Starting at the Raspberry Pi Zero ranging from £15 to £17 including VAT
This is a Zero
Zero.resized.png

Years ago, it was the RPi1 and RPi2 but most projects these days will use the RPi3, RPI4 or the new RPi5.
These models vary from £25 for a Model 3A up to £79 for the latest RPi5 with lots of memory.
Personally, I think the RPi Model 3B is the best "bang for buck".
This is a Raspberry Pi Model 3B - The size of a credit card.
RPi3.resized.png
The final RPi range is an interesting one - the CM4.
It, essentially, contains all the computing power of a RPi but without any of the interfaces.
It "piggy backs" onto a dedicated motherboard for dedicated applications.
We are gradually seeing these CM4s appearing as the heart of systems.
This is a CM4
CM4.resized.png


And this is the kind of place that they are being used
CM4 Piggy.resized.png


Anyway, my point is that ALL these devices are cheap enough to include in a project.
But, apart from the Pico, all the others run Linux - a proper operating system.
As an example, John mentions how the Pico can be made to start a program after power up.
But, with Linux we are talking about a "full blown" operating system - the same that is used in multiple professional cloud applications.
Recent versions Linux use "systemd" which is a professional method of running applications under Linux as a service.
And services can be started at power up.
So rather than a quick fiddle using Python and the Pico, Linux on the bigger RPis does the job exactly the same way as the professionals.
So to illustrate my point - why not use a proper computer operating system for very little more money.

John also talks about using relays instead of opto isolators.
I don't think it is a matter of being old-fashioned so much as picking the hardware for the job.
John's project is, essentially, outputting to his crane so a relay is perfectly satisfactory.
But my Anchor Chain project counts inputs.
Virtually all inputs suffer from switch bounce (at the exact moment a switch is closed, it makes and breaks the circuit several times).
I could probably get away with the anchor's reed switch bouncing if it were driving a relay but the relay switches that connect to the RPi would have to have some form of debouncing.
Debouncing can be done in hardware using a resistor capacitor network but it is much easier to do it in software.
Using opto isolators, we can make it a software problem to resolve.
Again, by choosing a RPi running Linux meant that I had a wealth of software available - software from the professional world.
In my case, I chose to use node.js which is widely used out there and has some excellent debouncing libraries.

Another benefit of using a full Linux system is the ease of connecting to the system for any future issues that may crop up.
I connected my Raspberry Pi Anchor Counter to my ships wired LAN.
Last week, I wanted to check something in the Chain Counter's software so it was simply a matter of powering it up and connecting the ship's PC to it using SSH (a secure terminal application).
And then all the software tools that I needed were there already on the RPi ready to use.

OK - so this is a very geeky subject but DIY enthusiasts are making projects like this all the time.
Anyone interested - Google is your best friend.
 

Hurricane

Well-known member
Joined
11 Nov 2005
Messages
9,587
Location
Sant Carles de la Ràpita
Visit site
Following my last post, I would like to say something about Linux itself.
Linux seems to me to be the biggest misunderstood secret ever.
Linux is everywhere - a fact that most people don't understand.
Literally everybody uses it - without knowing it.
Your home router probably uses it - your TV set top box probably uses it - a huge percentage of professional servers in the cloud use it - Google's Android (as in phones and tablets) IS Linux.
Even Microsoft use it - WSL (Windows Subsystem for Linux) and more recently, Microsoft have Linux installation notes on their website.
So, as I say, a huge secret to most people.
The big area where Linux hasn't yet conquered is in desktop computing.
Windows still seems to be the popular way of running home/office Desktops and Laptops.
I find this difficult to understand.
Why tie yourself to Microsoft accounts and do things they way they want you to?
Linux is free (as in freedom) so you can do anything you want without having to sign in to a Microsoft account.
You can choose what desktop environment you like.
Personally, I like the old Classic Windows environment like we had in Windows 95/98/2000/XP etc
I'm a dinosaur so I also choose a light theme because I don't like all the dark colours that people tend to use these days.
But it is completely up to you.

People often say that Linux doesn't support their software.
To a small extent, this is true but applications these days are becoming more and more multi platform.
For example, what do people actually use their computers for?
If it is just Internet browsing, and some office work, there are loads of Linux compatible applications out there - (LibreOffice for example is 100% Microsoft Office compatible - but free).

This brings me to Open Source Software in general.
Why pay for software when you can use it for free.
When talking to small business owners, I have been astounded at their negative reaction to Open Source Software.
One person recently said that security was an issue to them - thats why they use paid software, they said.
That statement is simply wrong - by using Open Source the software can be audited - something you can't do with Closed Software.
So, if there was a back door in the software, the Open Source community would KNOW.
With Closed Source Software you would never know.
I wonder if anyone remembers in Microsoft's Excel a few years ago (Excel 97), there was an hidden "Space Simulator" - do you call that a professional feature? - NO but it shows just how Closed Source is actually less secure than Open Source software.
And remember Open Source Software is free - so why not use it?

Linux.resized.resized.png

Wondows.resized.resized.png

Mac.resized.resized.png

So, why not give it a try - breathe life into an old computer - for free.
 

John100156

Well-known member
Joined
31 Oct 2007
Messages
2,651
Location
SANT CARLES DE LA RAPITA
Visit site
All good Mike - I always splash out and buy the Pico-W which has headers already soldered in/on, eyes are not as good nowadays when soldering pins even with magnification! ☹️.

As you know, all Pi's can code-out switch bounce, crudely by using say a 0.1s delay, or better still to use the GPIO Rising/Falling command(s). Its truly amazing how cheap these devices are; with most of my projects I only use a tiny amount of their capabilities. Don't forget the speed and versatility of the new RPi-5, which has to be one of, if not the best, SBC for the money on the market today!

I am presently having fun coupling the Pico to OpAmps (Operational Amplifiers) due to that chips very high input impedance and low output impedance, they couple well to the Pico. I am using them with a low gain of 4, a pot and a few passive components to produce a fully adjustable and smooth(ish) 0-10Vdc output, with Vcc/Gnd powered by a separate 12Vdc supply, but easy to convert to 24Vdc too. You don't need a separate chip, the Pico has built in ADC as well as i2C on several GPIO pins.

Mike, ADC/OpAmps may be useful if at some stage we want to amplify and read the LP/HP pressure sensors on the Cruisair Condenser units that we have been playing with, with i2C and a nice OLED or similar display and a heating and cooling program (just written some simple micorpython code that works) might be a fun project for next year, after all the hassle that we had getting old boards to repair our units.

Anyway, enough jargon, got to work out how to code-in an interrupt on something I am working on for my son, as a true novice, I am enjoying the learning curve....
 

jakew009

Well-known member
Joined
29 May 2012
Messages
428
Visit site
I think there is a lot to be said for using a Pico / other micro controller rather than a full on linux box.

The microcontroller can boot and start running code in a fraction of the time a RPi could boot and you don't have to worry half as much about SD card corruption etc.
 

starfire

Well-known member
Joined
7 May 2005
Messages
1,212
Location
In the Med
Visit site
Most of you will know that John and I are good friends - in fact, I pass his boat on the way to mine.
So, John will take this post in the constructive tone that it is.

Background
There are two main ranges in the Raspberry Pi - lots of products but two main concepts.
The Pico that John is talking about really is "as cheap as chips" starting at £3.90 including VAT!!
Yes under 4 quid.
All the I/O is there on the cheapest Pico but if you want WiFi it is £6.30.
Then you will need a power supply and connectors but these aren't expensive either.
This is a Pico
View attachment 166699
The other (serious range) is the Raspberry Pi itself.
Starting at the Raspberry Pi Zero ranging from £15 to £17 including VAT
This is a Zero
View attachment 166700

Years ago, it was the RPi1 and RPi2 but most projects these days will use the RPi3, RPI4 or the new RPi5.
These models vary from £25 for a Model 3A up to £79 for the latest RPi5 with lots of memory.
Personally, I think the RPi Model 3B is the best "bang for buck".
This is a Raspberry Pi Model 3B - The size of a credit card.
View attachment 166701
The final RPi range is an interesting one - the CM4.
It, essentially, contains all the computing power of a RPi but without any of the interfaces.
It "piggy backs" onto a dedicated motherboard for dedicated applications.
We are gradually seeing these CM4s appearing as the heart of systems.
This is a CM4
View attachment 166706


And this is the kind of place that they are being used
View attachment 166707


Anyway, my point is that ALL these devices are cheap enough to include in a project.
But, apart from the Pico, all the others run Linux - a proper operating system.
As an example, John mentions how the Pico can be made to start a program after power up.
But, with Linux we are talking about a "full blown" operating system - the same that is used in multiple professional cloud applications.
Recent versions Linux use "systemd" which is a professional method of running applications under Linux as a service.
And services can be started at power up.
So rather than a quick fiddle using Python and the Pico, Linux on the bigger RPis does the job exactly the same way as the professionals.
So to illustrate my point - why not use a proper computer operating system for very little more money.

John also talks about using relays instead of opto isolators.
I don't think it is a matter of being old-fashioned so much as picking the hardware for the job.
John's project is, essentially, outputting to his crane so a relay is perfectly satisfactory.
But my Anchor Chain project counts inputs.
Virtually all inputs suffer from switch bounce (at the exact moment a switch is closed, it makes and breaks the circuit several times).
I could probably get away with the anchor's reed switch bouncing if it were driving a relay but the relay switches that connect to the RPi would have to have some form of debouncing.
Debouncing can be done in hardware using a resistor capacitor network but it is much easier to do it in software.
Using opto isolators, we can make it a software problem to resolve.
Again, by choosing a RPi running Linux meant that I had a wealth of software available - software from the professional world.
In my case, I chose to use node.js which is widely used out there and has some excellent debouncing libraries.

Another benefit of using a full Linux system is the ease of connecting to the system for any future issues that may crop up.
I connected my Raspberry Pi Anchor Counter to my ships wired LAN.
Last week, I wanted to check something in the Chain Counter's software so it was simply a matter of powering it up and connecting the ship's PC to it using SSH (a secure terminal application).
And then all the software tools that I needed were there already on the RPi ready to use.

OK - so this is a very geeky subject but DIY enthusiasts are making projects like this all the time.
Anyone interested - Google is your best friend.
A little ot I know.

Looking to start playing with Raspberry Pi, I've lot's of electronics skills but little coding.

The intent is setup a Zigbee temp & humidity sensor network & be able to log & display this.

Any recommendations both for the Pi part & zigbee sensors.
 

Parabordi

Active member
Joined
22 Apr 2011
Messages
886
Location
Medway
Visit site
People often say that Linux doesn't support their software.
To a small extent, this is true but applications these days are becoming more and more multi platform.
For example, what do people actually use their computers for?
If it is just Internet browsing, and some office work, there are loads of Linux compatible applications out there - (LibreOffice for example is 100% Microsoft Office compatible - but free).

So, why not give it a try - breathe life into an old computer - for free.
i agree with a lot of what you say, but the problem with LibreOffice, is no Outlook equivalent. Anyone that still works, needs Outlook to get to Shared Calendars for setting up meetings and Outlook allows you to create a meeting for Teams. If they could crack that problem, i think i would definitely use it.
 
Top