Following a presentation I made on the September 2023 NRail.org ZoomTRAK meeting, I’ve written up a pair of new pages for this blog about my example design of an Arduino-based train speedometer, which is designed to measure and display the scale speed of a passing model train, with configurable scale (1:87, 1:160, …) and measured units (km/hr, mph, …). The pages can be found at these links.
Have had this project on my radar for over a year now. Finally with your December 2024 I managed to compile the code. But when executed it seems to halt at “DISP OK”. Pins, 2,3,4,5,8,9,10 hook up diagram would be helpful. Thanks for sharing.
LikeLiked by 1 person
Cool, you’re the first person in the 9 years since I started this blog to actually comment on one of my posts!
I will get the info you want back to you, hopefully today while we here in the Richmond VA area deal with a days-long-so-far boil-water alert AND a big honking snow storm supposed to move in this evening. Right when our RANTRAK club has our monthly meeting tomorrow AND need to load up the NTRAK layout into a trailer for the Greenberg train show here next weekend.
For now, I don’t know why the code would stop at the DISP OK point. Will dig into that first.
TWR
LikeLike
Thanks for your quick reply. I’m having difficulty replying due to sign in to world press. I am using the same boards you listed. Will reply in depth later.
LikeLike
My apologies. I misstated “DISP ERR”. Actually it is “SPD ERR” which the code calls for. Again I apologize.
LikeLike
You didn’t really misstate, you mentioned DISP OK, not DISP ERR. SPD ERR would follow that, and that’s where I was looking.
LikeLike
Just got through reloading a new copy of your program and have experienced the same result. I then tried changing “Trace 0 to Trace 1” In Sensor.cpp the program compiles and when executed the code halts at “spd err”. I then tried changing “Trace 0 to Trace 1” in Speedometer.cpp and got a compiling error “Streaming.h” no such file or directory. I tried the above because I wasn’t getting any output in the serial monitor.
LikeLike
My mistake, I use the Streaming library out of habit. Do a fresh pull of the TrainSpeedometer repo on GitHub, I’ve changed a few codes so that by default the old-style Serial.print/println functions are used for trace outputs. Probably easier for you than getting the Streaming library from the arduino.cc website.
Well. it used to be on Arduino’s site. Now you would install the Streaming library from here: https://github.com/janelia-arduino/Streaming
LikeLike
Have downloaded and installed streaming library already.
LikeLike
First thing you can try:
In Sensor.cpp, change line 3 to say #define TRACE 1, then rebuild and run the sketch. Odds are an error is occurring when the code is trying to init the pair of sensors. Meanwhile the hardware that appears in the YouTubes is still assembled in a box behind me, so I’ll use that and my code to whip up a diagram of how it all is connected.
LikeLike
Tried and makes no difference
LikeLike
It didn’t give you more debugging output? I’ll look at it again Monday.
LikeLike
Also change TRACE to 1 in Speedometer.h, that will turn on more diagnostic messages.
LikeLike
I installed the Streaming library and got “meter.begin() failed”. I’m going to reinstall the “ST_VL6180X.h” library.
LikeLike
Oh, you got Streaming installed. Good deal.
LikeLike
If you set TRACE to 1 in Sensor.cpp, you should have gotten another message before the “meter.begin() failed”.
LikeLike
When Sensor.cpp to Trace 1 and Speedometer.h to Trace 1. I only get the one line meter.begin() failed.
LikeLike
By the way… which Arduino-type board are you setting this up with? If you’re using the SparkFun QWIIC Shield like I did, I’ve discovered in the last 48 hours that it isn’t supported properly by all newer CPU boards. It was apparently designed only with the original Arduino UNO in mind. I have a few Adafruit boards which are driving the I2C on pins other than what the QWIIC Shield expects.
But the fact the display responded properly implies that’s probably not the root problem.
LikeLike
The display initiates fine. I’m not able to run the code at this time due to being away from my home at this time.
LikeLike
Okay, I have two Adafruit VL6180X sensors, both connected to QWIIC Shield. Each sensor also has additional pin marked GPIO and XSHUT. Call sensors SensorA and SensorB. These are the connections to the Arduino’s pins 2-5:
Pins 8-10 are used to select runtime options. All are in INPUT_PULLUP mode, so leave them floating or ground them as follows:
Notes:
Give me a few minutes and I’ll post a picture of the sensor board.
LikeLike
I have pins 2, 3, 4, and 5 connected as indicated. I have left 8, 9, & 10 open.
LikeLike
That should work. So you’ll get the “near track” distance, metric display, and 1:150 scaling of speed. You can always edit your copy of the code to change the defaults, esp. the distance from your sensors to the track being monitored.
LikeLike
LikeLike
Do you need to see how my display is set up? Or have you rolled your own?
LikeLike
On the sensor boards, the XSHUT pins are used to disable each sensor long enough for the I2C address of the other to be reprogrammed, so that when enabled they have distinct addresses. These are outputs from the Arduino.
The GPIO pins are used as input interrupts from each sensor to the Arduino, so that an interrupt handler can read the detected range from a sensor when conversion is complete.
LikeLike
Sensor board is mounted on 3D-printed supports.
LikeLike
By the way, about the VL6180X sensor…
Adafrut claims on https://learn.adafruit.com/adafruit-vl6180x-time-of-flight-micro-lidar-distance-sensor-breakout/pinouts that
Not true. My speedometer code relies on being able to do exactly that: set each sensor to its own new address. The procedure is described in an application note from ST, the sensor chip maker. It’s application note AN4478, downloadable from page https://www.st.com/en/imaging-and-photonics-solutions/vl6180x.html#.
You can see where that’s done in my code in Sensor.cpp, line 38. I used driver code that came from ST.
LikeLike
It’s possible that ST has updated their driver code which breaks my code in some subtle way, such as during the startup procedure. I will check that Monday.
LikeLike
ST driver code for the VL6180X hasn’t been revised on their GitHub since four years ago, so I’d say that’s not the issue.
LikeLike
We probably need to come up with a test sketch to verify your hardware and wiring can access a single VL6180X properly, with the other sensor temporarily disconnected.
LikeLike
Have been checking various items and have tested a few. Sensor and addresses are as should be.
In Sensor.cpp lines 35 & 36 mentions a virtual destructor to make sure to delete the object
LikeLike
I tried a different board and had the same outcome. When I reverse the interrupt and enable pins I get the halt at “DISP OK”. When hooked correctly the “SPD ERR” is displayed. Tried the adafruit triple example modified for only two sensors a got readings from both. Did not block both sensors simultaneously but will try that later. Not sure if readings were correct.
LikeLike
You were correct, code errors in repo slipped past me, found them two days ago. Fixed, tested, and have updated repo on GitHub. Give it another try.
LikeLike
D
LikeLike
Are you sure you’ve pulled the most recent version of the TrainSpeedometer repository? In the entire repo, the word ‘virtual’ only appears once, in Speedometer.h line 50, and the destructor symbol ‘~’ appears in none of the .ino, .cpp, or .h files.
LikeLike
My error, only two days ago discovered API errors in Sensor and Speedometer classes, got the same SPD ERR result. That’s been fixed and the repo has been updated. Try again.
Don’t know how this slipped past me for so long, but I only the other day tried running the code since months ago.
LikeLike
Downloaded and tested near track only. Tested metric and imperial Japanese and US. It reported speeds 15 out 15 trys. My layout of device mimics yours closely will provide a picture when completed. I wish to thank you wholeheartedly for this project. Jim.
LikeLike
o/\o
(high five)
LikeLike
After some digging and a couple of doses of headache meds, I’ve found a way that may allow me to reconfigure the hardware to remove the need for the four additional GPIO pins on the Arduino board. It will require the addition of an Adafruit LTC4316 I2C Address Translator – Stemma QT / Qwiic (https://www.adafruit.com/product/5914) in addition to the two VL6180X sensors. The three parts would be daisy-chained from the Arduino as sensor-translator-sensor, so only one Qwiic port will be needed. Looks it might also work with the way-more-compact Adafruit_VL6180X library rather than the STMduino (sp?) library I was using.
Now I just need to finish making v2.0 of my sketch to verify I can get the performance I had before. Will keep you updated on this. If it works, I’ll update my blog pages as well.
🙂
LikeLike