Slot Car Speed Display

83 views
Skip to first unread message

rlno...@gmail.com

unread,
Feb 22, 2018, 2:28:54 PM2/22/18
to Node-RED
I'm trying to build a flow that will display the speed of a slot car on a track. IR sensors on RPi inputs would be used to start and stop the timer as the car passes through.
I got a basic flow started using the Inject node and a timestamp but that uses a click on the screen instead of a gpio input. So there must be another way other than using a timestamp?
The desired output would be in miles per hour but the speed would not need to be very precise.

Zenofmud

unread,
Feb 22, 2018, 4:21:05 PM2/22/18
to node...@googlegroups.com
Why not have the gpio nodes each feed a change node that sets up for a join. The join feeds a function which does the math - distance / (stop-start) to give you your value. here is an example

[{"id":"66551b75.8c9e2c","type":"debug","z":"d6840804.ac19a8","name":"","active":true,"console":"false","complete":"true","x":675,"y":222,"wires":[]},{"id":"e6116318.50c0b8","type":"inject","z":"d6840804.ac19a8","name":"","topic":"","payload":"start","payloadType":"str","repeat":"","crontab":"","once":false,"x":105,"y":97,"wires":[["cb6d762a.e13508"]]},{"id":"74baeca9.d741bc","type":"join","z":"d6840804.ac19a8","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","x":441,"y":138,"wires":[["9e087c9e.e91848"]]},{"id":"3c2caeb6.78aaf2","type":"inject","z":"d6840804.ac19a8","name":"","topic":"","payload":"stop","payloadType":"str","repeat":"","crontab":"","once":false,"x":119,"y":172,"wires":[["4d8ff2a9.3a2f2c"]]},{"id":"cb6d762a.e13508","type":"change","z":"d6840804.ac19a8","name":"Start","rules":[{"t":"set","p":"parts.id","pt":"msg","to":"timer","tot":"str"},{"t":"set","p":"parts.index","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"parts.count","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":283,"y":99,"wires":[["74baeca9.d741bc"]]},{"id":"4d8ff2a9.3a2f2c","type":"change","z":"d6840804.ac19a8","name":"Stop","rules":[{"t":"set","p":"parts.id","pt":"msg","to":"timer","tot":"str"},{"t":"set","p":"parts.index","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"parts.count","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":285,"y":169,"wires":[["74baeca9.d741bc"]]},{"id":"9e087c9e.e91848","type":"function","z":"d6840804.ac19a8","name":"","func":"var start = msg.payload[0];  // time at start\nvar stop  = msg.payload[1];  // time at end\nvar distance = 10; // distance in feet\nvar elapsed_time = (stop - start) / 1000; //convert to seconds\nvar speed = distance / elapsed_time; // speed ft/sec \nmsg.payload = 'the speed is ' + speed + ' ft/sec';\nreturn msg;","outputs":1,"noerr":0,"x":607,"y":141,"wires":[["66551b75.8c9e2c"]]}]


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/6de6b1cc-59aa-4f02-bbee-22c50e9d6742%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Simon Walters

unread,
Feb 22, 2018, 4:27:48 PM2/22/18
to Node-RED
You can just add a timestamp to a GPIO event with a change node

[{"id":"3c56ee42.bfa332","type":"rpi-gpio in","z":"7698c679.9464c8","name":"","pin":"7","intype":"up","debounce":"25","read":false,"x":210,"y":1320,"wires":[["f036db48.4fbb98"]]},{"id":"f036db48.4fbb98","type":"change","z":"7698c679.9464c8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":1320,"wires":[["b054b4b0.7da138"]]},{"id":"b054b4b0.7da138","type":"debug","z":"7698c679.9464c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":1320,"wires":[]}]

Simon

Dave C-J

unread,
Feb 22, 2018, 4:40:17 PM2/22/18
to node...@googlegroups.com
You may be ok - but when it comes to timing things like this you may want to consider external hardware instead - such as arduino or esp8266. While they run code - it is not a full blown stack with all it's overheads that the Pi does -  most notably in the node.js situation being the garbage collection it does, and maybe other operating system overheads that may distort any timing. which when converted to speed may give wildly inaccurate results...  By running dedicated hardware without these overheads you would get more consistent results.

Of course for a proof of concept it may not matter - just a heads up.

Zenofmud

unread,
Feb 22, 2018, 9:12:57 PM2/22/18
to 'Simon Walters' via Node-RED
And to add what Dave says, you could have the arduino send a MQTT message to NR and do the calculations and display there...or just use the arduino to take the measurements and calculate the result and use an OLE to display it. All sorts of options :>)

On Feb 22, 2018, at 4:40 PM, Dave C-J <dce...@gmail.com> wrote:

You may be ok - but when it comes to timing things like this you may want to consider external hardware instead - such as arduino or esp8266. While they run code - it is not a full blown stack with all it's overheads that the Pi does -  most notably in the node.js situation being the garbage collection it does, and maybe other operating system overheads that may distort any timing. which when converted to speed may give wildly inaccurate results...  By running dedicated hardware without these overheads you would get more consistent results.

Of course for a proof of concept it may not matter - just a heads up.


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

rlno...@gmail.com

unread,
Feb 23, 2018, 1:38:01 PM2/23/18
to Node-RED
Paul, your flow is working fine for my application, thank you.
The display on next on my list. At first I thought to just display the Dashboard on a monitor connected to the RPi maybe using a projector. However adding more and more equipment is something I want to avoid.
I need something visible from about 20-30 feet so I thought about a large LED display. Probably not the cheapest solution.
What options are there to convert the payload data to a display?

Zenofmud

unread,
Feb 23, 2018, 5:14:45 PM2/23/18
to node...@googlegroups.com
You could use the ui to display it then send the output of the computer to a projector

Paul

rlno...@gmail.com

unread,
Feb 24, 2018, 2:54:06 PM2/24/18
to Node-RED
A projector with hdmi input would be nice.
But if I wanted to send the speed payload to a multi-digit seven segment display, would the Serial node be the way to send the payload out of the RPi serial port?

Dave C-J

unread,
Feb 24, 2018, 3:36:57 PM2/24/18
to node...@googlegroups.com
Depends on the display.  
--
Sent from phone.

rlno...@gmail.com

unread,
Mar 7, 2018, 5:22:39 PM3/7/18
to Node-RED
This display driver should drive my display https://www.sparkfun.com/products/13279
But after hours of searching this forum and google, I can't find any examples of NR driving a 7 seven segment display.

Simon Walters

unread,
Mar 7, 2018, 5:40:45 PM3/7/18
to Node-RED
I think you'd have to work the logic out from reading Sparkfun's Ardunio code and then re-writing it

It seems to just need 3 pins being switched high/low in particular sequences

I've ordered the chip its uses to have a play with one and see what can be done

Zenofmud

unread,
Mar 7, 2018, 5:44:17 PM3/7/18
to node...@googlegroups.com
Just to make the project bigger, you might want to attach the display to an arduino and have it run as an MQTT client which will display the numbers, then have NodeRed publish the value to display via MQTT. 

You should be able to find a tutorial on using an arduino to display the numbers.


Paul

rlno...@gmail.com

unread,
Mar 7, 2018, 9:04:49 PM3/7/18
to Node-RED
I was hoping to keep the parts count down and just use the RPi to drive the display instead of adding an arduino.
But when I couldn't find any tutorials or even mention of RPi using NR to drive a pair of 7 segments, I started to wonder if there was a technical reason why it couldn't be done?

rlno...@gmail.com

unread,
Mar 7, 2018, 9:06:52 PM3/7/18
to Node-RED
Simon, let me know what you figure out. I'm not very good from the engineering side to get things to work. I rely on the experts here to guide me in the right direction then follow their suggestions.
Reply all
Reply to author
Forward
0 new messages