Hello everyone
I have an issues regarding connecting Arduino Nano
I have a Nano and I have made a program to display a variable on OLED 0.96 inch.. also i want to upload the data to thingspeak using ESP8266 WiFi module, when ever i use both devices simultaneously, the oled and wifi freezes but they work alone just fine... is there any issue with my arduino or what?
code is given here
#include <Adafruit_GFX.h> // Include core graphics library for the display
#include <Adafruit_SSD1306.h> // Include Adafruit_SSD1306 library to drive the display
#include <SoftwareSerial.h>
//////////////wifi
#define RX 8
#define TX 7
String AP = "Abdullah"; // CHANGE ME
String PASS = "thankyou"; // CHANGE ME
String API = "D9LLQ1QSEKWMORK0"; // CHANGE ME
String HOST = "api.thingspeak.com";
String PORT = "80";
String field = "field1";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
int valSensor;
SoftwareSerial esp8266(RX,TX);
////////////////////////
int analogPin= 0;
int raw= 0;
int Vin= 5;
float Vout= 0;
float R1= 1000;
float R2= 0;
float buffer= 0;
float cond;
float TDS;
long cnt1=0,cnt2=0;
/////////////
void setup() // Start of setup
{
///////////////wifi'
Serial.begin(9600);
esp8266.begin(115200);
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=""+ AP +"",""+ PASS +""",20,"OK");
/////////////////////////////
///////////////wifi'
Serial.begin(9600);
esp8266.begin(115200);
/////////////////////////////
} // End of setup
void loop() // Start of loop
{
raw= analogRead(analogPin); if(raw)
{ buffer= raw * Vin;
Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
R2= R1 * buffer; cond=1/R2;
TDS=1500cond770;
}
//////////////////////wifi
String getData = "GET /update?api_key="+ API +"&"+ field +"="+String(TDS)+" \r\n";
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,"TCP",""+ HOST +"","+ PORT,20,"OK");
sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
esp8266.println(getData);delay(1000);countTrueCommand++;
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
//////////////////////////////////////////////////
/////////////////// for TDS sensor//////////////
/////////////////////////////////////////////////
} // End of loop
void sendCommand(String command, int maxTime, char readReplay[]) {
Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while(countTimeCommand < (maxTime*1))
{
esp8266.println(command);//at+cipsend
if(esp8266.find(readReplay))//ok
{
found = true;
break;
}
countTimeCommand++;
}
if(found == true)
{
Serial.println("OYI");
countTrueCommand++;
countTimeCommand = 0;
}
if(found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}