On 02/05/2026 11:59, Terry Coles wrote:
That's exactly what I am currently doing.
So I connected a Pi to a skeletal circuit using a breadboard and
installed the operational code on it. Here are the relevant code
fragments, including a debug print statement to count the loops:
# Calculate how many times to continue checking if the has passed a Sensor.
sensor_pause_time = 0.05 # Time in seconds for the program to
pause each time round the Sensor test loop.
# Calculate number of loops in out leg.
sensor_test_time_out = 8 # Time in seconds required.
sensor_test_loops_out = (sensor_test_time_out / sensor_pause_time)
print(sensor_test_loops_out)
# Calculate number of loops in back leg.
sensor_test_time_back = 8 # Time in seconds required.
sensor_test_loops_back = (sensor_test_time_back / sensor_pause_time)
print(sensor_test_loops_back)
.....
print("First Leg Out. Waiting for Sensor B after speed reaches max.")
train_start() # Train will start and
accelerate towards the Tunnel.
print("Out of Train_start")
i = sensor_test_loops_out # Set the loop counter
to give the required time testing for the sensor
while i >= 0:
i = i -1
if GPIO.input(sensor_b): # GPIO Pin 6 (sensor_b)
is pulled up, so while loop continues until line goes low or the loop times out
time.sleep(sensor_pause_time)
else:
print ("Sensor B Activated")
break
To mimic the on site hardware, I pulled up GPIO Pin 6 and grounded it
after the loop started. Everything worked as expected so we still have
something amiss in the hardware.
--
Terry Coles
--
Next meeting: Online, Jitsi, Tuesday, 2026-05-05 20:00
Check to whom you are replying
Meetings, mailing list, IRC, ... https://dorset.lug.org.uk
New thread, don't hijack: mailto:[email protected]