Hello all,
i’ve been searching all weekend and have struggled to find the cause (and solution) to a problem I am having converting my code for use with Blynk.
I am using an Arduino Uno and ESP12 module for the wifi connectivity to a local server, I am having no issues with the wifi connection itconnects every time.
Please see my code prior to alterations for Blynk usage
#include <LiquidCrystal_I2C.h>
const int xpin = A1; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A3; // z-axis (only on 3-axis models)
int sampleDelay = 20; //number of milliseconds between readings
LiquidCrystal_I2C lcd(0x27, 2, 1, 0 ,4 ,5 ,6 ,7 ,3, POSITIVE); // Set the LCD I2C address;
void setup()
{
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0, 0); // Sets the cursor to col 0 and row 0
lcd.print("X:");
lcd.setCursor(0, 1); // Sets the cursor to col 0 and row 1
lcd.print("Y:");
lcd.setCursor(8, 0); // Sets the cursor to col 8 and row 0
lcd.print("Z:");
analogReference(EXTERNAL);
pinMode(xpin, INPUT);
pinMode(ypin, INPUT);
pinMode(zpin, INPUT);
Serial.begin(9600);
}
void loop()
{
Serial.print(analogRead(xpin));
Serial.print(",");
Serial.print(analogRead(ypin));
Serial.print(",");
Serial.println(analogRead(zpin));
lcd.setCursor(3, 0); // Sets the cursor to col 0 and row 0
lcd.print(analogRead(xpin));
lcd.setCursor(3, 1); // Sets the cursor to col 0 and row 1
lcd.print(analogRead(ypin));
lcd.setCursor(10, 0); // Sets the cursor to col 8 and row 0
lcd.print(analogRead(zpin));
}
The purpose of the sketch is to read the feedback from a 3 Axis accelerometer and the value of each axis is subsequently printed to the serial monitor and a OLED display .
Here is my code reformatted for use with Blynk.
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <ESP8266_Lib.h>
#define BLYNK_PRINT Serial
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = "bleh";
char ssid[] = "bleh";
char pass[] = "bleh";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(8, 9); // RX, TX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
const int xpin = A1; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A3; // z-axis (only on 3-axis models)
//LiquidCrystal_I2C lcd(0x27, 2, 1, 0 ,4 ,5 ,6 ,7 ,3, POSITIVE); // Set the LCD I2C address;
BlynkTimer timer;
void setup()
{
// lcd.begin(16,2);
// lcd.clear();
// lcd.setCursor(0, 0); // Sets the cursor to col 0 and row 0
// lcd.print("X:");
// lcd.setCursor(0, 1); // Sets the cursor to col 0 and row 1
// lcd.print("Y:");
// lcd.setCursor(8, 0); // Sets the cursor to col 8 and row 0
// lcd.print("Z:");
analogReference(EXTERNAL);
pinMode(xpin, INPUT);
pinMode(ypin, INPUT);
pinMode(zpin, INPUT);
Serial.begin(9600);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass, "10.1.1.244", 8080);
timer.setInterval(20L, serialmonitor);
//timer.setInterval(450l, superchart);
}
void serialmonitor()
{
Serial.print(analogRead(xpin));
Serial.print(",");
Serial.print(analogRead(ypin));
Serial.print(",");
Serial.println(analogRead(zpin));
//lcd.setCursor(3, 0); // Sets the cursor to col 0 and row 0
// lcd.print(analogRead(xpin));
// lcd.setCursor(3, 1); // Sets the cursor to col 0 and row 1
//lcd.print(analogRead(ypin));
//lcd.setCursor(10, 0); // Sets the cursor to col 8 and row 0
// lcd.print(analogRead(zpin));
}
void superchart()
{
Blynk.virtualWrite(V5, analogRead(xpin));
Blynk.virtualWrite(V6, analogRead(ypin));
Blynk.virtualWrite(V7, analogRead(zpin));
}
void loop()
{
Blynk.run();
timer.run();
}
I am now finding myself with two problems:
-
Using the liquidcrystal_I2C library causes everything to freeze once I connect to the server, on the serial monitor I can see I connect, the ping is reported (Ready) but the serialmonitor code does not run and I am disconnected in the app. If I don’t use this library then as soon as I connect values are immediately printed to the serial monitor.
-
As soon as I activate the ‘superchart’ timer to virtualwrite analogread values to virtual pins the program slows down to a crawl. The serial monitor slows down to printing approximately 1 or 2 times a second (according to timestamps).
Now I assume I am doing something incorrect here causing the problem but after lots of searching all weekend I can’t figure it out. I have tried assigning each virtualwrite to its own timer but that made no real difference apart from the fact I could see the serial monitor response getting slower each timer another virtualwrite was taking place.
Thanks in advance for any assistance and patience.