├── MD_MAX72XX-master.zip ├── Adafruit_MQTT_Library-master.zip ├── .gitattributes ├── .gitignore └── Google_Assistant_Controlled_Display └── Google_Assistant_Controlled_Display.ino /MD_MAX72XX-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techiesms/Google-Assistant-Controlled-Scrolling-Display/master/MD_MAX72XX-master.zip -------------------------------------------------------------------------------- /Adafruit_MQTT_Library-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techiesms/Google-Assistant-Controlled-Scrolling-Display/master/Adafruit_MQTT_Library-master.zip -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /Google_Assistant_Controlled_Display/Google_Assistant_Controlled_Display.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This is the code for the project called 3 | * Google Assistant Controlled Scrolling Display 4 | * which is edited by Sachin Soni for his YouTube channel "techiesms". 5 | * 6 | *Tutorial video of this project is available on the youtube channel whose link 7 | *is attached here. 8 | * 9 | * 10 | *explore|learn|share 11 | * techiesms 12 | * 13 | *YouTube Channel :- https://www.youtube.com/user/sachinsms1990 14 | * 15 | *Website :- http://www.techiesms.com 16 | * 17 | */ 18 | /************************* Necessary Libraries *********************************/ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "Adafruit_MQTT.h" 25 | #include "Adafruit_MQTT_Client.h" 26 | 27 | #define SCROLL_DELAY 75 28 | 29 | /************************* Variables *********************************/ 30 | char* str; 31 | String payload; 32 | uint32_t present; 33 | bool first_time; 34 | uint16_t scrollDelay; // in milliseconds 35 | #define CHAR_SPACING 1 // pixels between characters 36 | 37 | // Global message buffers shared by Serial and Scrolling functions 38 | #define BUF_SIZE 75 39 | char curMessage[BUF_SIZE]; 40 | char newMessage[BUF_SIZE]; 41 | bool newMessageAvailable = false; 42 | 43 | ESP8266WiFiMulti WiFiMulti; 44 | 45 | // Define the number of devices we have in the chain and the hardware interface 46 | // NOTE: These pin numbers will probably not work with your hardware and may 47 | // need to be adapted 48 | #define MAX_DEVICES 8 49 | 50 | /************************* Matrix Display Pins *********************************/ 51 | #define CLK_PIN D5 // or SCK 52 | #define DATA_PIN D7 // or MOSI 53 | #define CS_PIN D8 // or SS 54 | 55 | /************************* Adafruit.io Setup *********************************/ 56 | #define AIO_SERVER "io.adafruit.com" 57 | #define AIO_SERVERPORT 1883 // use 8883 for SSL 58 | #define AIO_USERNAME "USERNAME" 59 | #define AIO_KEY "KEY" 60 | 61 | 62 | /************ Global State (you don't need to change this!) ******************/ 63 | 64 | // Create an ESP8266 WiFiClient class to connect to the MQTT server. 65 | WiFiClient client; 66 | // or... use WiFiFlientSecure for SSL 67 | //WiFiClientSecure client; 68 | 69 | // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. 70 | Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); 71 | 72 | /****************************** Feeds ***************************************/ 73 | 74 | // Setup a feed called 'onoff' for subscribing to changes. 75 | Adafruit_MQTT_Subscribe message = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/message"); 76 | 77 | /*************************** Sketch Code ************************************/ 78 | 79 | // Bug workaround for Arduino 1.6.6, it seems to need a function declaration 80 | // for some reason (only affects ESP8266, likely an arduino-builder bug). 81 | void MQTT_connect(); 82 | 83 | // SPI hardware interface 84 | MD_MAX72XX mx = MD_MAX72XX(CS_PIN, MAX_DEVICES); 85 | // Arbitrary pins 86 | //MD_MAX72XX mx = MD_MAX72XX(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES); 87 | 88 | 89 | 90 | 91 | 92 | uint8_t scrollDataSource(uint8_t dev, MD_MAX72XX::transformType_t t) 93 | // Callback function for data that is required for scrolling into the display 94 | { 95 | static char *p = curMessage; 96 | static uint8_t state = 0; 97 | static uint8_t curLen, showLen; 98 | static uint8_t cBuf[8]; 99 | uint8_t colData; 100 | 101 | // finite state machine to control what we do on the callback 102 | switch (state) 103 | { 104 | case 0: // Load the next character from the font table 105 | showLen = mx.getChar(*p++, sizeof(cBuf) / sizeof(cBuf[0]), cBuf); 106 | curLen = 0; 107 | state++; 108 | 109 | // if we reached end of message, reset the message pointer 110 | if (*p == '\0') 111 | { 112 | p = curMessage; // reset the pointer to start of message 113 | if (newMessageAvailable) // there is a new message waiting 114 | { 115 | strcpy(curMessage, str); // copy it in 116 | newMessageAvailable = false; 117 | } 118 | } 119 | // !! deliberately fall through to next state to start displaying 120 | 121 | case 1: // display the next part of the character 122 | colData = cBuf[curLen++]; 123 | if (curLen == showLen) 124 | { 125 | showLen = CHAR_SPACING; 126 | curLen = 0; 127 | state = 2; 128 | } 129 | break; 130 | 131 | case 2: // display inter-character spacing (blank column) 132 | colData = 0; 133 | curLen++; 134 | if (curLen == showLen) 135 | state = 0; 136 | break; 137 | 138 | default: 139 | state = 0; 140 | } 141 | 142 | return (colData); 143 | } 144 | 145 | void scrollText(void) 146 | { 147 | static uint32_t prevTime = 0; 148 | 149 | // Is it time to scroll the text? 150 | if (millis() - prevTime >= scrollDelay) 151 | { 152 | mx.transform(MD_MAX72XX::TSL); // scroll along - the callback will load all the data 153 | prevTime = millis(); // starting point for next time 154 | } 155 | } 156 | void no_connection(void) 157 | { 158 | newMessageAvailable = 1; 159 | strcpy(curMessage, "No Internet! "); 160 | scrollText(); 161 | 162 | 163 | } 164 | void setup() 165 | { 166 | mx.begin(); 167 | mx.setShiftDataInCallback(scrollDataSource); 168 | 169 | scrollDelay = SCROLL_DELAY; 170 | strcpy(curMessage, "Hello! "); 171 | newMessage[0] = '\0'; 172 | 173 | Serial.begin(57600); 174 | Serial.print("\n[MD_MAX72XX Message Display]\nType a message for the scrolling display\nEnd message line with a newline"); 175 | 176 | Serial.begin(115200); 177 | // Serial.setDebugOutput(true); 178 | 179 | Serial.println(); 180 | Serial.println(); 181 | Serial.println(); 182 | 183 | for (uint8_t t = 4; t > 0; t--) { 184 | Serial.printf("[SETUP] WAIT %d...\n", t); 185 | Serial.flush(); 186 | delay(1000); 187 | } 188 | 189 | WiFi.mode(WIFI_STA); 190 | WiFiMulti.addAP("SSID1", "PASS1"); 191 | WiFiMulti.addAP("SSID2", "PASS2"); 192 | WiFiMulti.addAP("SSID3", "PASS3"); 193 | Serial.println("Connecting"); 194 | newMessageAvailable = 1; 195 | present = millis(); 196 | first_time = 1; 197 | // Setup MQTT subscription for onoff feed. 198 | mqtt.subscribe(&message); 199 | str = " Ask Google assistant to change the msg!!! "; 200 | } 201 | 202 | void loop() 203 | { 204 | while (WiFiMulti.run() != WL_CONNECTED) { 205 | Serial.println("WiFi not connected!"); 206 | delay(1000); 207 | } 208 | // Ensure the connection to the MQTT server is alive (this will make the first 209 | // connection and automatically reconnect when disconnected). See the MQTT_connect 210 | // function definition further below. 211 | MQTT_connect(); 212 | 213 | // this is our 'wait for incoming subscription packets' busy subloop 214 | // try to spend your time here 215 | 216 | 217 | 218 | Adafruit_MQTT_Subscribe *subscription; 219 | while ((subscription = mqtt.readSubscription(1))) { 220 | if (subscription == &message) { 221 | payload =""; 222 | Serial.print(F("Got: ")); 223 | Serial.println((char *)message.lastread); 224 | str = (char*)message.lastread; 225 | payload = (String) str; 226 | payload += " "; 227 | str = &payload[0]; 228 | newMessageAvailable = 1; 229 | } 230 | } 231 | 232 | scrollText(); 233 | } 234 | void MQTT_connect() { 235 | int8_t ret; 236 | 237 | // Stop if already connected. 238 | if (mqtt.connected()) { 239 | return; 240 | } 241 | 242 | Serial.print("Connecting to MQTT... "); 243 | 244 | uint8_t retries = 3; 245 | while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected 246 | Serial.println(mqtt.connectErrorString(ret)); 247 | Serial.println("Retrying MQTT connection in 5 seconds..."); 248 | mqtt.disconnect(); 249 | delay(5000); // wait 5 seconds 250 | retries--; 251 | if (retries == 0) { 252 | // basically die and wait for WDT to reset me 253 | while (1); 254 | } 255 | } 256 | Serial.println("MQTT Connected!"); 257 | } 258 | 259 | --------------------------------------------------------------------------------