Dears , would you plz help me…
When I enter this code ‘’ Blynk.begin(auth, ssid, pass); ‘’ , the display turns off.
This is while before I enter this statement, the code works correctly. Of course, Blynk does not work!!
I use the SPI OLED 0.96 and DHT11 in my code.
This is my code:
Blockquote
#define BLYNK_TEMPLATE_ID "******************"
#define BLYNK_DEVICE_NAME "Quickstart Device"
#define BLYNK_AUTH_TOKEN "*********************"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//This section should be modified according to your display type and library
#define setpixel(x, y, color) display.writePixel(x, y, color)
#define LCDWidth display.width()
#define ALIGN_CENTER(t) (LCDWidth - ((LCDWidth - (LCDWidth - CalcTextWidth(t))) / 2)) - 2
#define ALIGN_RIGHT LCDWidth - 3
#define ALIGN_LEFT(t) LCDWidth - CalcTextWidth(t)
#define OLED_MOSI 13 //Connect to D1 on OLED
#define OLED_CLK 14 //Connect to D0 on OLED
#define OLED_DC 5 //Connect to DC on OLED
#define OLED_CS 15 //Connect to CS on OLED
#define OLED_RESET 0 //Connect to RES on OLED
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
#include "DHT.h"
#define DHTTYPE DHT11
DHT dht(10, DHT11); // DHT instance named dhtA, D4 and sensor type
uint8_t DHTPin = 10;
float Temperature;
float Humidity;
float Temp_Fahrenheit;
char ssid[] = "***";
char pass[] = "*****";
uint8_t sensorPin = A0;
//int sensor = A0; // select the input pin for the potentiometer
int sensor = 0; // random(0,100);
int sensorValue = 0; // variable to store the value coming from the sensor
int counter = 0; // Seconds counter
unsigned long int currentTime,nextTime;
//8x8 Persian Letters
//This is the font definition. You can use http://gurgleapps.com/tools/matrix to create your own font.
const unsigned char PeChar[71][8] PROGMEM = {
0x00, 0x1C, 0x20, 0x08, 0x08, 0x08, 0x08, 0x00, //0 alef1
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, //1 alef2
0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, //2 alef3
0x00, 0x00, 0x00, 0x01, 0x01, 0x06, 0x00, 0x02, //3 be1
0x00, 0x00, 0x40, 0x81, 0x81, 0x7E, 0x00, 0x10, //4 be2
0x00, 0x00, 0x00, 0x01, 0x01, 0x06, 0x00, 0x07, //5 pe1
0x00, 0x00, 0x40, 0x81, 0x81, 0x7E, 0x00, 0x38, //6 pe2
0x00, 0x03, 0x00, 0x01, 0x01, 0x06, 0x00, 0x00, //7 te1
0x00, 0x14, 0x40, 0x81, 0x81, 0x7E, 0x00, 0x00, //8 te2
0x02, 0x05, 0x00, 0x01, 0x01, 0x06, 0x00, 0x00, //9 the1
0x08, 0x14, 0x40, 0x81, 0x81, 0x7E, 0x00, 0x00, //10 the2
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x00, 0x04, //11 jim1
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x40, 0x3A, //12 jim2
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x00, 0x1C, //13 che1
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x40, 0x37, //14 che2
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x00, 0x00, //15 hee1
0x00, 0x00, 0x0C, 0x12, 0x01, 0x3E, 0x40, 0x38, //16 hee2
0x00, 0x20, 0x0C, 0x12, 0x01, 0x3E, 0x00, 0x00, //17 khe1
0x00, 0x20, 0x0C, 0x12, 0x01, 0x3E, 0x40, 0x38, //18 khe2
0x00, 0x00, 0x04, 0x02, 0x01, 0x12, 0x0C, 0x00, //19 dal
0x00, 0x10, 0x04, 0x02, 0x01, 0x12, 0x0C, 0x00, //20 zal
0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x0C, //21 re
0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x02, 0x0C, //22 ze
0x02, 0x05, 0x00, 0x01, 0x01, 0x01, 0x02, 0x0C, //23 zhe
0x00, 0x00, 0x00, 0x15, 0x15, 0x6A, 0x00, 0x00, //24 sin1
0x00, 0x00, 0x00, 0x15, 0x95, 0x9A, 0x90, 0x60, //25 sin2
0x04, 0x0A, 0x00, 0x15, 0x15, 0x6A, 0x00, 0x00, //26 shin1
0x04, 0x0A, 0x00, 0x15, 0x95, 0x9A, 0x90, 0x60, //27 shin2
0x00, 0x00, 0x06, 0x29, 0x31, 0x5E, 0x00, 0x00, //28 sad1
0x00, 0x00, 0x06, 0x49, 0x91, 0x9E, 0x90, 0x60, //29 sad2
0x00, 0x10, 0x06, 0x29, 0x31, 0x5E, 0x00, 0x00, //30 zad1
0x00, 0x10, 0x06, 0x49, 0x91, 0x9E, 0x90, 0x60, //31 zad2
0x00, 0x20, 0x26, 0x29, 0x31, 0x7E, 0x00, 0x00, //32 taa
0x00, 0x28, 0x26, 0x29, 0x31, 0x7E, 0x00, 0x00, //33 zaa
0x00, 0x00, 0x03, 0x04, 0x04, 0x0F, 0x00, 0x00, //34 ein1
0x00, 0x00, 0x1E, 0x22, 0x1C, 0x77, 0x00, 0x00, //35 ein2
0x00, 0x1E, 0x22, 0x1C, 0x24, 0x23, 0x20, 0x1C, //36 ein3
0x00, 0x03, 0x04, 0x04, 0x0F, 0x10, 0x10, 0x0F, //37 ein4
0x00, 0x08, 0x03, 0x04, 0x04, 0x0F, 0x00, 0x00, //38 qein1
0x08, 0x00, 0x1E, 0x22, 0x1C, 0x77, 0x00, 0x00, //39 qein2
0x40, 0x1E, 0x22, 0x1C, 0x24, 0x23, 0x20, 0x1C, //40 qein3
0x08, 0x03, 0x04, 0x04, 0x0F, 0x10, 0x10, 0x0F, //41 qein4
0x04, 0x00, 0x06, 0x09, 0x09, 0x1E, 0x00, 0x00, //42 fe1
0x04, 0x00, 0x06, 0x89, 0x89, 0x7E, 0x00, 0x00, //43 fe2
0x06, 0x00, 0x06, 0x09, 0x09, 0x1E, 0x00, 0x00, //44 qaf1
0x06, 0x00, 0x06, 0x09, 0x49, 0x47, 0x41, 0x3E, //45 qaf2
0x00, 0x0F, 0x10, 0x1E, 0x01, 0x3E, 0x00, 0x00, //46 kaf1
0x00, 0x07, 0x08, 0x8E, 0x81, 0x7E, 0x00, 0x00, //47 kaf2
0x07, 0x0F, 0x10, 0x1E, 0x01, 0x3E, 0x00, 0x00, //48 gaf1
0x07, 0x0F, 0x10, 0x9E, 0x81, 0x7E, 0x00, 0x00, //49 gaf2
0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00, //50 lam1
0x00, 0x01, 0x01, 0x11, 0x21, 0x22, 0x1C, 0x00, //51 lam2
0x00, 0x00, 0x06, 0x09, 0x09, 0x36, 0x00, 0x00, //52 mim1
0x00, 0x04, 0x0A, 0x19, 0x29, 0x46, 0x40, 0x20, //53 mim2
0x00, 0x02, 0x00, 0x01, 0x01, 0x06, 0x00, 0x00, //54 noon1
0x00, 0x00, 0x08, 0x21, 0x41, 0x41, 0x22, 0x1C, //55 noon2
0x00, 0x00, 0x06, 0x09, 0x09, 0x07, 0x01, 0x0E, //56 vaav
0x08, 0x04, 0x0A, 0x15, 0x09, 0x36, 0x00, 0x00, //57 he1
0x00, 0x00, 0x30, 0x48, 0x56, 0xE9, 0x50, 0x20, //58 he2
0x00, 0x07, 0x09, 0x09, 0x05, 0x00, 0x00, 0x00, //59 he3
0x00, 0x08, 0x04, 0x0A, 0x11, 0x11, 0x0E, 0x00, //60 he4
0x00, 0x00, 0x00, 0x01, 0x01, 0x06, 0x00, 0x06, //61 ye1
0x00, 0x00, 0x00, 0x4C, 0x92, 0x89, 0x84, 0x78, //62 ye2
0x00, 0x06, 0x29, 0x48, 0x46, 0x41, 0x21, 0x1E, //63 ye3
0x0C, 0x12, 0x10, 0x08, 0x04, 0x00, 0x04, 0x00, //64 soal
0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x00, //65 tajob
0x00, 0x00, 0x00, 0x04, 0x08, 0x0C, 0x0C, 0x00, //66 vir
0x10, 0x08, 0x04, 0x04, 0x04, 0x04, 0x08, 0x10, //67 kmn1
0x04, 0x08, 0x10, 0x10, 0x10, 0x10, 0x08, 0x04, //68 kmn2
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, //69 slash
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, //70 backslash
};
//Persian Numbers 8x8
const unsigned char num[10][8] PROGMEM = {
0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x06, 0x00, //0
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, //1
0x00, 0x09, 0x09, 0x0E, 0x08, 0x08, 0x08, 0x00, //2
0x00, 0x25, 0x25, 0x3A, 0x20, 0x20, 0x20, 0x00, //3
0x00, 0x03, 0x14, 0x14, 0x1F, 0x10, 0x10, 0x00, //4
0x00, 0x08, 0x04, 0x12, 0x21, 0x29, 0x16, 0x00, //5
0x00, 0x10, 0x21, 0x22, 0x1C, 0x08, 0x10, 0x00, //6
0x00, 0x11, 0x11, 0x0A, 0x0A, 0x04, 0x04, 0x00, //7
0x00, 0x04, 0x04, 0x0A, 0x0A, 0x11, 0x11, 0x00, //8
0x00, 0x06, 0x09, 0x09, 0x07, 0x01, 0x01, 0x00, //9
};
// Functions for right alignment of integers
int align2(int q){ // Space in 100s and 10s
if (q < 100) {display.print(" ");}
if (q < 10) {display.print(" ");}
}
int align3(int q){ // Space in 1000s
if (q < 1000) {display.print(" ");}
align2(q);
}
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
// Set incoming value from pin V0 to a variable
int value = param.asInt();
// Update state
Blynk.virtualWrite(V1, value);
}
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}
// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V2, millis() / 1000);
}
BlynkTimer timer;
void setup() {
Serial.begin(115200);
dht.begin();
display.begin(SSD1306_SWITCHCAPVCC);
pinMode(DHTPin, INPUT);
pinMode(sensorPin, INPUT);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(15, 8);
display.println("MyLOGO");
display.drawRoundRect(1, 1, 124, 30, 5, WHITE);
display.display();
delay(1000);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, sendsensor);
}
void sendsensor() {
climateRoutine(); // Climate routine
delay(100); // 4.7 sec between routines
Humidity = dht.readHumidity();
Temperature = dht.readTemperature();
Temp_Fahrenheit= dht.readTemperature(true);
if (isnan(Humidity) || isnan(Temperature) || isnan(Temp_Fahrenheit)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Clear the buffer.
display.clearDisplay();
char txt[] = "دما:";
display.setTextSize(2);
PutCharPE(txt,ALIGN_RIGHT+2 ,0,1,WHITE);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(69,1);
display.print(Temperature, true);
display.print(" ");
display.setTextSize(0.5);
display.setCursor(96,1);
display.cp437(true);
display.write(167);
display.setTextSize(0.5);
display.print("C");
char txt2[] = "رطوبت:";
display.setTextSize(2);
PutCharPE(txt2,ALIGN_LEFT(txt2)+30 ,0,1,WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.print(Humidity, true);
display.setCursor(25, 0);
display.print("%");
drawPercentbar( 0, 20, 70, 10,sensor);
sensor++;
if( sensor > 100) sensor =0;
display.display();
delay(100);
scrolltxt();
}
// ++++++++++++Main Loop ++++++++++++++
// 1 second timer
void loop() {
Blynk.run(); // Initiates Blynk
timer.run();
}
void scrolltxt()
{
delay(2000);
display.startscrollright(0x00, 0x00);
delay(2000);
}
void drawPercentbar(int x,int y, int width,int height, int progress)
{
progress = progress > 100 ? 100 : progress;
progress = progress < 0 ? 0 :progress;
float bar = ((float)(width-4) / 100) * progress;
display.drawRect(x, y, width, height, WHITE);
display.fillRect(x+2, y+2, bar , height-4, WHITE);
// Display progress text
display.setCursor((width/2) -10, y+2 );
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextColor(BLACK, WHITE); // 'inverted' text
display.print(progress);
display.print("%");
// Read pot and display values
sensorValue = analogRead(sensorPin); // read the value from the sensor
int perCent = float(sensorValue * 100.0/1018);
display.drawLine(0,47,0,62, SSD1306_WHITE);
display.fillRect(1, 50, perCent, 10, SSD1306_WHITE);
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(99,22); //percentage no.&% coordinate
align2(perCent);
display.print(perCent);
display.println("%");
display.fillRect(0, 20, 90, 10, SSD1306_BLACK); // Clear box//increase-decr as sensor
//display.setTextColor(BLACK, WHITE); // 'inverted' text
display.setTextColor(SSD1306_WHITE);
display.setCursor(20,21);
display.setTextSize(1);
//display.setCursor(100,50);
align3(sensorValue);
display.println(sensorValue);
delay(100);
display.fillRect(1, 20, perCent, 10, SSD1306_WHITE);
display.setTextColor(SSD1306_BLACK);
display.setCursor(90,50);
align2(perCent);
display.print(perCent);
display.println("%");
display.drawRect(0, 20, 90, 10, SSD1306_WHITE); // RAW pot value box محل و رنگ باکس ولوم
//nextTime = millis() + 1000; // 1 second in the future
//display.println(counter);
char txt6[] = "ی";
display.setTextSize(2);
PutCharPE(txt6,ALIGN_CENTER(txt6) ,9,1,WHITE);
if((sensorValue) < (500)) {
char txt7[] = "ب";
display.setTextSize(2);
PutCharPE(txt7,ALIGN_CENTER(txt7)-50 ,9,1,WHITE);
}
if((sensorValue) > (500)) {
char txt8[] = "س";
display.setTextSize(2);
PutCharPE(txt8,ALIGN_CENTER(txt8)+50 ,9,1,WHITE);
}
display.display();
}
void climateRoutine() {
byte h1 = dht.readHumidity(); // f1 and h1 are celsius and humidity readings
// byte t1 = dht.readTemperature(true); // for temperature in farenheits
byte t1 = dht.readTemperature(); // from DHT/A
// Set Virtual Pin 1 frequency to PUSH in Blynk app
}
//////////////////////////language setting part//////////////
char* strreverse(char* s)
{
char* beg = s-1, *end = s, tmp;
while (*++end);
while (end-- > ++beg)
{
tmp = *beg;
*beg = *end;
*end = tmp;
}
return s;
}
void drawBitmapPE(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color) {
if/els....
}