Go Down

Topic: D1 Mini ESP8226 / MD_Max72xx / Instagram Count Live (Read 374 times) previous topic - next topic

Cosha

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 <InstagramStats> 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:

Code: [Select]
/*******************************************************************
 *  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:

Code: [Select]

// 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.


Cosha

So i pressed on and tried to use a bit of code to get the InstagramStats to work with the ESP8226:

Code: [Select]


/*******************************************************************
 *  An example of usisng the InstagramStats library to get
 *  info on a given user.
 *
 *  Written by Brian Lough
 *  
 *******************************************************************/

 // ----------------------------
 // Standard Libraries - Already Installed if you have ESP8266 set up
 // ----------------------------

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include "InstagramStats.h"

// ----------------------------
// Additional Libraries - each one of these will need to be installed.
// ----------------------------

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted

// Connections for ESP8266 hardware SPI are:
// Vcc       3v3     LED matrices seem to work at 3.3V
// GND       GND     GND
// DIN        D7     HSPID or HMOSI
// CS or LD   D8     HSPICS or HCS
// CLK        D5     CLK or HCLK

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define DIN_PIN D7
#define CS_PIN  D8
#define CLK_PIN D5

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

#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 = 60000; //mean time between api requests
unsigned long whenDueToCheck = 0;

//Inputs
String userName = "My Name"; // from their instagram url https://www.instagram.com/brian_lough/


void setup() {

  Serial.begin(115200);
  P.begin();

  // 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:
  P.displayText("Connecting Wifi", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);
}

void getInstagramStatsForUser() {
  Serial.println("Getting instagram user stats for " + userName );
  InstagramUserStats response = instaStats.getUserStats(userName);
  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;
    
P.displayAnimate();
  }
}

 



Unfortunately, it does not work.
Hopefully i have shown that i have been trying my hardest to make this work, i would very much appreciate a gentle nudge in the wright direction to get it working.

Not asking for a new code to be written for me, i wont learn that way, but more of a push the right way so i don't follow the wrong path!

Thanks so much in advance!

Cosha

A day later, countless research later, i cannot get the matrix board to play!

The only code that could make it usable is this:


Code: [Select]
#include "Arduino.h"
#include <ESP8266WiFi.h>

WiFiClient client;

#define NUM_MAX 4
#define ROTATE 90

// for ESP-01 module
//#define DIN_PIN 2 // D4
//#define CS_PIN  3 // D9/RX
//#define CLK_PIN 0 // D3

// for NodeMCU 1.0
#define DIN_PIN 15  // D8 //15
#define CS_PIN  13  // D7 //13
#define CLK_PIN 12  // D6 //12

#include "max7219.h"
#include "fonts.h">


This was used from a youtube live count library.

i have also installed:

LedControlSPIESP8266.h

No luck either there!
I'm now stumped after 2 days!




Cosha

Day 3?

I'm not sure i'm loosing all track of time  :o

So, I have managed to get MD_Parola and MD_MAX72xx working with my Wemos D1  :smiley-cool:
I did a whole clean of my library's (one suspects that i had so many library's, there must of been conflicts somewhere when compiling the sketch)

Now however, getting my information displayed 'statically' on the FC16 board is somewhat difficult for me.

Code: [Select]
/*******************************************************************
 *  An example of usisng the InstagramStats library to get
 *  info on a given user.
 *
 *  Written by Brian Lough
 *  https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA
 *******************************************************************/

#include "InstagramStats.h"

 // ----------------------------
 // Standard Libraries - Already Installed if you have ESP8266 set up
 // ----------------------------

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN   14  // or SCK
#define DATA_PIN  13  // or MOSI
#define CS_PIN    15  // or SS

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// ----------------------------
// 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[] = "**";       // your network SSID (name)
char password[] = "**";  // your network key

WiFiClientSecure client;
InstagramStats instaStats(client);

