mrdman
Posts: 5
Joined: Fri Oct 02, 2020 9:22 am

GPIO connection to existing bike sensor

Fri Oct 02, 2020 9:47 am

Hi,
I want to connect my static exercise bike to my Raspberry Pi.
Currently it has a basic computer which connects via a mono 3.5mm jack to the base of the bike. I'm assuming it's a reed switch.
Measuring between shield(black probe) and tip(red probe), I read -2.8V when off. 0V when the pedals are in a specific position.
So I'm assuming the shield is tied to B+ in the bike computer, and the tip is the input pin to the microcontroller (which must be pulled down).
Or, the tip is B- and the shield must be the input to the microcontroller (which must be pulled up).

Now my thought is, I can sniff off the signal using a splitter cable, but just want to confirm if my thoughts are correct.

I don't want to open up the bike computer if it's not necessary, and I think all I will need to do is add a Schottky inline with the GPIO pin, and I should be fine no matter what the condition.

I've drawn four diagrams to explain my thinking.
The top two are the options that the bike reed switch could be set up. As the bike isn't grounded, I believe it will work no matter which setup the bike has.
Image

The bottom two are more of a thought experiment if I stupidly swap leads going in to Pi for whatever reason. Again, I believe no harm would be done.


I think in all cases, the Schottky stops any issue with the GPIO pin being changed to an output.

Does anyone see a flaw in my plan?

jayben
Posts: 501
Joined: Mon Aug 19, 2019 9:56 pm

Re: GPIO connection to existing bike sensor

Fri Oct 02, 2020 7:00 pm

What is the point of the diode? Why would you ground the +ve side, rather than the -ve? If your signal is going from 0 to +2.8V, then in theory you could just connect it straight to an input on the Pi.

In practice, that'd be quite risky, as there might be spikes or a malfunction that took the voltage below 0V or above 3.3; the best way to handle that is to reduce the fault current down to a non-damaging level. If you put, say, a 10K resistor in series then the maximum current would be under 1 milliamp, which is sufficiently low that it can't do any harm.

A belt-and-braces approach would be to put clamping diodes to power & ground, but these wouldn't be essential, if the maximum current is low enough. It might be a good idea to add some shunt resistance to the input (maybe 100K) so that it doesn't float around generating a spurious signal when the input is disconnected.

The only downside of adding an input resistor is that the response time will be a bit slower (due to the combination of series resistance & shunt capacitance) so it may stop working if the input is over a few megahertz, but presumably you won't be pedalling quite that fast...

mrdman
Posts: 5
Joined: Fri Oct 02, 2020 9:22 am

Re: GPIO connection to existing bike sensor

Sat Oct 03, 2020 4:08 pm

The idea of the Schottky is for when the GPIO gets set to output accidently. 3V won't get shorted to ground.

Yes, a series resistor seems a good idea. Was considering that. Will add a 10k in series with the diode.

I've just realised I made a mistake with how I drew the two options for how the bike could be set up. I've corrected it below...

Image

So with the 10k in series with the diode, I think I should be fine no matter which of the two ways the reed switch is connected to the bike right? ( I want to avoid opening the bike computer to check.)
And also I should be good against any spikes, polarity mistakes with my cables and if I set GPIO accidently to output.

jayben
Posts: 501
Joined: Mon Aug 19, 2019 9:56 pm

Re: GPIO connection to existing bike sensor

Sun Oct 04, 2020 12:17 pm

The 10K resistor alone would provide adequate protection against damage if the Pi pin is set as output, and you might find that the 2.8V signal minus the diode voltage-drop is sufficiently low that the Pi doesn't register the switching properly, but give it a go...

User avatar
pasman1
Posts: 245
Joined: Mon Aug 10, 2020 3:01 pm
Location: Poland

Re: GPIO connection to existing bike sensor

Sun Oct 04, 2020 1:22 pm

maybe better is to use optocoupler + resistor.
Pi4-4G RaspiOS 32 BuLlSeYe

Brandon92
Posts: 949
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: GPIO connection to existing bike sensor

Sun Oct 04, 2020 2:05 pm

mrdman wrote:
Fri Oct 02, 2020 9:47 am
Currently it has a basic computer which connects via a mono 3.5mm jack to the base of the bike. I'm assuming it's a reed switch.
Did you check that it is a reed contact with your multimeter or do you think it is. It could also be another sensor for example a halo sensor. If there is enough contact on the Jack connector.

If it is a reed contact then you don't want use a optocoupler. Because you will load the controller and it might not detect it correctly that it is closed. Or you need to find a optocoupler that has a very low current to operate, what is possible.
When it is a other type of sensor it could become a bit more difficult.

Is that voltage what you measurd in a steady state. So the wheel is not turning. If it is then your multimeter could measure it wrong.

mrdman
Posts: 5
Joined: Fri Oct 02, 2020 9:22 am

Re: GPIO connection to existing bike sensor

Mon Oct 05, 2020 9:06 am

