SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
By JoeteckTips
#198469
Hello Arduino gurus,

I know nothing about Arduino. Going at this blindly. I truly envy you guys. This is some hard stuff. I asked for help at another forum but they needed to get paid which I find very strange. This is a hobby. Forums are places to get help.

I am looking to build a YouTube subscriber counter.

I have watched a very fasted paced tutorial video from www.educ8s.tv on how to create your very own YouTube subscriber counter display.
I have started the return process of my 20x4 display as I believe it to be DOA. I can't get any output to it or turn on the back light. The location is at 0x3F for the display, I checked to make sure.

I just need to program the ESP8266 D1 Mini and output to the 20x4 I2C LCD display.
These are the libraries I need. I believe I have added them successfully. The top three are in red, not sure why.
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>
#include <ArduinoJson.h>

If I get this working, I will give you a shout out in my Youtube video on who has helped me and direct everyone with a Arduino issue to come see ABC person(s). My channel is about reviews and how tos. I'm not trying to pass this off as my idea, but offer them a better tutorial making it easier for the beginner like myself.

Please tell me what I need to change or add to get this to work. Please let me know of this works for you and let me know what I need to do on my end to get it to work. where to download the correct libraries. Thank you.

JoeteckTips

Here is the code:
<begin code>

//////////////////////////////////////////////
// 20x4 Subscriber Counter for YouTube //
// //
// http://www.educ8s.tv //
/////////////////////////////////////////////

#include <Wire.h>
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>
#include <ArduinoJson.h>

byte LT[8] =
{
B01111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};

byte UB[8] =
{
B11111,
B11111,
B11111,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte RT[8] =
{
B11110,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};

byte LL[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B01111
};

byte LB[8] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111,
B11111
};

byte LR[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11110
};

byte UMB[8] =
{
B11111,
B11111,
B11111,
B00000,
B00000,
B00000,
B11111,
B11111
};

byte LMB[8] =
{
B11111,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111,
B11111
};

const char* ssid = "SSID of local network"; // SSID of local network
const char* password = "Password on network"; // Password on network
String apiKey = "YouTube Data API"; // YouTube Data API v3 key generated here: // https://console.developers.google.com
String channelId = "YouTube channel id"; // YouTube channel id

const char *host = "www.googleapis.com";
long subscribers,subscribersBefore = 0;

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

void setup()
{
Serial.begin(9600);
int cursorPosition=0;

lcd.begin(20,4);
lcd.setCursor(0,0);
lcd.print("Connecting ....");

createCustomChars();

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
lcd.setCursor(cursorPosition,1);
lcd.print(".");
cursorPosition++;
}

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Connected!");
delay(1000);
}

void loop()
{
int length;
String subscribersString = String(getSubscribers());
if(subscribers != subscribersBefore)
{
lcd.clear();
length = subscribersString.length();
printSubscribers(length,subscribersString);
subscribersBefore = subscribers;
}
delay(60000);
}

void printSubscribers(int length, String subscribersString)
{
switch(length)
{
case 5: printDigits(subscribersString,5);printDigits(subscribersString,4);printDigits(subscribersString,3);printDigits(subscribersString,2);printDigits(subscribersString,1);break;
case 4: printDigits(subscribersString,4);printDigits(subscribersString,3);printDigits(subscribersString,2);printDigits(subscribersString,1);break;
case 3: printDigits(subscribersString,3);printDigits(subscribersString,2);printDigits(subscribersString,1);break;
case 2: printDigits(subscribersString,2);printDigits(subscribersString,1);break;
case 1: printDigits(subscribersString,1);break;
default: break;
}
}

void printDigits(String subscribersString,int digit)
{
int length = subscribersString.length();
char digitToPrint = subscribersString.charAt(length-digit);
Serial.println(digitToPrint);
switch(digit)
{
case 1: printDigitToScreen(digitToPrint,17); break;
case 2: printDigitToScreen(digitToPrint,13); break;
case 3: printDigitToScreen(digitToPrint,9); break;
case 4: printDigitToScreen(digitToPrint,5); break;
case 5: printDigitToScreen(digitToPrint,1); break;
}
}

void printDigitToScreen(char digit,int position)
{
int digitToPrint = digit - '0'; //Convertion from char to int
switch(digitToPrint)
{
case 1:digit1(position); break;
case 2:digit2(position); break;
case 3:digit3(position); break;
case 4:digit4(position); break;
case 5:digit5(position); break;
case 6:digit6(position); break;
case 7:digit7(position); break;
case 8:digit8(position); break;
case 9:digit9(position); break;
case 0:digit0(position); break;
}
}

