Hello all,
Today the whole Arduino programming is starting to click, its taken me quite a while! I have learned so much in the last few days that i am really happy with. I have also spent a lot of time doing research and trying to self learn, rather than spamming forums for support.
One of the main things i have been really struggling with is LCD displays, and uploading information to them.
I have a new project of making a Instagram live subscriber counter using a D1 Mini ESP8226 and the MD library's (MD_Parola / MD_MAX72xx)
I have made lots of learning progress using <LiquidCrystal_I2C> and that was kindly shared by Brian Lough.
I successfully used a Liquid Crystal display properly this morning and even managed to work the code to print the information onto the screen (not just serial monitor). This was hugely exciting for me, to actually see it working.
Granted, this is not exactly 'advanced' by any means, but i had to do a lot of research and learning of including library's outside of IDE and combing different bits of code together. I also used a serial port scanner to get the 0x27 code to run the 16x2 lcd screen.
This was done via the Wesmos D1 8226. Here is the code i used:
/*******************************************************************
* An example of usisng the InstagramStats library to get
* info on a given user.
*
* Written by Brian Lough
*
*******************************************************************/
#include "InstagramStats.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
// ----------------------------
// Standard Libraries - Already Installed if you have ESP8266 set up
// ----------------------------
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
// ----------------------------
// Additional Libraries - each one of these will need to be installed.
// ----------------------------
#include "JsonStreamingParser.h"
// Used to parse the Json code within the library
// Available on the library manager (Search for "Json Streamer Parser")
// https://github.com/squix78/json-streaming-parser
//------- Replace the following! ------
char ssid[] = "My SSID"; // your network SSID (name)
char password[] = "My Password"; // your network key
WiFiClientSecure client;
InstagramStats instaStats(client);
unsigned long delayBetweenChecks = 20000; //mean time between api requests
unsigned long whenDueToCheck = 0;
//Inputs
String userName = "My Instagrame Name"; // from their instagram url https://www.instagram.com/brian_lough/
void setup() {
Serial.begin(115200);
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
// Set WiFi to station mode and disconnect from an AP if it was Previously
// connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
// Attempt to connect to Wifi network:
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("...Connecting... ");
lcd.setCursor(0,1);
lcd.print("....The Wifi....");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
lcd.print(".");
delay(5000);
lcd.clear();
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);
}
void getInstagramStatsForUser() {
// On
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("...Refreshing...");
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(" Live Sub Count ");
delay(1000);
lcd.clear();
// Off
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(" ");
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(" Live Sub Count ");
delay(1000);
lcd.clear();
// On
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("...Refreshing...");
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(" Live Sub Count ");
delay(1000);
lcd.clear();
// Off
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(" ");
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(" Live Sub Count ");
delay(1000);
lcd.clear();
// On
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("...Refreshing...");
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(" Live Sub Count ");
delay(1000);
lcd.clear();
// Off
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(" ");
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(" Live Sub Count ");
delay(1000);
lcd.clear();
// On
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("...Refreshing...");
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(" Live Sub Count ");
delay(1000);
lcd.clear();
// Off
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(" ");
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(" Live Sub Count ");
delay(1000);
lcd.clear();
// On
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("...Refreshing...");
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(" Live Sub Count ");
delay(1000);
lcd.clear();
Serial.println("Getting instagram user stats for " + userName );
delay(1000);
lcd.clear();
InstagramUserStats response = instaStats.getUserStats(userName);
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Ben Smith");
lcd.setCursor(0,1);
lcd.print(response.followedByCount);
Serial.println("Response:");
Serial.print("Number of followers: ");
Serial.println(response.followedByCount);
}
void loop() {
unsigned long timeNow = millis();
if ((timeNow > whenDueToCheck)) {
getInstagramStatsForUser();
whenDueToCheck = timeNow + delayBetweenChecks;
}
}
This part of the code is rather ugly, i am sure there is a better way to wrap this code up to 'Flash' the lcd.print comment, this i will do some more research into:
// On
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("...Refreshing...");
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(" Live Sub Count ");
delay(1000);
lcd.clear();
// Off
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(" ");
lcd.backlight();
lcd.setCursor(0,1);
lcd.print(" Live Sub Count ");
delay(1000);
lcd.clear();
I am happy how that has turned out for now using the LCD, but for this project i was wanting to use the MD_MAX72xx library's and a FC16 x 4 matrix module, just to show some basic information (i know it is a powerful library)
This is where i ran into trouble!
I went back to basics and tried to upload some example sketches from the MD library's to the 8226 board, using all the same pin set ups and i failed to get it to work.
I then went even more basic, and used my Leonardo board to run some of the examples (Daft punk, Robot eyes, serial prints and graphs using a pin pulled low to change displays etc...) they all worked OK (after searching for the Leonardo pin that are different from everything else)
Feeling pleased with myself, i decided to go back and try the included sample MD_MAX72xx_ESP8226.
Again, i checked everything to ensure the pins were defined.
It did not work for me.