optoblog

How to Build a Raspberry Pi with Node-RED and Industrial GPIO

发表 Benson Hougland2016年12月14日下午3:39:17

更新:此帖子已更新,以反映最新的Raspbian Jessie Lite图像(不再包括Node-red或node.js)的变化,并使用新的数字I/O用于Raspberry Pi入门套件for I/O hardware (new code, photos, and video).

覆盆子皮®毫无疑问,仅需35美元,这是一台功能强大的计算机。确实就是这样:a computer。That means the Pi is capable of many tasks and perfect for many automation applications.

Couple the Pi to industrial, solid-state digital inputs and outputs,您也可以为商业和工业应用构建引人注目且具有成本效益的解决方案。

快速构建软件应用程序的最简单,最有趣的方法之一就是节点红色,由IBM新兴技术设计的免费,开源软件工具,用于以新颖有趣的方式将硬件设备,API和在线服务接线。

但是,Node-red仅包含在完整的Pixel GUI版本中Raspbian Jessie操作系统,可从raspberrypi.org获得。他们的最新2017-07-05-raspbian-jessie-lite.img建立无头操作(无需监视器,键盘或鼠标)不再与Node-red或所需的软件工具Node.js和NPM捆绑在一起。

这purpose of this post is to guide you through creating a headless Raspberry Pi computer with the latest versions of Node-RED, node.js, and npm, building a Node-RED application, and controlling and sensing GPIO connected to industrial digital I/O, quickly and simply. (For a sneak peek at the result of this build, see the video near the end of this post.)

digital_io_for_rpi_starter_kit-benson.jpg

图片:新的Opto 22数字I/O用于Raspberry Pi启动器套件带Raspberry Pi 3计算机


这篇文章提供了以下分步说明:

  • 用Raspbian Jessie Lite构建和配置MicroSD启动图像
  • 安装Node-red,node.js和npm
  • 配置Node-red以在启动时间启动
  • 安装各种节点红色节点,包括我们的snap pac节点红节点(可选)
  • 通过GPIO节点导入传感和控制数字I/O的节点红色流

这是您将要采取的步骤的图表:

pioverview.jpg

您需要什么:

  • 覆盆子pi-我正在使用覆盆子pi 3
  • MicroSD卡(至少8 GB)和计算机的读取器
  • 电源

Optional items used in this post (needed to see the result of a Node-RED flow with GPIO nodes):

获取用于Raspberry Pi入门套件的数字I/O

现在,我不是Raspberry Pi或Linux命令行的专家。您也不需要。我认为,如果您谨慎地按顺序遵循这些步骤,您会发现以下说明非常容易。

完成后,您将拥有一个完整,功能强大且令人兴奋的计算平台,以构建梦想的自动化应用程序。

步骤1:构建和配置Raspbian microSD启动设备

Download Raspbian Jessie Lite image for无头操作(无需监视,键盘或鼠标):
https://downloads.raspberrypi.org/raspbian_lite_latest

将文件解压缩到您的 /下载文件夹中。

从终端窗口中的OS X说明:

diskutil列表
  • 从结果确定microSD磁盘名称(例如,对于磁盘4):

diskutil unmount disk4s1
CD下载/

  • Choose one (1st for Jessie; 2nd for Jessie Lite):
sudo dd bs = 1m if = 2017-07-07-05-raspbian-jessie.img of =/dev/rdisk4
sudo dd bs = 1m if = 2017-07-07-05-raspbian-jessie-lite.img =/dev/rdisk4

Instructions for Windows:

  1. 下载Win32磁盘成像器:https://sourceforge.net/projects/win32diskimager/
  2. 安装并启动Win32磁盘成像器。
  3. 从您的下载文件夹中选择图像文件,然后为您的SD卡选择驱动器字母。
  4. 单击写。

更新:raspberrypi.org的最新raspbian jessie映像(2017-07-05-raspbian-jessie-lite.img)不再允许默认情况下使用SSH连接。您必须在卡的根部放置一个没有命名“ SSH”的文件。为此,只需在没有内容的桌面上创建一个新的文本文档,然后重命名文件以删除扩展名。将此文件复制到您的microSD卡中/BOOT/目录。现在,您可以如下一步所示。

