SlotForum banner
1 - 20 of 553 Posts

Premium Member
280 Posts
Discussion Starter · #1 ·
- This is a restart of my previous thread that for some reason disappeared -

During Christmas I started working on a wireless lap timer based on a wifi-module WeMos D1 mini. It is based on the very common wifi-chip ESP8266 which popularity have really skyrocketed the last year. The price of the modules is very low. The WeMos can be bought for about $4 on eBay.

The Lap timer for Scalextric SSD slot cars does not have its own display. The result page is presented as a webpage served by a web server running on the WeMos. A PC, tablet or smart phone can be used as long as it has a browser with HTML5 and javascript support. Most of the them do.

Lap timer features
  • 1-6 players
  • All time high (best lap time all races)
  • Best lap time last race
  • Placement indexing
  • False start indication
  • Very few parts needed
  • Start lights
  • Start sound
  • 1ms resolution
The All time high result is stored in the browser as a cookie, and is persistent until it is manually removed.
False start is detected and halts the race if one contender is passing the start line within 0.1s after the start signal. The sinner will be indicated with flashing text.
The Winner will be indicated by a flashing text. A new All time high will also be indicated by flashing text.
The physical sensors (one for each track) need to be connected to D1 and D2 on the WeMos. More information (BOM, connection diagram etc.) can be found here
It is a very simple electrical schema.

The full code and all links can be downloaded from bitbucket here

The race is started in one of the following ways,
  • Click the physical button connected to D3 on the WeMos module
  • Press letter R on the keyboard
  • Press the Spacebar on the keyboard
  • Click/point on the webpage where it says PRESS HERE TO RACE!
Pressing C on the keyboard clears the All time high. One can also Click/Press the button "Clear All time high".
Pressing keys 1-6 choose how many players that will compete during the next race. One can also use the drop down menu.

Video showing one of the first versions,

Pictures of my early prototyping/setup here

The lap timer is under development. The software is working quite well, but more need to be done with the hardware. As a sensor I use ITR8307, but I might switch that for another type of sensor.

Premium Member
280 Posts
Discussion Starter · #3 ·
--- Restored from google search ---

QUOTE (RikoRocket @ 9 Jan 2017, 22:45)Sounds great

A couple of questions:

What/how are you doing the ID decryption? The board you show appears to be just a WiFi module.

And what sensors are you using?

The decryption is done in the ESP8266-chip. It is a very capable microprocessor running in 160MHz with some onboard memory.
The sensors is connected to one of its general input/output pins (GPIO), and the identification is easily done in an interrupt routine.

The sensor I use is the ITR8307 that actually is a reflex detector. I planned to also implement support for analog cars. However, in the digital variant only the phototransistor part of the ITR8307 is used. The IR-diode is so far left unconnected.

QUOTE (Drifter2 @ 9 Jan 2017, 23:10)Cool project,
after reading your post I just ordered a WeMos to have a play with.

At a guess, any missed laps could be from the ESP sending wireless data whilst a car passes the sensor.

Great! I look forward to hear your experience with it

Regarding your theory, I am not so sure. When I have done the development I have had a PIC microprocessor generating the signals to simulate 6 fast passing cars.
I made the cars pass within ~24ms and all of them are always detected and reported to the webpage. See the video above.
This rules out your theory.
I rather think that the isolating tape I used close to the sensors to prevent a short circuit, was the real problem. I had not cleaned the area from small pieces of tape so parts of it was covering the sensor. Now it is removed, but I now need to wait until the kids want to race again. (We need to keep the track in its box since we live in an apartment.)

Have fun!

QUOTE (chris99 @ 10 Jan 2017, 14:31)Ordered the bits and looking forward to having a play with this. Wireless and browsers will take it to a whole new level. Many thanks for sharing.

I have tried other Arduino-based detectors, based on the ElectricImages/MIH circuits, but have found occasional missed laps when two trains of three cars pass simultaneously but that's pushing it to the limit.

It is hard to say what the reason could be. By a quick glance I can find several problems.
1. The extra library layer that is put between the bare metal of atmega and the Arduino IDE adds a lot of overhead. The most effective code is written in assembly or C (depending on the quality of the compiler). The library for the ESP8266 seem to me much more effective.
2. I found a link to a *.ino file inside a thread (link) that someone referred to, and the code is not very optimal written. However, the author of the code also makes this clear.
The carID detection routine could for example be optimised.
3. Outputting the result over the serial interface is one of the most heavy things you can do on a Arduino platform. This could mess up the interrupt routines. In my code I output my result to a TCP/IP websocket stream. Considering that the ESP8266 have built in wifi HW support communication over wifi is a very "light weight" output.
4. An Arduino is usually based on atmega microprocessors. They are clocked at 8-16MHz. They need one clock cycle per instruction.
That is probably good enough if programmed in C (or similar), but using the Arduino IDE just makes it on the limit too slow due to the overhead added by the Arduino IDE libraries written for the atmega family. The ESP8266 is clocked in 160MHz running a RTOS. 80% of the MIPS is available to the user. The rest is handling the WLAN. This module runs in circles around the atmega.

