Wibbes wrote:hi bard
long time since i have being looking into this, i have started working back in windows to give it a bit more power for a 6 lane setup.
one the main problems for the pi is its speed, especially when trying to monitor 2 or more lanes it becomes very hard to time them accurately , think best i got to be reliable was around 0.25 of a second on 2 lanes maybe 0.2 if i trimmed it down a bit on the drawing cycles for the screen.

to be fair even in windows its hard to do real timings without dedicated external hardware to do the timing( arduino or over micro).

You probably could get more speed by changing how you draw and update the screen - if graphics is the bottleneck. Pygame is not very fast at drawing and updating the screen on the Pi. But the whole approach of having the timing (stopping of the timer) depend on the GUI loop seems to me flawed. With that approach you can't expect to get better timing resolution than the GUI's frame rate.

Maybe you could separate the timing loop from the display/control loop into a separate thread or process?

Another idea: While I don't know anything about how the GPIO works - but would it somehow be possible to use interrupts instead of reading the state periodically?

You code seems clean and simple and hope that some more experienced in Python and GPIO would take a look and show how to achieve a better timing resolution.

However, the current lap time and power control is via a clunky old laptop with a parallel printer port so I was always looking to convert the control element to an integral Raspberry Pi at some point.

Hopefully the links will help those in need of some more info on the basic slot car control electronics at least.

After double-checking, I really think a Pi unit can easily track a few events per second (start the clock, record track times for a few lanes, ....).
I will investigate more wth Python and C# to find pieces of code or a friend that could do it for me (I haven't coded in decades and have to see if I can do it again in langages I would have to learn...).
Let's keep investigating and keep in touch.

@joan and @Sleep Mode zZ: totally agree with you guys

@nigel.arnold: the different electronic setups for lap timing (photocells, dead strip, webcams, Reed or Hall effect sensors,....) amount to the same for the prog: recording an event (line x, time) after seeing a pulse on a "port"

My approach would be as Sleep Mode zZ suggested:

- a process/thread for the display
- another process for the clock

When a car passes the line (thus generating an interrupt/pulse), recording of the time and the lane is sent to the "database" and the display process.
In this case, even if the display in a little slow, we are closer to getting accurate timing on all events stated before (timing sectors, jump starts,...)

I'm sure as soon as this project gets momentum, more coding experts will contribute.

Hi
I'm pretty New to coding and was given the task of making a time attack system for drift trike racing. I'm thinking of getting some pir motion sensors and rigging them up as start and finish lines on the course. This project seems to be suited although I don't require laptimes. Just a start and stop. How could I modify the code for 2 sets of gpio pins one to start. The other to stop the stopwatch? Any help would be fantastic

Hi all,
I put a litte stop watch, race timer together using my Pi 2, IR-LEDs and Python. It's not pretty and I'm going to add some Pygame graphics later on (any help here highly appreciated), but it's working

It handles 2 lanes, best lap time for each track (please note you need to create the empty files using the files names in the code for this).

The electrical circuits are presented in attached pictures along with component lists.

As promised, I've now managed to learn some basic Pygame and updated the Race timer accordingly.
You can also run another race without exiting the program. Fonts, images and sounds can be downloaded from enywhere.

A couple of lessons learned:
1. GPIO.cleanup() did not remove GPIO.add_event_detect, which was causing trouble with multiple firing of events at the same time during reruns of the timer.
2. Running python from IDLE3 over vnc client on my PC rendered no graphics. It was solved using gksu to start IDLE3. Another way was to start it using /usr/bin/python3.4 without gksu.

Here is the code for anyone interested. My kids slotcar track has become so much more fun with this
Good luck with your projects! I'm happy to help if anyone has questions related to this.

EDIT: I amended the code slightly to add sound in the end of race and not to reflect -1 lap in the beginning.EDIT2: I've uploaded a video here: https://youtu.be/dPD9qsKATBE

Good thing it's noted. I forgot to mention I solved it using:
GPIO.remove_event_detect(pin/channel), which clears it each rerun of the program, so no problem in my program with that.
So I didn't really have the problem with triggering on up+down, rather the add events kept stacking up, so run 1 was fine, rerun 1it detected 2 laps at a time, 2nd 3 laps etc, despite gpio.cleanup() was run before each rerun.

Keep in mind the bounce time of the events, I've set them to 2500ms, so if you've got faster lap times than that, you need to change it to cater for that or you'll be having problems.
/M

Due to the fact that I'm running the screen on my PC with TightVNC client, I learnt some other things today:
- There is a lot of "hissing" going on over the 3.5mm audio output. To handle this during the race, I've added stopped the sound (pygame.mixer.stop()) and reinitialized it for each run. The HDMI output does not seem to suffer from this, so use it if you can.
- My suggestion is not to run TightVNC over wifi, it's lagging and gets clogged up, whilst LAN-cable works just fine.

Marre wrote:please note you need to create the empty files using the files names in the code for this

I came across your Stopwatch code and plan to adapt it to a solution with a 2.8" GPIO touch screen. It seems that simply touching the necessary files isn't enough. Would it be possible to provide an example?