Attaching a stepper to the big gauge is a bit more of a challenge. I'm pretty keen on maintaining the original appearance of the gauge, so from the front it needs to appear unmodified, but there isn't a lot of room in the back for the motor.
Here's how it looks in bits:
Some modification is necessary - I cut off the back (well, more snapped off really...) support for the rear bearing which makes just enough room for the motor. I cut down the needle shaft so the motor would fit in the back and then pushed a bit of wire insulation over the shafts to join them together. I also removed the return spring and damper - these aren't used any more and were just getting in the way.
Getting everything back together was tough, but, now it looks like this:
Almost original.
Now my attention turns to driving the thing. I'm going to put an Arduino between the Pi and the stepper to drive it. I could continue to transmit the required position in an RC PWM format and use the Arduino to capture the pulse length, but a better option I think is to use the serial port and just send the position directly.
The sample Arduino code already looks for a serial command, the only modification I need to make is the maximum position. The gauge moves through about 120 degrees so I need a maximum of (120*3) 360 degrees.
Finally, a modification to the python script:
from bs4 import BeautifulSoup
import requests
import time
import serial
wind_max_pos=362
wind_min_pos=0
wind_range=float(25)
ser = serial.Serial('/dev/ttyAMA0', 4800)
lookup=[0,7,14,27,41,57,75,93,112,128,146,160,176,192,206,220,235,250,265,279,292,304,317,330,343,357]
r=requests.get("http://www.bramblemet.co.uk/wap/")
data=r.text
soup=BeautifulSoup(data)
link=soup.find('a')
p=requests.get(r.url[:-18]+link.get('href'))
windpage=p.text
soup=BeautifulSoup(windpage)
windspeed=int(soup.prettify()[309:315])
print("The current windspeed in the Solent is: "+ str(windspeed)+" Knots")
if windspeed>wind_range:
windspeed=wind_range
position=lookup[windspeed]
if position<wind_min_pos:
position=wind_min_pos
ser.write(str(position))
ser.write("\n")
ser.close()
print(str(position))
A little bodge here, I'm connecting the Pi TX pin to the Arduino RX directly. The Pi is of course running at 3.3V and the Arduino at 5V. 3.3V is sufficiently high to register as a '1' on the Arduino. I feel safe doing this as the Custard Pi shield has Zeners to prevent damage to the Pi should 5V somehow end up on the TX pin.
When the script is run, the needle moves! Win.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.