Jump to content


Photo

Simple wifi laptimer for Scalextric SSD


  • Please log in to reply
517 replies to this topic

#1 niclasf

niclasf

    Racer Dude

  • PLUS+
  • 248 posts

Posted 21 January 2017 - 11:14 PM

ó 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

Controls
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/Pictures
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.


#2 Drifter2

Drifter2

    Top Tuner

  • Members
  • PipPipPipPipPipPip
  • 442 posts

Posted 22 January 2017 - 10:40 PM

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.

#3 niclasf

niclasf

    Racer Dude

  • PLUS+
  • 248 posts

Posted 22 January 2017 - 11:07 PM

--- Restored from google search ---

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

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 smile.gif

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. thumbsup.gif

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 thumbsup.gif


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.

#4 niclasf

niclasf

    Racer Dude

  • PLUS+
  • 248 posts

Posted 22 January 2017 - 11:19 PM

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, gen_compact_index_file.sh
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,

CODE
function startRace() {
           :
    var snd1 = new Audio('<mp3 or wav file>');  /* Point to a mp3 or wav file */
           :
    snd1.play();    /* 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.

/Niclas
foogadgets

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 smile.gif 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.
  • Lone Racer likes this

#5 niclasf

niclasf

    Racer Dude

  • PLUS+
  • 248 posts

Posted 22 January 2017 - 11:26 PM

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.



#6 niclasf

niclasf

    Racer Dude

  • PLUS+
  • 248 posts

Posted 22 January 2017 - 11:32 PM

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?


#7 niclasf

niclasf

    Racer Dude

  • PLUS+
  • 248 posts

Posted 22 January 2017 - 11:38 PM

The old thread can be accessed through google search cache,

Page 1
Page 2
Page 3



#8 chris99

chris99

  • PLUS+
  • 2,569 posts

Posted 23 January 2017 - 07:35 AM

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).

Cheers, Chris

Scalextric APB C7042 Tower - Menu map - Lexicon


#9 DaveLat

DaveLat

    Team Owner

  • PLUS+
  • 1,095 posts

Posted 23 January 2017 - 11:40 AM

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

thanks,

Dave

Attached Files



#10 chris99

chris99

  • PLUS+
  • 2,569 posts

Posted 23 January 2017 - 12:05 PM

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.

Cheers, Chris

Scalextric APB C7042 Tower - Menu map - Lexicon


#11 DaveLat

DaveLat

    Team Owner

  • PLUS+
  • 1,095 posts

Posted 23 January 2017 - 12:09 PM

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%)
.....................................(58%)
......................................(87%)
.......................................(100%)

just off to work so ill try again later


#12 CMOTD

CMOTD

    Brian Rogers

  • Admin
  • 2,419 posts

Posted 23 January 2017 - 12:23 PM

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.

#13 niclasf

niclasf

    Racer Dude

  • PLUS+
  • 248 posts

Posted 23 January 2017 - 12:24 PM

Look like all is good. You should have a running web server now.

/Niclas


#14 DaveLat

DaveLat

    Team Owner

  • PLUS+
  • 1,095 posts

Posted 23 January 2017 - 12:29 PM

I thought it renewed automatically

Ok sorted the subscription issue out.
here is the screenshot

Attached Files



#15 chris99

chris99

  • PLUS+
  • 2,569 posts

Posted 23 January 2017 - 12:32 PM

I think it's just counting to 100% as it progresses the compiling and upload. It says "Done uploading" so I guess that's good.

Try connecting your browser when you get a chance.

Cheers, Chris

Scalextric APB C7042 Tower - Menu map - Lexicon





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users