Make your own router with WRTNode - controlling LEDs via the GPIO port

In previous articles about WRTNode among other things, we learned, How to add four ports LAN and a port WAN to this small router oriented development related projects with the Internet of things and the Robotics.

Today we will learn the basics about the port GPIO This device making Flash a bi-color led, or two failing LEDs as different colors of “Hello World” to be familiarized with This development platform.

The first thing we must do is to connect the bi-color led, or the LEDs two different colors in the pins GPIO0 and GPIO2 just as in the following table and the rear scheme of connection; should be noted that will not need to use resistors due to the low voltages that works WRTNode.

WRTNode Diode LED
Green anode
Red anode
Common cathode

If you use two LEDs instead of one bicolor, You must connect a bridge between the cathodes of both; On the other hand, the bi-color led they have one shared by its two anodes which reduces cabling required for this practice.

Connection between the bi-color led and WRTNode diagram

Now already we can feed our WRTNode, and connect to the Management Console of OpenWRT by means of the serial port as we learned in This previous article, to export the GPIO2, configure it as output, and assign a positive value “1“; Finally we reasignaremos a low value “0” to turn off led.

#Encendemos el led rojo
root@OpenWrt:~# echo 2 > /sys/class/gpio/export
root@OpenWrt:~# echo out > /sys/class/gpio/gpio2/direction
root@OpenWrt:~# echo 1 > /sys/class/gpio/gpio2/value

#Apagamos el led rojo
root@OpenWrt:~# echo 0 > /sys/class/gpio/gpio2/value

At this point repeat the previous step, This time with the GPIO0 to test the second diode of our bi-color led and check all circuit.

#Encendemos el led verde
root@OpenWrt:~# echo 0 > /sys/class/gpio/export
root@OpenWrt:~# echo out > /sys/class/gpio/gpio0/direction
root@OpenWrt:~# echo 1 > /sys/class/gpio/gpio0/value

#Apagamos el led verde
root@OpenWrt:~# echo 0 > /sys/class/gpio/gpio0/value

After checking its correct operation, We plasmaremos the the two steps above code in a script, so we will use the default text editor in this case it is VI, and We will stick the following code in our file called blinkleds; It should be noted that the shell by default in OpenWRT ES “Ash“, very similar to “bash” but with certain limitations.


#Exportamos los GPIO
echo 0 > /sys/class/gpio/export
echo 2 > /sys/class/gpio/export

#Los definimos como salidas
echo out > /sys/class/gpio/gpio0/direction
echo out > /sys/class/gpio/gpio2/direction

#Los hacemos parpadear
while true; do
  echo 1 > /sys/class/gpio/gpio0/value
  sleep 1
  echo 0 > /sys/class/gpio/gpio0/value
  sleep 1
  echo 1 > /sys/class/gpio/gpio2/value
  sleep 1
  echo 0 > /sys/class/gpio/gpio2/value
  sleep 1

You only need give Execute permissions to the script to finally run it, now the led It will Flash changing color until we interrupt the programme by pressing the key combination “CTRL + c“.

root@OpenWrt:~# chmod +x leds 
root@OpenWrt:~# ./leds

In this video You can see the operation of the fitting is made; If you like do not forget follow me on YouTube to not miss any of the unpublished videos I'm going to publish, regardless of the articles that I write.

In the following howto We will learn to develop a small program that will allow us to assign each led to a service, and generate visual warnings associated with events that define.

If you like you can follow me on Twitter, Facebook, Google +, LinkedIn, or share it with the buttons under this publication, If you have any questions or suggestions please do not hesitate to comment.

Help us to reach more readers Share on LinkedInShare on FacebookTweet about this on TwitterShare on Google+Email this to someone

Leave a Reply