步骤2:登录并配置无头PI

Jessie Lite下的无头操作的命令提示方法(笔记:this step could be problematic if more than one Raspberry Pi3/Raspbian Jessie in its default configuration exists on your network or if your DNS cache isn't flushed. If your connection is refused, see update in previous step.)

  1. MAC/Linux:Attempt SSH session from your terminal application::

ssh pi@raspberrypi

  • 视窗:您将需要免费的Putty Terminal应用程序下载。(您可以从中下载http://www.putty.org/。)安装后,输入Raspberrypiin the Host Name (or IP address) field. Make sure the port number is 22 and SSH option is selected, then click Open.
连接后,登录:

pi@raspberrypi’s password:raspberry

or for Windows:登录为:PI
然后,pi@raspberrypi的密码:raspberry

  1. sudo raspi-config在命令提示符
  2. 选择选项1-更改用户密码(例如,Opto22
  3. 选择选项2-Change Hostname (example:RPI-G4PB8H-BENSON
  4. 选择选项4-本地化选项(加利福尼亚州的用户示例):
    1. Locales:EN_US.UTF-8 UTF-8
    2. 时区:我们,太平洋
    3. 改变Wi-Fi国家:我们(按“ u”接近)
  5. 选择选项7-Advanced Options; select option A1 - Expand Filesystem
  6. 选择and then select是的when prompted for reboot.
  7. 使用新的主机名登录(示例:SSHpi@rpi-g4pb8h-benson)。
  8. 输入您的新密码。

步骤3:安装node.js,npm和node-red

sudo su-
curl -sl https://deb.nodesource.com/setup_6.x |sudo bash-
apt -get安装nodejs -y
节点-v(返回v6.11.0或更高)
NPM -V(returns 3.10.10 or higher)
NPM缓存清洁
npm install -g --unsafe-perm node-red
出口
节点红色

At this point, confirm Node-RED is running by navigating with your browser to your Pi and port 1880:

http:// [主机名]:1880(例子:http:// rpi-g4ph8h-benson:1880

步骤4:构建您的第一个节点红色应用程序

笔记:This step and the next exercise are important for two reasons: (1) They confirm everything is installed properly; and (2) They create the appropriate folders for the remaining steps.

  1. 单击并将注入节点拖到调色板。
  2. 将调试节点拖到调色板上。
  3. 将两个节点连接在一起。
  4. 单击Node-Red的右上角部署。
  5. Click the Debug tab beneath the Deploy button.
  6. Finally, click the tab emerging from the left of the Inject node. You should see the current time (in Epoch time) in the debug pane.

返回您的终端会话,并发出以下命令:

ctrl-c(关闭节点红)
sudo关闭-P现在

该最终命令立即使用PowerOff参数关闭您的PI,完成磁盘写入,并要求您删除并重新安装电源以再次启动。这是一项安全措施,以确保您到目前为止将所有工作保存到microSD卡上。Always wait for the green LED on the Pi to go out completely before removing power.

笔记:我强烈建议您始终使用shutdowncommand to preserve your Pi file system if you intend to power down the system. If you'd rather just reboot the Pi, use:

sudo关闭-r现在

步骤5:安装SNAP PAC节点红节点(可选)

这SNAP PAC Node-RED nodes offer a simple method for querying and controlling a SNAP PAC I/O System. You can use a SNAP PAC I/O system to gather and control analog, serial, and other digital I/O modules not covered by any G4 and SNAP digital I/O connected to the GPIO of the Pi.

注意:如果您已与上述说明分别在现有的PI上安装了Node-red,请确保首先安装了Node.js版本4.4.4或更高版本。这是使用Opto 22的Snap PAC节点红色节点的最低支持版本。您可以通过以下命令确定节点的版本:节点-v

PWD(应导致 /home /pi)
CD .NODE-RED
NPM安装节点红色contrib-pac

Step 6: Set up Node-RED to start up at boot

节点红建议方法是iNSTALL NODE-RED服务:

  • sudo su-
  • WGET https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/master/resources/nodered.service-o/lib/systemd/systemd/systemd/nodesten.service.service.service.service.service.service
  • wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start -O /usr/bin/node-red-start
  • WGET https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/master/resources/node-red-stop-o/ osr/usr/ usr/bin/node-node-red-stop
  • chmod +x/usr/bin/node-red-st*
  • systemctl daemon-reload
  • systemctl enable nodered.service
  • 关闭-r现在

When the Pi reboots, Node-RED should be running. Access the Node-RED environment from your web browser here:

http:// [主机名]:1880(F或示例,http://rpi-g4pb8h-benson:1880)

从命令行安装新节点时,使用节点red service命令启动/stop node-red:

  • 节点red-stop
  • node-red start

Step 7: Import a GPIO-based Node-RED flow to test I/O

最后一步涉及导入我创建的节点红色流以测试GPIO节点和机架上相应的I/O模块。(t他的测试流将在有或没有机架和I/O模块的情况下使用。

为您的PI供电,然后登录节点红色。然后,我们将导入此流程:

node-red-flow.gif

要导入此流量,请转到您的节点红色应用程序(http:// [主机名]:1880),单击右上角的汉堡图标,选择“导入”,然后选择“剪贴板”,然后选择新的流按钮。接下来,将此代码复制并粘贴到结果窗口中:

[{"id":"d95eb067.d4687","type":"inject","z":"aa9ee7c0.e8cd88",
“名称”:“打开输出”,“主题”:“ 0”,“有效载荷”:“”,
“ payloadType”:“ num”,“重复”:“”,“ crontab”:“”,“一次”:false,false,
“ X”:300,“ Y”:180,“ Wires”:[[878648AC.FC2948“]]]},{“ ID”:“ 878648AC.FC2948”,“类型
“ Z”:“ AA9EE7C0.E8CD88”,
“名称”:“位置3”,“ PIN”:“ 35”,“ SET”:“”,“ G4ODC5数字输出
"level":"0","out":"out","x":660,"y":220,"wires":[]},{"id":"7d18b79f.0fa588","type":"inject","z":"aa9ee7c0.e8cd88",
“名称”:“关闭输出”,“主题”:“”,“有效载荷”:“ 1”,
“ payloadType”:“ num”,“重复”:“”,“ crontab”:“”,“一次”:false,false,
“ X”:300,“ Y”:260,“ Wires”:[[878648AC.FC2948“]]]},{“ ID”:“ 82511EEF.33CBB”,“ type”:“ rpi-gpio in”,“,”,“”,“”,“Z“:” AA9EE7C0.E8CD88,
“名称”:“位置0”,“ pin”:“ 40”,“ intype”:“ tri”,“ g4idc5ma模块”,
“ debounce”:“ 25”,“读”:false,“ x”:330,“ y”:400,“ wires”:[[6f379125.5007d',“ 878648AC.FC2948”]},},{“:” 6F379125.5007D“,”类型“:” debug“,” z“:” aa9ee7c0.e8cd88“,”,
“名称”:“ G4IDC5MA的状态”,“ Active”:true,“ console”:“ false”,
"complete":"payload","x":620,"y":400,"wires":[]},{"id":"2e694694.1487aa","type":"comment","z":"aa9ee7c0.e8cd88","name":"Make sure G4ODC5MA is in Auto mode","info":"",
“ X”:652.5,“ Y”:146,“ Wires”:[]}]

Finally, click Import. Now, position the nodes on the canvas where you like, and you're done. Click the Deploy button to deploy this flow to your Pi.

现在,您可以单击名为“打开输出”的注入按钮的左侧,您应该在名为“ G4ODC5数字输出”的节点下看到“位置3”更改为“ 0”。单击名为“关闭输出”的注入按钮,该值将更改为一个。

如果此结果似乎倒转给您,那是因为Opto 22固态I/O模块为负逻辑:编写0以打开;写一个1以关闭。

为了在现场动作中看到这一点,我使用了新的Raspberry Pi Starter套件的数字I/O(以99美元的价格提供有限的时间)。我放置了自己的覆盆子PI3(I purchased mine at Amazon.com)on the assembled Starter Kit atop theOpto-P1-40p载体板并将其附加到G4PB8Hmounting rack. Then, I inserted each of the 4 modules in the orientation shown in the above photo, and below in the video. That puts my DC input module (G4IDC5MA)in position 0 on the rack, and the DC output module (G4ODC5)位置3。

获取用于Raspberry Pi入门套件的数字I/O

我将系统连接到以太网网络,并使用我的PI电源(Wall Wart)将其供电。

请注意,该测试流将在没有机架和I/O模块的情况下工作。您只是将无法看到LED积极地表明一切正常。在我用手机拍摄的简短视频中,您可以看到当我翻转输入的开关时机架上发生了什么,以及生成的输出模块启动:

如果您有入门套件,并遵循上面的所有说明,则可以从软件(Node-red)打开和关闭G4ODC5。只需单击标有打开输出并关闭输出的节点左侧的注入按钮,如下所示:

node-red-flow.gif

全做完了!

恭喜!您刚刚构建了一台具有节点红色的完整,最新的Raspberry Pi计算机,并能够使用PI的GPIO引脚与现实世界中的电气负载进行交互。

让我知道您的安装是如何在下面的评论部分进行的。我也很想听听任何提示,评论,建议或投诉!

Thank you for reading. -Benson


BONUS: Other nodes you may find useful

这re are hundreds of Node-RED nodes available from npm andflow.nodered.org。这里有一些我发现对各种任务有用。有两种安装这些节点的方法。

首选方法来自节点红色。从右上角的汉堡菜单中,选择“管理调色板”。然后单击左窗格中的“安装”选项卡。您可以按照下面列出的节点的名称搜索,然后单击“小安装”按钮。

If you prefer, you can also install from the command line. Use these steps:

  • 为您的RPI建立SSH会话。
  • 导航到您的.node-red文件夹(通常在 /home /pi文件夹下找到):
    CD .NODE-RED

Bigtimer-带有黄昏,黎明,月份,天数,手册替补,时间表暂停等的计时器

  1. npm安装节点 - 雷德里布 - 基因二聚体

ping-用于在网络上采用输入和ping设备

  1. NPM安装节点红色可配合ping

MSSQL-用于在本地或云中建立与Microsoft SQL Server实例的连接。

  • NPM安装节点 - red-contrib-mssql

mySQL-将数据与MySQL数据库连接并交换

  • npm安装节点 - 雷诺 - 节点 - 摩斯QL

M2X-用于连接并与AT&T的M2X IoT平台连接并接口

  • NPM安装节点红色M2X

Bluemix - various nodes for interfacing with IBM Bluemix IoT platform

  • npm install node-red-bluemix-nodes

聚合器 - 用于在特定时间段内汇总数字值,包括平均值,中位数,最小,最大值

  • npm安装节点 - red-contrib-Aggregator

Moment - produces a nicely formatted Date/Time string

  • npm安装节点red-contrib-moment

SNMP-用于获取单个OID或启用SNMP主机的表OID

  • NPM安装节点 - 雷德节点-SNMP

地下天气 - 获得当前的天气条件和预测

  • NPM安装节点红节点 - 地下地下

Dropbox-从Dropbox Cloud发送和接收文件

  • npm安装节点 - 雷诺 - 节点盒
Modbus TCP-通过以太网与Modbus/TCP设备通信。
  • NPM安装节点 - 雷德 - contrib-modbus
SparkPlug-与SparkPlug协议与Cirrus链接或点火MQTT服务器进行通信
  • npm安装节点red-contrib sparkplug

立即安装所有节点:

CD .NODE-RED

节点red-stop

NPM安装节点 - red-contrib-bigtimer node-red-configurable-ping node-contrib-mssql node-red node-node-node-node-mysql node-m2x node-m2x node-m2x node-bluemix-node node node node node-red-contrib-contrib-moment-contrib-moment node node- 雷德节点-SNMP节点 - 雷德节点 - 降落节点 - 雷德节点 - 节点 - 节点red-contrib-modbus node-contrib-contrib sparkplug

node-red start



主题:节点红色,,,,GPIO,,,,G4 I/O,,,,覆盆子皮,,,,数字I/O用于Raspberry Pi

Written byBenson Hougland

找到我:

    Subscribe to Email Updates

    Recent Posts

      Posts by Topic

      查看全部