YusofBandar/pi_scalextric

Controlling a pi_scalextric via a single page web application. A whole load of mqtt, python and node-red

★ 0Forks 0GitHub ↗Compare

README

pi_scalextric

Have a look at the schematic.

This is the parent project to the following components:

  • pi_scalextric_mqtt contains mqtt broker setup, python scripts and configuration files
  • pi_scalextric_spwa contains a simple single page web app to control scalextrix cars via mqtt

TL;DR – You can skip most of this article if you do the following:

  1. Clone pi_scalextric_mqtt onto Raspberry Pi

  2. Edit the config.json, resources.json and sensors.json files with appropriate details

  3. Run node-red-start and copy the mqtt_flow.json flow

  4. Change global context: configPath to the absolute path to the config.json file

  5. Setup new Mqtt connections for each Mqtt module and deploy

  6. Run python qrCodeGen.py [PATH_TO_CONFIG_FILE] [HOST_OF_SPWA]

  7. Generated Qr code can be scanned to direct users to SPWA

How To

Here's how I'm setting up the system:

Please note: to run an MQTT server on Heroku will require a credit card, even if on a free tier.

The best, safest, way to do this, is to obtain a top-up credit-card, such as one from Pockit (Other Top-up cards are available). It will ensure that if something goes wrong, and a charge to the card is attempted, there are no funds available, and you won't fall into debt without being aware!

  1. Web: Create a project alias on a GMail account

  2. Web: Create a Heroku account, using the project alias

  3. Web: Create an app in the Heroku account

  4. Web: Add the CloudMQTT element to the app in the Heroku account (you'll need to provide a credit card for this)

  5. Web: Find the connection details in the app's Config Vars

  6. Dev Machine: Use an MQTT debug client to check all is OK

  7. Download fresh Raspbian.

  8. Pi: Install onto SD Card.

  9. Boot Pi from SD Card, into Desktop

  10. Pi: Update Raspbian

  11. Pi: Update Node-RED

    1. see Node-RED update for Raspberry Pi
    2. start the Node-RED server, as instructed
  12. Pi: Install a git gui if you really can't be bothered with command line

  13. Pi: Clone the pi_scalextric_node_red project

  14. Pi: Clone the pi_scalextric_mqtt project

  15. Pi: Alter the config file:

    • located at path: <pi_scalextric_mqtt>/mqtt/src/config.json
      • set the values for the broker as those you have in your MQTT broker account 'details'.
      • set the values for the paths:
        • resources: <pi_scalextric_mqtt>/mqtt/src/pythonScripts/specialWeaponScripts
        • throttle: <pi_scalextric_mqtt>/mqtt/src/pythonScripts/throttleScripts/channel_throttle.py
        • sensors: <pi_scalextric_mqtt>/mqtt/src/pythonScripts/sensorScripts/sensors.py
  16. Pi: Node-RED: import the project:

    • Edit <pi_scalextric_node_red>/node_red_flow.txt. Select all,copy to clipboard.
    • Install missing node types, using the 'Manage Palette' menu.
      • (Note: If this doesn't exist, you don't have npm running)
      • install node-red-contrib-mqtt-dynamictopic: NOTE really important not to confuse this with node-red-contrib-mqtt-dynamic
      • install node-red-contrib-grovepi
  17. Pi: Node-RED: change parameters

    • Mqtt Subscribe: Set Global Context: configPath
      • set value to the path: <pi_scalextric_mqtt>/mqtt/src/config.json
    • Mqtt Subscribe: Set sensor definition path
      • Set value on the Sensors File node: <pi_scalextric_mqtt>/mqtt/src/sensors.json
  18. Pi:Node-RED: set the mqtt connection parameters

    • select any one of the Nodes of type: mqtt-dynamic
    • in the sidebar click on the gear icon to bring up the configuration
    • the configuration sets the values for all nodes of this type.
    • set the MQTT connection info to the same as that entered for the config.json
  19. Pi: Python: Install packages for mqtt - python checks the sensor values and sends to MQTT.

    • pip install paho-mqtt

Useful refs:

Raspbian Download Page

MQTT.fx

GitCola

pi pinout

LED

resistor lookup

TIP3055 (NPN)

back emf supression


This is the work of Yusof Bandar for DigitalLabs@MMU.

Contributors

YusofBandarcoopsatwork

Issues