element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Industrial Automation
  • Technologies
  • More
Industrial Automation
Blog AVNET SmartEdge IIOT Gateway: Control Industrial I/O directly from Node-RED
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Industrial Automation to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 24 Jan 2021 9:46 PM Date Created
  • Views 1176 views
  • Likes 3 likes
  • Comments 1 comment
  • smartedge
  • node-red
  • edge_computing
Related
Recommended

AVNET SmartEdge IIOT Gateway: Control Industrial I/O directly from Node-RED

Jan Cumps
Jan Cumps
24 Jan 2021

The SmartEdge IIOT GatewaySmartEdge IIOT Gateway is a Raspberry Pi 3 Compute based industrial Linux box.

It runs Raspbian with some additions. There's a set of industrial hardware extensions. In this blog I revisit the industrial I/O. I create a Node-RED flow that controls the inputs and outputs.

image

 

The industrial I/Os are controlled via the file system. I built 2 flows and an init subflow in Node-RED to exercise the system.

Two pins of DIGIO A are used. I1 as input. O1 as output.

Here's how they are wired:

image

 

Output flow

image

The process has two "buttons". They are Node-RED Inject nodes

Pressing a button sends 1 or 0 to the file that serves as interface for O1. That results in Industrial I/O O1 being activated or deactivated.

I'm showing the top Inject node here. The other node is the same, but generates a 0.

image

 

The payload is forwarded to a file node:

image

For info on the filenames used in this post, refer to the very first blog post of this series.

 

These are the commands executed, if you'd do this from the Linux prompt:

#switch O1
sudo echo 1 > /sys/class/gpio/gpio201/value
sudo echo 0 > /sys/class/gpio/gpio201/value

 

Input flow

image

The "read" node is an Inject that does not add messages to the process. It's our trigger.

When pressing it, the I1 interface file gets read, and the output is logged to the debug window.

 

image

 

The two others nodes only have their name set. They do their default job.

In Linux, you'd execute:

#read I1
cat /sys/class/gpio/gpio201/value

 

Init Subflow

image

 

Before using them, the interfaces have to be exported and outputs have to be set.

You can do that at Linux startup if you want. I chose not to depend on that and made an init flow.

It exports the I1 and O1 (explained in the 1st post, including magic numbers and filenames) and sets O1 to output.

image

image

In essence: values 201 and 200 are written to the interface export file, and that activates I1 and O1.

image

Because this action may throw an error when the interface is already exported and buzy, I added a catch to avoid error messages in the debug window.

image

The output pin O1 is set to output:

image

written to the pin handler's direction file.

image

The Linux script would look like:

# enable DIGIO A I1 and O1
echo 200 >/sys/class/gpio/export
echo 201 >/sys/class/gpio/export
# make O1 an output pin
sudo echo out > /sys/class/gpio/gpio201/direction

 

The Node-RED source

This is the code for flow and subflow. This can be imported in Node-RED.

When you deploy it, you can directly test I1 and O1.

 