Yes, I hear your point about 2.8V being a little low for the luxury of using a diode in series. My only worry was -2.8V into a GPIO pin. But maybe I'll look into a keying connector to stop that happening mechanically rather than stopping it electrically.
(Edit: Also, I just realised I drew the "swapped leads" diagram on the wrong side. I wouldn't be swapping on the reed switch side as that's a jack. I'd be swapping on the Pi side, and so the diode wouldn't even help me there.)

To answer the questions about which sensor is in the bike, I don't know anything apart from the fact that I read steady 0V when the pedals are in one specific position, and steady 2.8V when in any other position. So all I'm doing basically is using the raspberry Pi as a very crude multimeter, (detecting if there is a voltage present, or not).

Yes, I have also checked on my scope in case my multimeter was missing anything.
Image


I think the next thing now then is to add the 10k resistor inline with the GPIO, hook it up to the bike and test to see what behaviour I get.

Brandon92
Posts: 949
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: GPIO connection to existing bike sensor

Mon Oct 05, 2020 5:57 pm

You could measure the resistance of the "reed relay" to check it. When there is no magnet the resistance is very low and when there is a magnet the resistance very high (you wont measure it). Or the other way around. But if it is a reed relay I would not expect the puls that you get in the second scoop picture.

This is a intressting article on how to protect a digital input. Maybe it is interesting for you. But I would advice not to use a pull-up or pull-down resistor in your case.

Can you find the sensor as a spare part for you bike. Maybe the description would give you a hint what for type it is.

mrdman
Posts: 5
Joined: Fri Oct 02, 2020 9:22 am

Re: GPIO connection to existing bike sensor

Mon Oct 05, 2020 9:08 pm

Yes, reading dead short and OL.

Thanks for the design sheet on microcontroller inputs. Very useful. Will save that.
I was trying to keep the design to a simple cable at this stage. I have added the 10k resistor inside the mini jack itself. But maybe I should consider just putting a hat onto the Pi and then having the luxury of using all protection I want. Is there a standard PCB connector people use for the GPIO pins? I'll order a few next time I do an order. Harwin M20-7832046 maybe?

It's the cheapest bike on amazon, so no spares out there.

cagnulein
Posts: 7
Joined: Sun Jan 27, 2013 7:15 am

Re: GPIO connection to existing bike sensor

Wed Oct 21, 2020 9:53 am

Hi mrdman, i was starting the same project when i was your post!
Did you already do the connection? I would like to connect it to my existing project ( https://github.com/cagnulein/qdomyos-zwift ) in order to have my bike connected to zwift.

ElEscalador
Posts: 950
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA

Re: GPIO connection to existing bike sensor

Wed Oct 21, 2020 12:07 pm

I would bet $5 that your sensor is a hall effect sensor rather than a reed relay. It makes a little difference in that the 2.8v you're reading probably is not truly the thing sourcing 2.8v, but rather it's a voltage from the sensor floating. (With hall effect sensors, they usually float without the presence of a magnetic field and drive actively low when the field is present. Try pulling your 2.8 low with a big resistor (maybe 10k) and I'd be surprised if it doesn't drop to zero. Long story short - I'd pull the input pin you want to use high with a 10k resistor and connect it to the sensor with no other circuitry. Your event for your callback function then is when the pin reads low (that means the magnet is near).
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics

cagnulein
Posts: 7
Joined: Sun Jan 27, 2013 7:15 am

Re: GPIO connection to existing bike sensor

Wed Oct 21, 2020 12:14 pm

ElEscalador wrote:
Wed Oct 21, 2020 12:07 pm
I would bet $5 that your sensor is a hall effect sensor rather than a reed relay. It makes a little difference in that the 2.8v you're reading probably is not truly the thing sourcing 2.8v, but rather it's a voltage from the sensor floating. (With hall effect sensors, they usually float without the presence of a magnetic field and drive actively low when the field is present. Try pulling your 2.8 low with a big resistor (maybe 10k) and I'd be surprised if it doesn't drop to zero. Long story short - I'd pull the input pin you want to use high with a 10k resistor and connect it to the sensor with no other circuitry. Your event for your callback function then is when the pin reads low (that means the magnet is near).
thanks! I will try and i will let you know!

mrdman
Posts: 5
Joined: Fri Oct 02, 2020 9:22 am

Re: GPIO connection to existing bike sensor

Mon Nov 16, 2020 6:49 pm

cagnulein wrote:
Wed Oct 21, 2020 9:53 am
Hi mrdman, i was starting the same project when i was your post!
Did you already do the connection? I would like to connect it to my existing project ( https://github.com/cagnulein/qdomyos-zwift ) in order to have my bike connected to zwift.
Sorry, only just saw this.
Yes, mine works fine. As I mentioned, I'm really just piggy-backing off what is there and just using the Pi as a sort of crude DMM to tell me if the voltage at the sensor is low or high.

Return to “Other projects”