Create a streetcar with Lego Mindstorms components and a Raspberry Pi

Node-RED Setup

Node-RED has been preinstalled on Raspbian Jesse since the November 2015 version. The base Node-RED installation includes support for the Rasp Pi GPIO, but many other useful libraries can also be installed [4]. To check that Node-RED is installed and working, go to a terminal window and enter:

node-red-start &

If you are able to run Node-RED, the next step is to install the Pimoroni Explorer HAT Pro node and a web dashboard node. Depending on your installation, you might need to load the Node Package Manager npm first:

sudo apt-get update
sudo apt-get install npm
\curl -sS get.pimoroni.com/explorerhat | bash
cd ~/.node-red
npm install node-red-contrib-explorerhat
npm install node-red-dashboard

After you install these library nodes, you will need to restart your Rasp Pi. Once Node-RED restarts, you use a web browser to build applications. If you are working directly on your Rasp Pi, enter 127.0.0.1:1880 in the URL address bar of your browser.

Node-RED Control

To make a web-based manual control program, drag three button nodes from the left node panel onto the center panel and wire them to an Explorer HAT output node (Figure 5).

Figure 5: Node-RED Web dashboard logic.

Double-click on a button node to open the edit window, which lets you configure the dashboard, labels, and button actions. To control the first Explorer HAT motor, enter the topic motor.one. The payload is between -100 and 100, which corresponds to full reverse and full forward, with 0 being stopped.

After you have finished configuring Node-RED, click the Deploy button at the top right in your browser window. Deploying will run your program and enable the web dashboards. To access the web dashboards enter: http://<your-ip-address>:1880/ui (Figure 6). If you are unsure of your IP address, go to a terminal window and enter ifconfig (deprecated) or ip addr.

Figure 6: Streetcar manual control.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content