Arduino Nano Issues with SPI and I2C peripherals

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;
}

What makes you think your badly-posted code has a bootloader issue?

Thread moved.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Good Luck,
Red

What I'd do:

  • remove excess initialization in setup()
  • send update only if TDS changes

Eventually get rid of SoftwareSerial and use the display for debug messages.