Introduction: Arduino Yun Messager

About: Technologist, Electronic Engineer, sometime Coderdojo mentor.

Consisting of an Arduino side and a Linux (Linio) side, the Yun is a great platform for Wi-Fi or Web enabled Arduino projects.

In this project I'll show you how to make a very simple Yun-Messager that displays your message sent to it over Wi-Fi.

I modified the Bridge Example code, to keep it simple and added an Adafruit TFT display.

Features:

  • Arduino Yun running a Web Server
  • Messaging via the REST protocol
  • Display messages on a TFT display

Interested?

Here goes....

==============
By the way. If you like this Instructable, you might also like to read My Blog covering various projects and Tutorials.

==============

Step 1: Let's Get Started

You will need:
  1. Arduino Yun
  2. Adafruit TFT Display
  3. A breadbord and some wires
  4. A 5V power source for the Yun or USB cable to power from a PC

Install the Adafruit TFT libraries:
Adafruit ILI9340 library
Adafruit GFX Library

You can add them to the Arduino IDE by Sketch-> Import Library... ->Add Library...

The Adafruit TFT display is a breakout board with a 2.2" colour display. It interfaces with the Yun via SPI. On the Arduino UNO or similar the SPI pins are made available on the digital pins 13, 12, 11 and on the ICSP header but on the Leonardo and Yun they are only available on the ICSP header. This means you will need a male-male connecter to wire conveniently to the display. I made one by soldering together two Arduino Headers as shown.




Step 2: Wire It Up

Wire the SPI and Power connections of the TFT breakout board to the ICSP header as shown:
  • SCK
  • MISO
  • MOSI
  • Vin
  • Gnd

Wire the control connections of the TFT breakout board to the digital pins as shown:
  • CS -> D10
  • RST -> D9
  • D/C -> D8

Once it's wired up connect the Yun to your Wi-Fi network if you haven't done that already.

Step 3: REST Protocol and Code

I've modified the Bridge Example to act as a Server. It waits for a connection from a client such as a Web Browser. Once it sees that a Client has connected it parses the GET request for the string "message". Once it sees this it knows that a correctly formed command has been received containing a message. Then it prints that acknowledges the command back to the Client and prints the message on to the TFT display.

The REST protocol means the message looks like /arduino/message/this is my message

If your arduino was called arduino and was located at IP address 192.168.1.34 then the full REST would be:
http: //192.168.1.14/arduino/message/I got this message over Wifi :-)

NOTE: any spaces or special characters will be replaced by their Hex codes by the Client browser before sending to the Yun. For example:
192.168.1.14/arduino/message/I%20got%20this%20%20%20message%20over%20Wifi%20:-%29

Here's the code. As you can see it's a fairly straightforward mod of the Bridge Example and Adafruit's TFT example:


/*
Adapted from: Arduino Yun Bridge example http://arduino.cc/en/Tutorial/Bridge Adapted from example sketch for the Adafruit 2.2" SPI display written by Limor Fried/Ladyada for Adafruit Industries. This library works with the Adafruit 2.2" TFT Breakout w/SD card ----> http://www.adafruit.com/products/1480 */ #include "Bridge.h"
#include "YunServer.h" #include "YunClient.h" #include "SPI.h" #include "Adafruit_GFX.h" #include "Adafruit_ILI9340.h" #if defined(__SAM3X8E__) #undef __FlashStringHelper::F(string_literal) #define F(string_literal) string_literal #endif // These are the pins used for the UNO // for Due/Mega/Leonardo use the hardware SPI pins (which are different) #define _sclk 13 #define _miso 12 #define _mosi 11 #define _cs 10 #define _rst 9 #define _dc 8 Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst); // Listen on default port 5555, the webserver on the Yun // will forward there all the HTTP requests for us. YunServer server; void setup() { // Bridge startup pinMode(13,OUTPUT); digitalWrite(13, LOW); Bridge.begin(); digitalWrite(13, HIGH); // Listen for incoming connection only from localhost // (no one from the external network could connect) server.listenOnLocalhost(); server.begin(); tft.begin(); tft.fillScreen(ILI9340_BLACK); tft.setRotation(1); } void loop() { // Get clients coming from server YunClient client = server.accept(); // There is a new client? if (client) { // Process request process(client); // Close connection and free resources. client.stop(); } delay(50); // Poll every 50ms } void process(YunClient client) { // read the command String command = client.readStringUntil('/'); // is "message" command? if (command == "message") { messageCommand(client); } } void messageCommand(YunClient client) { String message = client.readStringUntil('/'); // Send feedback to client client.print(F("Message")); client.print(F(" set to ")); client.println(message); // Update datastore key with the current message value String key = "Message"; Bridge.put(key, message); // Send to the Screen tft.fillScreen(ILI9340_WHITE); tft.setCursor(5, 5); tft.setTextColor(ILI9340_BLACK); tft.setTextSize(4); tft.println(message); }

Step 4: Enjoy!

That's it.

Enter your messages in REST protocol from the URL bar of a browser as described and have fun.

I've focused on keeping the code simple and clear but please go ahead and change it.

Some ideas:
  • A button to confirm the message has been read.
  • After 5 minutes put some display on the TFT like scrolling lines or something to catch someones attention. Then display the message again.
  • Once a client connects without "message" in the REST serve out a Web Form for the user to fill in the message. Modify the code to use GET forms. (i.e. arduino/?message=my_message)