Using a faster processor module might work fine, but I would put my money on that the main problem is in the serial output of the arduino based laptimer.
Also I am not sure why two interrupts are used. If one think about it, only one is needed for both tracks in the digital case.

QUOTE (xjr1300sp @ 10 Jan 2017, 22:09)Hi I like this idea can we have more photos of the sensor board and a wiring diagram plus a full list of components please

If you follow the link I posted perviously you will find all the details.
From the git repo
you will find a lot more information in the README-file. There you will find the link to
my google drive share
where you find the wiring diagram and the BOM.

Unfortunately I did not take a photo of the soldering side of the PCB before hot gluing it to the track. But since you have the wiring diagram, I guess that having no photo, does not matter that much.

Premium Member
280 Posts
Discussion Starter · #4 ·
QUOTE (chris99 @ 11 Jan 2017, 16:29)...
It wasn't too difficult as I've uploaded Arduino sketches before, but what was new for me is that you need to copy all files, not just the sketch, from the above webpage-based repository, into a your own Arduino sketch folder in a sub-folder named: esp_slot_car_laptimer
You also have to respect the directory structure with a sub-sub folder called http which contains more files.
The only requirement from the Arduino IDE is that the main ino-file has the same name as the directory it is put inside.
The directory should then preferably be placed inside the default Arduino project directory, but the last is not necessary.

The html-directory is something that I have added to keep all the code in one directory. In the ino-file I refer to a big variable that contains all the html and javascript code. The variable is a compact variant of what is inside the files contained in the http-directory.
The content of the variable is compacted to save space.

There is also a wifi credential-file. It is kept separate so that I can deliver new code without risking to also push in my own credentials into the git reposistory.

QUOTE (chris99 @ 14 Jan 2017, 09:54)Hi,
Just delving into the program a bit. I see the one of the tabs in the Arduino program has the file webpage.h. Can it be edited directly by a user before compiling/uploading to change the webpage font to something like liquid crystal?

Also, just out of interest, I see you have beeps for the countdown. I don't know if it also beeps when a car passes, but would it be easy for the user to substitute an audio file for the beep with a bit of simple file editing or is that a proper programming job?

If you want to edit the html och javascript content, you do that inside the http directory.
the html-code is in the index_base.html and the javascript is inside the main_base.js file.
When you have done your changes, you execute the bash-script,
The script will generate two files.
1. A index.html-file that is compacted and put inside the http directory.
2. A new webpage.h file put in the directory above to be used by the ino-file.

File 1 is to be used when testing. You just point your browser to this file and it will be loaded instead of from the ESP8266. It is much faster to test in that way.
File 2 you do not need to touch. Once you are happy with how the index.html-file works, you just rebuild and upload the code to your WeMos and you are ready to go.

At first I used mp3 or wav files to play sounds. However I wanted the laptimer to be independent of internet connection.
I had two options. Option one, to use a hardware buzzer that connects to the WeMos. Option two, to implement a simple beep that makes the browser beep. I went for the software generated beep to avoid hardware complexity. The hardware is super simple right now.

you can use the following code inside the startRace function to use mp3 or wav file,

CODEfunction startRace() {
var snd1 = new Audio('<mp3 or wav file>'); /* Point to a mp3 or wav file */
:; /* Use this instead of the beep() function */
Google is your friend if you like to know more.

Please download the latest code from git that I uploaded yesterday.
I have done a lot of improvements.
The biggest ones are performance and layout. I have reused the remaining laps field to present the placing in the race. In this way the status page do not occupy so much space.
I have changed so that the lapcounter counts down and not up.
I have improved the minimum time difference between detected cars from 7ms to 0.8ms. I am not sure about what this corresponds to in distance, but it is in the ballpark of 1cm.

Note that this has not been tested with real lightdetectors but only through data generated very fast with a PIC-microprocessor.
The data above only gives an indication of how fast the WeMos module is to handle interrupts.
It can handle 6 cars passing the finish-line with minimum 800us apart each car.


QUOTE (Drifter2 @ 17 Jan 2017, 12:13)Hi Niclas,
have you thought of doing an analog version?
The only additional hardware would be a light bridge. The extra code would be trivial compared to what you have already.
I think that there would be a strong interest in an analog option. Just my 2c :)

The idea of using a reflexdetector (ITR8307) is to be able to later add analog mode as well. Without the need for a light bridge. However, that might not work at all
It was just an idea I wanted to try.

