Hi to all. I’am experiencing a strange problem with my sketch and i need your help.
I want to add a i2c lcd diplay to my project but when I simply add Wire.h the connection with blynk fail with “Cmd error”
I searched in the forum but i didn’t find an answer to my problem.
Can someone help me ?
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
WARNING!
It's rather tricky to get it working, please read this article:
https://github.com/blynkkk/blynk-library/wiki/ESP8266-with-AT-firmware
You’ll need:
- Blynk App (download from AppStore or Google Play)
- Arduino Uno board
- Decide how to connect to Blynk
(USB, Ethernet, Wi-Fi, Bluetooth, ...)
There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#define BLYNK_GREEN "#23C48E"
#define BLYNK_BLUE "#04C0F8"
#define BLYNK_YELLOW "#ED9D00"
#define BLYNK_RED "#D3435C"
#define BLYNK_DARK_BLUE "#5F7CD8"
#define DHTPIN 7 // what digital pin we're connected to
#define DHTTYPE DHT11 // DHT 11
#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <PID_v1.h>
#include <CountUpDownTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "a77277448436405aa115303ec2ab1883";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "protected";
char pass[] = "nintendo";
// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
#include "DHT.h" // Including library for dht
SoftwareSerial EspSerial(9, 10); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
//Specify the links and initial tuning parameters
double Kp = 10, Ki = 1, Kd = 1;
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
double Humidity, Temperature;
int humSetpoint;
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
PID myPID(&Temperature, &Output, &Setpoint, Kp, Ki, Kd, AUTOMATIC);
//Timer management
CountUpDownTimer T(DOWN, LOW);
unsigned long Timer_Duration = 1200 ;//43200; // runtime in seconds
//LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line disp
void setup()
{
// Debug console
Serial.begin(9600);
// Set ESP8266 baud rate
// Set ESP8266 baud rate
EspSerial.begin(57600);
EspSerial.write ("AT+UART=9600,8,1,0,0\r\n");
EspSerial.begin(9600);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8442);
timer.setInterval(1000L, ReadAndCompute);
T.SetTimer( Timer_Duration);
T.StartTimer();
// lcd.init(); // initialize the lcd
// lcd.backlight();
//
}
void loop()
{
Blynk.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
BLYNK_CONNECTED() {
Blynk.virtualWrite(V0, 28);
Blynk.virtualWrite(V1, 75);
Blynk.virtualWrite(V11, (int)Kp);
Blynk.virtualWrite(V12, (int)Ki);
Blynk.virtualWrite(V13, (int)Kd);
// Blynk.virtualWrite(V7, (double)Timer_Duration / 60);
Blynk.setProperty(V9, F("color"), BLYNK_GREEN );
// Blynk.virtualWrite(V9, 0);
//
// UpdateTimer();
}
void ReadAndCompute()
{
Humidity = dht.readHumidity();
Temperature = dht.readTemperature();
//Serial.println(T.ShowTotalSeconds() );
//Serial.println(Timer_Duration);
myPID.Compute();
}