Hi,
I am a newbee to Ardiuno.
I have created a project with Ultrasonic sensor connected to Nano and data is transmitted using RF transmitter. On reciever side i have used a ESP8266 mini to get the data from RF reciever and send to Ardiuno UNO to display it in LCD(GUI Mode).Also i have coded Blynk in ESP8266. My problem is that the data is not getting updated in the LCD or uno RX LED is not flashig when ESP8266 is connected to WIFI. If i disconnects wifi after the short while of initial power on, the LCD gets updated/refreshed in every 10 seconds. I tried changing uno,nano,ESP8266 but no luck. i am using a 5v 2.5 AMP adapter for uno& ESP8266 . Even on 12v 1 AMP adapter I am experiencing same error. Needs advise what could be wrong
ESP8266mini code
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL2odH_TnAc"
#define BLYNK_TEMPLATE_NAME "Water Level"
#define BLYNK_AUTH_TOKEN "gfSCpuFg4n3GBYjrEYhjEeFmwJ2b4nQu"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <EEPROM.h>
#include <RCSwitch.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(D1,D2);
RCSwitch mySwitch = RCSwitch();
char auth[] = "gfSCpuFg4n3GBYjrEYhjEeFmwJ2b4nQu";
char ssid[] = "AndroidAP98D2";
char pass[] = "wdgo5814";
BlynkTimer timer;
float Tank_Hight,Tank_U_Hight;
int OldLevel;
int Distance;
float Level;
int Buzzer = D0;
int LED = D4;
long Time,UP_Time,Buzz_Time;
int i,Flag;
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
mySerial.println("Hello, world?");
EEPROM.begin(512);
delay(1000);
mySwitch.enableReceive(D5);
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
timer.setInterval(100L, Update_Data);
//Tank_Hight = EEPROM.read(100)*10;
Tank_Hight = analogRead(A0)/3;
//Tank_Hight = Tank_Hight;
Serial.print("Tank_Hight : "); Serial.println(Tank_Hight);
pinMode(LED,OUTPUT);
pinMode(Buzzer,OUTPUT);
}
void Update_Data() {
Blynk.virtualWrite(V4, Tank_Hight);
}
//BLYNK_WRITE(V2){ Tank_U_Hight = param.asInt(); Serial.println(Tank_Hight); }
//BLYNK_WRITE(V3){ EEPROM.write(100, Tank_U_Hight/10); EEPROM.commit(); Tank_Hight = EEPROM.read(100)*10; Serial.print("Hight Updated "); Serial.println(Tank_Hight); }
void loop() {
Tank_Hight = analogRead(A0)/30;
Tank_Hight = Tank_Hight*10;
if ( millis() - UP_Time>1000){
UP_Time = millis();
Serial.print("Tank_Hight : "); Serial.println(Tank_Hight);
}
Blynk.run();
timer.run();
Run();
}
void Run(){
if (mySwitch.available()) {
digitalWrite(LED,LOW);
int Rec = mySwitch.getReceivedValue();
Distance = Rec - 3000;
mySwitch.resetAvailable();
Serial.println(Distance);
Blynk.virtualWrite(V1, Distance);
calculate_Level();
digitalWrite(LED,HIGH);
if(Level>90 || Level<10){ if(i==0){ i=1; Buzz_Time=millis();}}
if(Level<85 && Level>15){ i=0; }
}
if(millis()-Buzz_Time<60000){ if(i==1) { Buzz();} else { digitalWrite(Buzzer,LOW); }}
else { digitalWrite(Buzzer,LOW);}
}
void Buzz(){
if(millis()-Time>100){
Time = millis();
Flag = !Flag;
digitalWrite(Buzzer,Flag);
}
}
void calculate_Level(){
//Tank_Hight = 200;
int h = Tank_Hight - Distance;
Level = h*100/( Tank_Hight-25 );
if (Level>100) { Level = 100; }
if (Level<0) { Level = 1; }
Serial.println(Level);
if(Level == OldLevel ){ OldLevel = Level; }
else { OldLevel = Level; mySerial.print(Level + 100);mySerial.println("#"); }
Blynk.virtualWrite(V0, Level);
}
Ardiuno uno code
#include <SPFD5408_Adafruit_GFX.h> // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
int Val;
long Sig_Time;
void setup(void) {
Serial.begin(9600);
progmemPrintln(PSTR("TFT LCD test"));
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif
tft.reset();
tft.begin(0x9341); // SDFP5408
tft.setRotation(0);
tft.fillScreen(BLACK);
//tft.fillRect(20, 20, 200, 160, RED);
tft.setRotation(1);
tft.fillRect(85, 85, 170, 35, RED);
tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(90, 90); tft.print("NO SIGNAL");
}
void loop(void) {
if ( millis()-Sig_Time > 30000){
tft.fillScreen(BLACK);
tft.fillRect(85, 85, 170, 35, RED);
tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(90, 90); tft.print("NO SIGNAL");
}
if(Serial.available()>0){
String Read = Serial.readStringUntil("#");
Serial.println(Read);
Val = Read.toInt();
Serial.println(Val);
if(Val>100){
Sig_Time = millis();
Val = Val-100;
tft.setRotation(0);
//tft.fillRect(85, 85, 170, 35, BLACK);
tft.fillScreen(BLACK);
//tft.fillScreen(BLACK);
tft.fillRect(20, 20, 210, 160, RED); //delay(1000);
tft.fillRect(25, 25, 210, 150, BLACK); //delay(3000);
//for ( int i =0; i<190; i++) { tft.fillRect(30, 30, i, 140, GREEN); } //delay(1);}
int lvl = Val*2;
if (Val<25) { tft.fillRect(30, 30, lvl, 140, RED); }
else if (Val<50) { tft.fillRect(30, 30, lvl, 140, YELLOW); }
else if (Val<75) { tft.fillRect(30, 30, lvl, 140, BLUE); }
else if (Val>=75){ tft.fillRect(30, 30, lvl, 140, GREEN); }
tft.setRotation(1);
tft.fillRect(200, 160, 100, 80, BLACK); tft.setTextColor(WHITE); tft.setTextSize(5); tft.setCursor(200, 160); tft.print(Val); tft.print("% ");
/*tft.fillRect(200, 160, 100, 80, BLACK);*/ tft.setTextColor(WHITE); tft.setTextSize(2.5); tft.setCursor(200, 40); tft.print("ECJ IOT");
/*tft.fillRect(200, 160, 100, 80, BLACK);*/ tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(200, 80); tft.print("WATER");
tft.setCursor(200,120); tft.print("LEVEL");
}
else {
tft.fillScreen(BLACK);
//if(Val==33){for ( int i=0; i<20; i++){ tft.drawCircle(200, 260, i, GREEN); }}
//if(Val==22){for ( int i=0; i<20; i++){ tft.drawCircle(200, 260, i, YELLOW); }}
if(Val==33){
tft.fillRect(85, 85, 170, 35, RED);
tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(90, 90); tft.print("NO-SIGNAL");
}
}
}
}
unsigned long testFillScreen() {
unsigned long start = micros();
tft.fillScreen(BLACK);
tft.fillScreen(RED);
tft.fillScreen(GREEN);
tft.fillScreen(BLUE);
tft.fillScreen(BLACK);
return micros() - start;
}
unsigned long testText() {
tft.fillScreen(BLACK);
unsigned long start = micros();
tft.setCursor(0, 0);
tft.setTextColor(WHITE); tft.setTextSize(1);
tft.println("Hello World!");
tft.setTextColor(YELLOW); tft.setTextSize(2);
tft.println(1234.56);
tft.setTextColor(RED); tft.setTextSize(3);
tft.println(0xDEADBEEF, HEX);
tft.println();
tft.setTextColor(GREEN);
tft.setTextSize(5);
tft.println("Groop");
tft.setTextSize(2);
tft.println("I implore thee,");
tft.setTextSize(1);
tft.println("my foonting turlingdromes.");
tft.println("And hooptiously drangle me");
tft.println("with crinkly bindlewurdles,");
tft.println("Or I will rend thee");
tft.println("in the gobberwarts");
tft.println("with my blurglecruncheon,");
tft.println("see if I don't!");
return micros() - start;
}
unsigned long testLines(uint16_t color) {
unsigned long start, t;
int x1, y1, x2, y2,
w = tft.width(),
h = tft.height();
tft.fillScreen(BLACK);
x1 = y1 = 0;
y2 = h - 1;
start = micros();
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
x2 = w - 1;
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
t = micros() - start; // fillScreen doesn't count against timing
tft.fillScreen(BLACK);
x1 = w - 1;
y1 = 0;
y2 = h - 1;
start = micros();
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
x2 = 0;
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
t += micros() - start;
tft.fillScreen(BLACK);
x1 = 0;
y1 = h - 1;
y2 = 0;
start = micros();
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
x2 = w - 1;
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
t += micros() - start;
tft.fillScreen(BLACK);
x1 = w - 1;
y1 = h - 1;
y2 = 0;
start = micros();
for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
x2 = 0;
for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
return micros() - start;
}
unsigned long testFastLines(uint16_t color1, uint16_t color2) {
unsigned long start;
int x, y, w = tft.width(), h = tft.height();
tft.fillScreen(BLACK);
start = micros();
for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
//for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
//tft.drawFastHLine(0, y, w, color1);
return micros() - start;
}
unsigned long testRects(uint16_t color) {
unsigned long start;
int n, i, i2,
cx = tft.width() / 2,
cy = tft.height() / 2;
tft.fillScreen(BLACK);
n = min(tft.width(), tft.height());
start = micros();
for(i=2; i<n; i+=6) {
i2 = i / 2;
tft.drawRect(cx-i2, cy-i2, i, i, color);
}
return micros() - start;
}
unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
unsigned long start, t = 0;
int n, i, i2,
cx = tft.width() / 2 - 1,
cy = tft.height() / 2 - 1;
tft.fillScreen(BLACK);
n = min(tft.width(), tft.height());
for(i=n; i>0; i-=6) {
i2 = i / 2;
start = micros();
tft.fillRect(cx-i2, cy-i2, i, i, color1);
t += micros() - start;
// Outlines are not included in timing results
tft.drawRect(cx-i2, cy-i2, i, i, color2);
}
return t;
}
unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
unsigned long start;
int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
tft.fillScreen(BLACK);
start = micros();
for(x=radius; x<w; x+=r2) {
for(y=radius; y<h; y+=r2) {
tft.fillCircle(x, y, radius, color);
}
}
return micros() - start;
}
unsigned long testCircles(uint8_t radius, uint16_t color) {
unsigned long start;
int x, y, r2 = radius * 2,
w = tft.width() + radius,
h = tft.height() + radius;
// Screen is not cleared for this one -- this is
// intentional and does not affect the reported time.
start = micros();
for(x=0; x<w; x+=r2) {
for(y=0; y<h; y+=r2) {
tft.drawCircle(x, y, radius, color);
}
}
return micros() - start;
}
unsigned long testTriangles() {
unsigned long start;
int n, i, cx = tft.width() / 2 - 1,
cy = tft.height() / 2 - 1;
tft.fillScreen(BLACK);
n = min(cx, cy);
start = micros();
for(i=0; i<n; i+=5) {
tft.drawTriangle(
cx , cy - i, // peak
cx - i, cy + i, // bottom left
cx + i, cy + i, // bottom right
tft.color565(0, 0, i));
}
return micros() - start;
}
unsigned long testFilledTriangles() {
unsigned long start, t = 0;
int i, cx = tft.width() / 2 - 1,
cy = tft.height() / 2 - 1;
tft.fillScreen(BLACK);
start = micros();
for(i=min(cx,cy); i>10; i-=5) {
start = micros();
tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
tft.color565(0, i, i));
t += micros() - start;
tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
tft.color565(i, i, 0));
}
return t;
}
unsigned long testRoundRects() {
unsigned long start;
int w, i, i2,
cx = tft.width() / 2 - 1,
cy = tft.height() / 2 - 1;
tft.fillScreen(BLACK);
w = min(tft.width(), tft.height());
start = micros();
for(i=0; i<w; i+=6) {
i2 = i / 2;
tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
}
return micros() - start;
}
unsigned long testFilledRoundRects() {
unsigned long start;
int i, i2,
cx = tft.width() / 2 - 1,
cy = tft.height() / 2 - 1;
tft.fillScreen(BLACK);
start = micros();
for(i=min(tft.width(), tft.height()); i>20; i-=6) {
i2 = i / 2;
tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
}
return micros() - start;
}
// Copy string from flash to serial port
// Source string MUST be inside a PSTR() declaration!
void progmemPrint(const char *str) {
char c;
while(c = pgm_read_byte(str++)) Serial.print(c);
}
// Same as above, with trailing newline
void progmemPrintln(const char *str) {
progmemPrint(str);
Serial.println();
}
Thanks in Advance