Thanks to both you and chris99 for your feedback.

I have seen that you Drifter2 work on similar stuff as I.
I have created my own power base and in-car-chip myself. And now also the timer.
All system is using SSD, but could of course be changed.
See my other videos on my YouTube channel.

Premium Member
280 Posts
Discussion Starter · #5 ·
QUOTE (Drifter2 @ 22 Jan 2017, 23:40) <{POST_SNAPBACK}>I wonder if the MIH decoder circuit would be useful here. It may need to be tweaked as I think its tied low, active high. Else use "RISING" on the interrupt in software.

That will probably work. If I remember correct, the circuit was a little bit over complicated. I did not really understand why so many components was needed. I will have another look.

The software will probably not need to be changed. Distance between two rising edges and two falling edges is the same.

Premium Member
280 Posts
Discussion Starter · #6 ·
Saved valuable information from google cache, provided by chris99 ...

QUOTE (chris99 @ 15 Jan 2017, 13:39)For info, tests done by RichG with the XLC sensor showed the car IR LED is visible to the sensor for a distance of 10 to 13mm and so a fastish car is "seen" by the sensor for around 3.3ms.

So in theory, even if two cars are passing the two sensors side-by-side, there's enough time to read both cars with your minimum detection time of 0.8ms between cars.
It's probably an ignorant question, but does your system allow both sensors to be read more or less simultaneously, even though there is only pin connection on the Wemos board, such that one sensor's reads during the 3.3ms don't block the other sensor during that time?

2,890 Posts
QUOTE (niclasf @ 23 Jan 2017, 00:26) <{POST_SNAPBACK}>That will probably work. If I remember correct, the circuit was a little bit over complicated. I did not really understand why so many components was needed. I will have another look.

The software will probably not need to be changed. Distance between two rising edges and two falling edges is the same.
Fwiw, I vaguely remember someone commenting that the car IR is so strong that the dual transistor amplification might not be needed.

Another old project used just one transistor per lane (plus resistors).

Premium Member
2,198 Posts
Not yet got the bits and bobs for the sensor end of the project but I have my Wemos board.
All the softwrae and coding downloaded and correctly placed with help from Niclasf and Chriss99.

Connected up the Wemos and uploaded the sketch but was left with the upload failed message at the end, ive attached screenshot if someone could interperet




2,890 Posts
Dave, your inbox is full.

I don't know what he above message means but maybe check the board parameters in the Arduino Tools menu. I'm not sure if they are auto detected but I see settings for CPU frequency, flash size, upload speed .... I don't know what they should be though.

Premium Member
2,198 Posts
Hi Chris,

yes just realised and cleared out some messages.....
I just retried uploading and got a different message but for some reason I cant show the screenshot but it ends:

..................................... (29%)

just off to work so ill try again later

Premium Member
3,083 Posts
Dave, the reason you cannot upload the screenshot and your inbox is full is that your Plus membership has expired and its privileges are no longer available to you. Your gallery is now inoperative, you cannot upload files to your posts and your message inbox has been drastically reduced in size.

Should you wish to renew then go to 'my controls'/ 'purchase paid subscriptions' and follow the instructions.

2,890 Posts
I can't find anything in your instructions about running the "" file in your http sub-directory.
I think it's necessary to run the file to create an index.html file for the browser to find? For Windows you told me by email to execute it in a command line shell.

I did get it working on Win 10 after blindly installing loads of Bash & Git stuff that I didn't understand and was probably unnecessary, and then I deleted it all. So, I can't get the .sh file to to run any more. In any case I think it is just a simple Bash based Linux script to create an index.html?

So, to save angst amongst other non-Linux users, could you add some instructions, or maybe it would be easier to make a .bat script for Windows users to just double click on?
I'm right out of my depth here and probably talking twaddle, but it would be useful if there is an easier way to do this, if it's a necessary step.

Premium Member
280 Posts
Discussion Starter · #19 ·
The standard index.html-file that is loded by the the browser client is provided by the WeMos.
The content of the index.html-file is stored in the webpage.h-file and contained in the string index_html[]

The index.html-file is thus programmed into the WeMos as a string variable together with the rest of the program. No need to take any additional actions.

If you like to change the index.html-file in any way (or the javascript) you can do that.
Then you need to go into the http-directory and do the changes in index_base.html and/or main_base.js.
When the changes are done, you need to execute the script,
The script will output a complete index.html-file that you can test by pointing your local browser to it.
It will also re-generate the webpage.h-file so that the next time you flash your WeMos, the new index.html-file will be flashed onto the WeMos.

The is a bash-file that is dependent on awk, tr and cat. Linux distributions and macOS already have them installed.

I hope this clarify your thoughts.

1 - 20 of 553 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.