Project showcase
MKR1000 Message of the Day

MKR1000 Message of the Day © GPL3+

Use Arduino MKR1000 and a LCD to set the message of the day.

  • 1,758 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

I wanted to display text on an LCD screen with the MKR1000. I wrote a simple sketch that subscribes to a topic from my own Mosquitto server and updates the screen with on the data it receives.

You can update the screen using your phone or your laptop, all you need is a MQTT client. Setting up your own Mosquitto server is a little harder and I won't be covering this, you could use Arduino Cloud as an alternative.

Wiring

To wire the LCD just search for the UNO wiring and invert pin 11 with pin 4.

Code

SKETCHC/C++
// include the library code:
#include <LiquidCrystal.h>
#include <PubSubClient.h>
#include <WiFi101.h>


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 4, 5, 11, 3, 2);

// Network settings
char ssid[] = "iPhone";     //  your network SSID (name)
char pass[] = "xxxxxx";  // your network password

// Server settings
char * server  = "yerr server";
const int port = 8883; // Need to add certificates via Firmware Updater

// MQTT settings
char * client_id     = "arduino_mkr1000"; // your thing name
char * mqtt_username = "user"; // your mqtt username, null if not used
char * mqtt_password = "pass"; // your mqtt password, null if not use
char * topic0        = "motd";
int status = WL_IDLE_STATUS;     // the Wifi radio's status

// Client settings
WiFiSSLClient sslClient;
PubSubClient client(sslClient);

void setup() {
  Serial.begin(115200);
  while (!Serial);
  // set up the LCD's number of columns and rows:

  // Print MOTD
  lcd.begin(16, 2);
  lcd.print("      MOTD");


  Serial.println("Initializing");
  Serial.println(WiFi.status());
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);
  }

  // you're connected now, so print out the data:
  Serial.println("You're connected to the network");
 
  client.setServer(server, port);
  client.setCallback(on_message);



  // Allow the hardware to sort itself out
  delay(1500);
}

void on_message(char* topic, byte* payload, unsigned int length) {
    Serial.print("Got message: ");
    String message;
    for (int i = 0; i < length; ++i) {
      Serial.print( (char)payload[i] );
      message += (char)payload[i];
    }
    Serial.print(" length: ");
    
    Serial.println(length);
    if ( length <= 16 ) {
      lcd.clear();
      lcd.begin(16, 2);
      lcd.print("      MOTD");
      lcd.setCursor(0,1);
      lcd.print(message);
    }
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection: ");
    // Attempt to connect
    if (client.connect(client_id, mqtt_username, mqtt_password)) {
      Serial.println("connected");
      subscribeAll();
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

void subscribeAll() {
  // Subscribe to all topics here.
  client.subscribe(topic0);
  Serial.println("Subscribing to topics..");
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();
}

Comments

Similar projects you might like

Arduino MKR1000 Kit

Project showcase by Team TATCO

  • 2,104 views
  • 1 comment
  • 11 respects

Water Quality Monitoring Using MKR1000 and ARTIK Cloud

Project tutorial by Team Animo!

  • 7,077 views
  • 12 comments
  • 30 respects

Control your MKR1000 with aREST Framework

Project showcase by vincent wong

  • 5,514 views
  • 5 comments
  • 16 respects

MKR1000 Christmas IoTree with Cayenne Project Builder

Project tutorial by Benny Estes

  • 3,077 views
  • 3 comments
  • 9 respects

Arduino MKR1000 & Favoriot

Project tutorial by Lintang Wisesa

  • 211 views
  • 0 comments
  • 2 respects

MKR1000 WiFi Robot

Project showcase by Arduino_Genuino

  • 32,107 views
  • 10 comments
  • 58 respects
Add projectSign up / Login