void digit0(int position_x)
{
lcd.setCursor(position_x, 1);
lcd.write((byte)0);
lcd.write(1);
lcd.write(2);
lcd.setCursor(position_x, 2);
lcd.write(3);
lcd.write(4);
lcd.write(5);
}

void digit1(int position_x)
{
lcd.setCursor(position_x,1);
lcd.write(1);
lcd.write(2);
lcd.setCursor(position_x+1,2);
lcd.write(5);
}

void digit2(int position_x)
{
lcd.setCursor(position_x,1);
lcd.write(6);
lcd.write(6);
lcd.write(2);
lcd.setCursor(position_x, 2);
lcd.write(3);
lcd.write(7);
lcd.write(7);
}

void digit3(int position_x)
{
lcd.setCursor(position_x,1);
lcd.write(6);
lcd.write(6);
lcd.write(2);
lcd.setCursor(position_x,2);
lcd.write(7);
lcd.write(7);
lcd.write(5);
}

void digit4(int position_x)
{
lcd.setCursor(position_x,1);
lcd.write(3);
lcd.write(4);
lcd.write(2);
lcd.setCursor(position_x+2,2);
lcd.write(5);
}

void digit5(int position_x)
{
lcd.setCursor(position_x,1);
lcd.write((byte)0);
lcd.write(6);
lcd.write(6);
lcd.setCursor(position_x,2);
lcd.write(7);
lcd.write(7);
lcd.write(5);
}

void digit6(int position_x)
{
lcd.setCursor(position_x,1);
lcd.write((byte)0);
lcd.write(6);
lcd.write(6);
lcd.setCursor(position_x,2);
lcd.write(3);
lcd.write(7);
lcd.write(5);
}

void digit7(int position_x)
{
lcd.setCursor(position_x,1);
lcd.write(1);
lcd.write(1);
lcd.write(2);
lcd.setCursor(position_x+1,2);
lcd.write((byte)0);
}

void digit8(int position_x)
{
lcd.setCursor(position_x,1);
lcd.write((byte)0);
lcd.write((byte)6);
lcd.write(2);
lcd.setCursor(position_x,2);
lcd.write(3);
lcd.write(7);
lcd.write(5);
}

void digit9(int position_x)
{
lcd.setCursor(position_x,1);
lcd.write((byte)0);
lcd.write((byte)6);
lcd.write((byte)2);
lcd.setCursor(position_x+2,2);
lcd.write((byte)5);
}

int getSubscribers()
{
WiFiClientSecure client;
Serial.print("connecting to "); Serial.println(host);
if (!client.connect(host, 443)) {
Serial.println("connection failed");
return -1;
}
String cmd = String("GET /youtube/v3/channels?part=statistics&id=") + channelId + "&key=" + apiKey+ " HTTP/1.1\r\n" +
"Host: " + host + "\r\nUser-Agent: ESP8266/1.1\r\nConnection: close\r\n\r\n";
client.print(cmd);

int repeatCounter = 10;
while (!client.available() && repeatCounter--) {
delay(500);
}
String line,buf="";
int startJson=0;

while (client.connected() && client.available()) {
line = client.readStringUntil('\n');
if(line[0]=='{') startJson=1;
if(startJson)
{
for(int i=0;i<line.length();i++)
if(line=='[' || line==']') line=' ';
buf+=line+"\n";
}
}
client.stop();

DynamicJsonBuffer jsonBuf;
JsonObject &root = jsonBuf.parseObject(buf);
if (!root.success()) {
Serial.println("parseObject() failed");
delay(10);
return -1;
}

subscribers = root["items"]["statistics"]["subscriberCount"];
Serial.println(subscribers);
return subscribers;
}

void createCustomChars()
{
lcd.createChar(0,LT);
lcd.createChar(1,UB);
lcd.createChar(2,RT);
lcd.createChar(3,LL);
lcd.createChar(4,LB);
lcd.createChar(5,LR);
lcd.createChar(6,UMB);
lcd.createChar(7,LMB);
}

<end code>
By lyndon
#198491
They "needed to get paid" because you posted in the Gigs & Collaborations section which is primarily for paid assistance. People aren't being helpful over there because you're coming in with an attitude that's turning them off!

My suggestion would be to contact the original author of the project and ask him/her for help.
If that fails, understand that it's a complex project involving networking and expecting people to just jump in and fix the issues at no cost is asking a lot. Sure, you may get lucky and someone may help (we're a pretty friendly bunch on this site), but if you start bitching that no one wants to help you for free, don't be surprised at the reaction.