unsigned long delayBetweenChecks = 60000; //mean time between api requests
unsigned long whenDueToCheck = 0;

//Inputs
String userName = "Ben_bear_smith"; // from their instagram url https://www.instagram.com/brian_lough/


void setup() {

  Serial.begin(115200);
  P.begin();

  // 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:
  P.displayText("WiFi", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(5000);

 
 
  P.displayClear();

  }

  // When Connected
  P.displayText("* OK", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);
}

void getInstagramStatsForUser() {
  Serial.println("Getting instagram user stats for " + userName );
  P.displayText("Wait", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT );
  InstagramUserStats response = instaStats.getUserStats(userName);
  Serial.println("Response:");
  Serial.print("Number of followers: ");
  Serial.println(response.followedByCount);
  P.displayText(" " + response.followedByCount);
}

void loop() {
  P.displayAnimate();
  unsigned long timeNow = millis();
  if ((timeNow > whenDueToCheck))  {
    getInstagramStatsForUser();
    whenDueToCheck = timeNow + delayBetweenChecks;
  }
}



This code fails:
Code: [Select]
  P.displayText(" " + response.followedByCount);

Also this fails:
Code: [Select]
P.displayText(response.followedByCount , PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT );


This code works:
 P.displayText("Wait", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT );



Please....

Someone shoot me!

Cosha

Well...That will do i guess!

Thanks for following along!

Code: [Select]
/*******************************************************************
 *  An example of usisng the InstagramStats library to get
 *  info on a given user.
 *
 *  Written by Brian Lough
 *  https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA
 *******************************************************************/

#include "InstagramStats.h"

 // ----------------------------
 // Standard Libraries - Already Installed if you have ESP8266 set up
 // ----------------------------

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN   14  // or SCK
#define DATA_PIN  13  // or MOSI
#define CS_PIN    15  // or SS
#define PRINT(s, x) { Serial.print(F(s)); Serial.print(x); }

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// ----------------------------
// 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[] = "                       ";       // your network SSID (name)
char password[] = "               ";  // your network key

WiFiClientSecure client;
InstagramStats instaStats(client);

unsigned long delayBetweenChecks = 10000; //mean time between api requests
unsigned long whenDueToCheck = 0;

//Inputs
String userName = "Ben_bear_smith"; // from their instagram url https://www.instagram.com/brian_lough/
String W = "Wifi";
String R01 = ".";
String R02 = "...";
String R03 = ".....";
String R04 = ".......";
String R05 = ".........";
String R06 = "...........";
String R07 = "..... .....";
String R08 = "....   ....";
String R09 = "...     ...";
String R10 = "..       ..";
String R11 = ".         .";

void setup() {

  Serial.begin(115200);
  P.begin();

  // 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:
  P.displayText("WiFi", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(5000);
  P.displayClear();

  }

  // When Connected
  P.print (W);
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);
  delay (4000);
  P.displayClear();
}

void getInstagramStatsForUser() {
  Serial.println("Getting instagram user stats for " + userName);
  P.print(R01);
  delay(400);
  P.print(R02);
  delay(400);
  P.print(R03);
  delay(400);
  P.print(R04);
  delay(400);
  P.print(R05);
  delay(400);
  P.print(R06);
  delay(400);
  P.print(R07);
  delay(400);
  P.print(R08);
  delay(400);
  P.print(R09);
  delay(400);
  P.print(R10);
  delay(400);
  P.print(R11);

  P.displayClear();
 
  InstagramUserStats response = instaStats.getUserStats(userName);
  Serial.println("Response:");
  Serial.print("Number of followers: ");
  Serial.println(response.followedByCount);
  P.print(response.followedByCount);
  delay(10000);
  P.displayClear();
}

void loop() {
  P.displayAnimate();
  unsigned long timeNow = millis();
  if ((timeNow > whenDueToCheck))  {
    getInstagramStatsForUser();
    whenDueToCheck = timeNow + delayBetweenChecks;
  }
}

Go Up