This tutorial refers to a product that has reached its end-of-life status.

Arduino Yún Console Pixel

Control an LED through the Console.

An example of using a Yún device to receive data on the Console from a computer. In this case, the Yún device turns the on-board LED connected to digital pin 13 on when it receives the character 'H', and off when it receives the character 'L'.

The Console, based on Bridge, enables you to send information between the Yún device and a computer just as you would with the serial monitor, but wirelessly. It creates a secure connection between the Yún device and your computer via SSH.

To see the Console, make sure your Yún device and computer are in the same wireless network. Pick your Yún's name and IP address in the Port menu in the Arduino Software (IDE) then open the Serial Monitor. You can also see it by opening a terminal window and typing

ssh root@ yourYúnsName.local 'telnet localhost 6571'
then pressing enter. When prompted for the password, enter it.

Hardware Required

  • Yún board or shield

  • computer and Yún device on the same wireless network

Circuit

There is no circuit for this example.

The circuit for this tutorial.
The circuit for this tutorial.

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Code

Include the Console library, which inherits from Bridge.

#include <Console.h>

Create variables and name the pin to write to, and another one to store the incoming byte from the Console.

1const int ledPin = 13;
2char incomingByte;

In

setup()
initialize the Bridge and Console, and wait for a connection to the Console port.

1void setup() {
2
3 Bridge.begin();
4
5 Console.begin();
6
7 while(!Console);

Once connected, print out some basic instructions to the Console window with

Console.println()
and set the LED pin as an output.

1Console.println("type H or L to turn pin 13 on or off");
2
3 pinMode(ledPin, OUTPUT);
4}

In

loop()
, check to see if there is information from the Console. If there is, read the oldest byte in the buffer and echo it back to the Console window.

1void loop() {
2
3 if (Console.available() > 0) {
4
5 incomingByte = Console.read();
6
7 Console.println(incomingByte);

If the incoming byte is a capital "H", turn the LED on, if it is a "L", turn the LED off.

1if (incomingByte == 'H') {
2
3 digitalWrite(ledPin, HIGH);
4
5 }
6
7 if (incomingByte == 'L') {
8
9 digitalWrite(ledPin, LOW);
10
11 }
12
13 }
14}

The complete sketch is below :

1/*
2
3 Console Pixel
4
5 An example of using YunShield/Yún board to receive data from the
6
7 Console on the Yún. In this case, the board turns on an LED when
8
9 it receives the character 'H', and turns off the LED when it
10
11 receives the character 'L'.
12
13 To see the Console, pick your Yún's name and IP address in the Port menu
14
15 then open the Port Monitor. You can also see it by opening a terminal window
16
17 and typing
18
19 ssh root@ yourYunsName.local 'telnet localhost 6571'
20
21 then pressing enter. When prompted for the password, enter it.
22
23 The circuit:
24
25 * LED connected from digital pin 13 to ground
26
27 created 2006
28
29 by David A. Mellis
30
31 modified 25 Jun 2013
32
33 by Tom Igoe
34
35 This example code is in the public domain.
36
37 http://www.arduino.cc/en/Tutorial/ConsolePixel
38
39 */
40
41#include <Console.h>
42
43const int ledPin = 13; // the pin that the LED is attached to
44char incomingByte; // a variable to read incoming Console data into
45
46void setup() {
47
48 Bridge.begin(); // Initialize Bridge
49
50 Console.begin(); // Initialize Console
51
52 // Wait for the Console port to connect
53
54 while (!Console);
55
56 Console.println("type H or L to turn pin 13 on or off");
57
58 // initialize the LED pin as an output:
59
60 pinMode(ledPin, OUTPUT);
61}
62
63void loop() {
64
65 // see if there's incoming Console data:
66
67 if (Console.available() > 0) {
68
69 // read the oldest byte in the Console buffer:
70
71 incomingByte = Console.read();
72
73 Console.println(incomingByte);
74
75 // if it's a capital H (ASCII 72), turn on the LED:
76
77 if (incomingByte == 'H') {
78
79 digitalWrite(ledPin, HIGH);
80
81 }
82
83 // if it's an L (ASCII 76) turn off the LED:
84
85 if (incomingByte == 'L') {
86
87 digitalWrite(ledPin, LOW);
88
89 }
90
91 }
92}

Last revision 2016/05/25 by SM

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.