[
{"id":"a17b32e7.2ec35","type":"subflow","name":"Subflow init DIGIO","info":"","category":"","in":[],"out":[],"env":[],"color":"#DDAA99"},
{"id":"d3a2f9b2.f39798","type":"inject","z":"a17b32e7.2ec35","name":"export O1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"201","payloadType":"str","x":200,"y":80,"wires":[["8fa6d153.718b8"]]},
{"id":"8fa6d153.718b8","type":"file","z":"a17b32e7.2ec35","name":"export","filename":"/sys/class/gpio/export","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":390,"y":80,"wires":[[]]},
{"id":"950ca3fe.56b6a","type":"file","z":"a17b32e7.2ec35","name":"direction","filename":"/sys/class/gpio/gpio201/direction","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":400,"y":160,"wires":[[]]},
{"id":"27bb2e8b.92bc52","type":"inject","z":"a17b32e7.2ec35","name":"out O1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.5","topic":"","payload":"out","payloadType":"str","x":200,"y":160,"wires":[["950ca3fe.56b6a"]]},
{"id":"68535b63.eed274","type":"catch","z":"a17b32e7.2ec35","name":"ignore export if it is buzy","scope":["8fa6d153.718b8"],"uncaught":false,"x":230,"y":200,"wires":[[]]},{"id":"a38d7b40.a85ac8","type":"inject","z":"a17b32e7.2ec35","name":"export I1","props":[{"p":"payload"},
{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"200","payloadType":"str","x":200,"y":120,"wires":[["8fa6d153.718b8"]]},{"id":"2930abc4.06f094","type":"tab","label":"DIGIO","disabled":false,"info":""},{"id":"f3c94f23.3d446","type":"rpi-gpio out","z":"2930abc4.06f094","name":"DIGIO B O3","pin":"35","set":true,"level":"0","freq":"","out":"out","x":510,"y":720,"wires":[]},{"id":"5db3429d.3d146c","type":"inject","z":"2930abc4.06f094","name":"","props":[{"p":"payload"},
{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":310,"y":720,"wires":[["f3c94f23.3d446"]]},{"id":"e3d92d70.e3861","type":"inject","z":"2930abc4.06f094","name":"","props":[{"p":"payload"},
{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":310,"y":780,"wires":[["f3c94f23.3d446"]]},{"id":"4bf82d71.3d7654","type":"comment","z":"2930abc4.06f094","name":"modded to GPIOs","info":"","x":350,"y":660,"wires":[]},
{"id":"c8151694.4bc7d8","type":"comment","z":"2930abc4.06f094","name":"SmartEdge style","info":"","x":340,"y":860,"wires":[]},
{"id":"c65d4e31.7cff8","type":"inject","z":"2930abc4.06f094","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":310,"y":920,"wires":[["9ad9c626.44d138"]]},{"id":"b7e46153.4b49c","type":"inject","z":"2930abc4.06f094","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"str","x":310,"y":980,"wires":[["9ad9c626.44d138"]]},
{"id":"9ad9c626.44d138","type":"file","z":"2930abc4.06f094","name":"DIGIO A O1","filename":"/sys/class/gpio/gpio201/value","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":530,"y":920,"wires":[[]]},
{"id":"8f5ad274.395a1","type":"file in","z":"2930abc4.06f094","name":"DIGIO A I1","filename":"/sys/class/gpio/gpio200/value","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":530,"y":1040,"wires":[["2e3e8462.6c5fec"]]},
{"id":"2e3e8462.6c5fec","type":"debug","z":"2930abc4.06f094","name":"debug window","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":760,"y":1040,"wires":[]},
{"id":"2335d9e3.e3dee6","type":"inject","z":"2930abc4.06f094","name":"read","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":310,"y":1040,"wires":[["8f5ad274.395a1"]]},
{"id":"29be1a09.ac6376","type":"subflow:a17b32e7.2ec35","z":"2930abc4.06f094","name":"Initialise DIGIO","env":[],"x":540,"y":860,"wires":[]}
]

 

todo: links to previous blogs...

 

Related Blog
Industrial I/O
Use the Industrial I/O
Control Industrial I/O directly from GPIO Pins
C Program for the Industrial I/O
Control Industrial I/O directly from Node-RED
Display Industrial I/O on Node-RED Dashboard
CAN Bus
Use the Isolated CAN
CAN programming in C on Linux: Filter and Mask
2020 Linux Image
The 2020 Linux Image and IoTConnect Scripts
Understand the Custom Scripts and Services (Pt. 1: intro and reset button service)
Understand the Custom Scripts and Services (Pt. 2: led service)
Understand the Custom Scripts and Services (Pt. 3: IoT Connect service)
  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 4 years ago +1
    Showing the industrial pin status on a Node-RED dashboard: AVNET SmartEdge IIOT Gateway: Display Industrial I/O on Node-RED Dashboard www.youtube.com/watch An example with history:
Parents
  • Jan Cumps
    Jan Cumps over 4 years ago

    Showing the industrial pin status on a Node-RED dashboard: AVNET SmartEdge IIOT Gateway: Display Industrial I/O on Node-RED Dashboard

     

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

     

    An example with history:

    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • Jan Cumps
    Jan Cumps over 4 years ago

    Showing the industrial pin status on a Node-RED dashboard: AVNET SmartEdge IIOT Gateway: Display Industrial I/O on Node-RED Dashboard

     

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

     

    An example with history:

    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube