ESP8266 and SD card reader problem

Hello to all.

i have one small problem,and im too tired to think now so sorry if its stupid but im obviously missing something.

I am working on a small weather station,well its 90% finished,and i thought i should leave the SD part for the end because its the easiest thing to do..BUT! :smiley: i was wrong.

This is the problem..i am using arduino pro mini,esp8266 and one of those sd card readers,standard thing,miso mosi clock and chip select,nothing unusual.

and the problem is : esp and SD wont work together!

ESP works perfectly when SD is not initialized.
SD works perfectly when ESP is not initialized.

so i was thinking..surely it must be some SPI problems,but i cant see the problem.

ESP is using 8,9 pins as rx,tx.
SD is SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK) as described in documentation.

and they just wont work together :smiley: if someone has some ideas please i would be very thankful because my brain is stuck :smiley:

I think that code is not actually important here its usual code like in examples..

So..once more for the end :smiley: EVERY example for the SD works perfectly :smiley:
ESP is working perfectly too.

but combined together is a big fail! :smiley:

Add more current ? I guess USB feed is not enough .. or the 3v3 regulator cannot feed both cards.

hmm,power supply is pretty strong and stable,but you see..i should check on that! :smiley:

see this video: ESP8266 - Getting Started & Connected. - YouTube

i saw every single video online about esp,and once again :smiley: esp is working perfectly :smiley: like a web server,everything is fine,you connect to it,data shows..requests,at commands..its just working as its supposed to :smiley: but..when i initialize the SD card reader,then esp stops sending data..and sd is not working aswell.

so..sd reader alone works fine,but when i initialize SD card reader in setup..then all stops.

and everything is powered from one 4.2 V 2600mah battery,then pull down to exactly 3.3V

and there is not so much components in my circuit

1.dht
1.bmp180
1.esp

  1. SD
    1.RTC

thats it :smiley:

i just cant figure it out :smiley:

Which hardware exactly ? How connected ? code ?

Arduino pro mini + esp8266 + sd adapter.

i didnt make the hardware,my father did,thats his job professionally,but thats not important because i told him to how to connect and his job was to make me a descent power supply for all that.

so esp is connected to rx-9 tx-8 and two pins are on vcc and one is on ground as its supposed to.

and the sd adapter is using arduinos miso mosi pins i cant remember now but i know they are standard and they are working :smiley:

so hardware is nothing unusual and its easy :smiley:

and the code is working too,just i cant initialize both esp and card reader

I understand you won't let us see what you have..

Problem is likely to be that both cards are enabled at the same time. Others have experienced this problem and done som tricks.
see this one Problem using both SPI library and SD library in Arduino UNO program - Networking, Protocols, and Devices - Arduino Forum #5

oh no :smiley: sorry,i will post the code dont worry about that,its just that i commented everything in Serbian so i need some time to Translate the comments,im not hiding the code,come on :smiley: its a mix of examples :smiley: no new coding solutions :smiley: im just a little short on time so i dont manage to work everything in time :smiley:

#include <SoftwareSerial.h>
SoftwareSerial esp8266(9, 8); //esp rx tx pins
#define DEBUG true
#include <SFE_BMP180.h>
#include <Wire.h>
#include <dht11.h>
#include <OneWire.h>
#include <SPI.h>
dht11 DHT11;
SFE_BMP180 pressure;
#include "RTClib.h"
RTC_DS1307 rtc;
#include <SD.h>
#define ALTITUDE 80.0
double priti = 0;
const int zelena = 3;
const int zuta = 4;
const int crvena = 5;
int baterija = A0;
float vredbat;
double p = 0;
double T, P;
String vremeString = "";
const int chipSelect = 10; //sd card chip select pin
File myFile;
void setup() {
  SPI.begin;
  Serial.begin(9600);
  rtc.begin();
  //rtc.adjust(DateTime(__DATE__, __TIME__));
  pinMode (baterija, INPUT);
  pinMode(zelena, OUTPUT);
  pinMode(zuta, OUTPUT);
  pinMode(crvena, OUTPUT);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  Serial.begin(9600);
  esp8266.begin(9600);
  DHT11.attach(2);
  //---------------------------------------------------------------preassure sensor initialization
  if (pressure.begin())
    Serial.println("BMP180 senzor spreman,DHT spreman");
  else
  {
    Serial.println("BMP180 inicijalizacija neuspela");
    while (1);
  }
  //--------------------------------------------------------------esp8266 at commands
  sendData("AT+RST\r\n", 2000, DEBUG);
  blinkzelena();
  sendData("AT+CWMODE=3\r\n", 1000, DEBUG);
  blinkzelena();
  sendData("AT+CIPMUX=1\r\n", 1000, DEBUG);
  blinkzelena();
  sendData("AT+CIPSERVER=1,80\r\n", 1000, DEBUG);
  blinkzelena();
  sendData("AT+CIFSR\r\n", 1000, DEBUG);
  blinkzelena();
  Serial.println("WIFI SPREMAN,cekam konekciju");
  blink();
  //------------------------------------------------------------------------------------sd initialization

 Serial.print("Initializing SD card...");
  pinMode(SS, OUTPUT);
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    while (1) ;
  }
  Serial.println("card initialized.");
  myFile = SD.open("datalog.txt", FILE_WRITE);
  if (! myFile) {
    Serial.println("error opening datalog.txt");

    while (1) ;
  }
  //---------------------------------------------------------------------------------------------
}



void loop() {
  int chk = DHT11.read();
  float h = DHT11.humidity;
  vredbat = analogRead (baterija);
  vredbat = map (vredbat, 0, 625, 0, 100);
  int bat = vredbat;
  float x = bat;


  if (esp8266.available()) //
  {
    if (esp8266.find("+IPD,"))
    {

      digitalWrite(crvena, LOW);
      realtime();
      senzori();
      String webpage = "<head><meta http-equiv=""refresh"" content=""10""></head>";
      webpage += "<h1>Status baterije (%) </h1><h2>";
      webpage += x;
      webpage += "</h2>";
      webpage += "<h1>Vlaznost (%) </h1><h2>";
      webpage += h;
      webpage += "</h2>";
      webpage += "<h1>Vazdusni pritisak (Hpa) </h1><h2>";
      webpage += P;
      webpage += "</h2>";
      webpage += "<h1>Temperatura (T)</h1><h2>";
      webpage += T;
      String cipSend = "AT+CIPSEND=0";
      cipSend += ",";
      cipSend += webpage.length();
      cipSend += "\r\n";
      sendData(cipSend, 1000, DEBUG);
      sendData(webpage, 1000, DEBUG);
      digitalWrite(3, LOW);
      delay(2000);
      digitalWrite(3, HIGH);
      sendData("AT+CIPCLOSE=0\r\n", 1000, DEBUG);
      digitalWrite(crvena, HIGH);

    }
  }
}

String sendData(String command, const int timeout, boolean debug)
{
  String response = "";
  esp8266.print(command);
  long int time = millis();
  while ( (time + timeout) > millis())
  {
    while (esp8266.available())
    {
      char c = esp8266.read();
      response += c;
    }
  }

  if (debug)
  {
    Serial.print(response);
  }
  return response;
}

void blink() {
  digitalWrite(zelena, LOW);
  digitalWrite(zuta, HIGH);
  digitalWrite(crvena, HIGH);
  delay(100);
  digitalWrite(zelena, HIGH);
  digitalWrite(zuta, LOW);
  digitalWrite(crvena, HIGH);
  delay(100);
  digitalWrite(zelena, HIGH);
  digitalWrite(zuta, HIGH);
  digitalWrite(crvena, LOW);
  delay(100);
  digitalWrite(zelena, HIGH);
  digitalWrite(zuta, LOW);
  digitalWrite(crvena, HIGH);
  delay(100);
  digitalWrite(zelena, LOW);
  digitalWrite(zuta, HIGH);
  digitalWrite(crvena, HIGH);
  delay(100);
  digitalWrite(zelena, LOW);
  digitalWrite(zuta, HIGH);
  digitalWrite(crvena, HIGH);
  delay(100);
  digitalWrite(zelena, HIGH);
  digitalWrite(zuta, LOW);
  digitalWrite(crvena, HIGH);
  delay(100);
  digitalWrite(zelena, HIGH);
  digitalWrite(zuta, HIGH);
  digitalWrite(crvena, LOW);
  delay(100);
  digitalWrite(zelena, HIGH);
  digitalWrite(zuta, LOW);
  digitalWrite(crvena, HIGH);
  delay(100);
  digitalWrite(zelena, LOW);
  digitalWrite(zuta, HIGH);
  digitalWrite(crvena, HIGH);
  delay(100);
  digitalWrite(zelena, LOW);
  digitalWrite(zuta, LOW);
  digitalWrite(crvena, LOW);
  delay(100);
  digitalWrite(zelena, HIGH);
  digitalWrite(zuta, HIGH);
  digitalWrite(crvena, HIGH);
  delay(100);
  digitalWrite(zelena, LOW);
  digitalWrite(zuta, LOW);
  digitalWrite(crvena, LOW);
  delay(100);
  digitalWrite(zelena, HIGH);
  digitalWrite(zuta, HIGH);
  digitalWrite(crvena, HIGH);
  delay(100);
  digitalWrite(zelena, LOW);
  digitalWrite(zuta, LOW);
  digitalWrite(crvena, LOW);
  delay(100);
  digitalWrite(zelena, HIGH);
  digitalWrite(zuta, HIGH);
  digitalWrite(crvena, HIGH);
  delay(100);
  digitalWrite(zelena, HIGH);
  digitalWrite(zuta, HIGH);
  digitalWrite(crvena, HIGH);

}

void blinkzelena() {

  digitalWrite(zelena, LOW);
  delay(200);
  digitalWrite(zelena, HIGH);
  delay(200);
}

void senzori () {

  String dataString = "";
  char status;

  status = pressure.startTemperature();
  if (status != 0)
  {
    delay(status);
  }
  status = pressure.getTemperature(T);
  if (status != 0)
  {

  }
  status = pressure.startPressure(3);
  if (status != 0)
  {
    delay(status);
  }
  status = pressure.getPressure(P, T);
  if (status != 0)
  {

    priti = (P);

  }




}

void realtime() {

  DateTime now = rtc.now();

  vremeString += String(now.year(), DEC);
  vremeString += "/";
  vremeString += String(now.month(), DEC);
  vremeString += "/";
  vremeString += String(now.day(), DEC);
  vremeString += " ";
  vremeString += String(now.hour(), DEC);
  vremeString += ":";
  vremeString += String(now.minute(), DEC);
  vremeString += ":";
  vremeString += String(now.second(), DEC);
  vremeString += " ";


}


void logger() {
  String dataString = "";
  // myFile = SD.open("Datalog.txt",FILE_WRITE);
  dataString += vremeString;
  dataString += " ";
  dataString += String(T);
  dataString += "c";
  dataString += " ";
  dataString += String(DHT11.humidity, DEC);
  dataString += "%";
  dataString += " ";
  dataString += String(P);
  dataString += "Hpa";
  //  dataString += String(x);
  //dataString += "%";

  //  myFile.println(dataString);
  Serial.println(dataString);

}

so the problem is when i put the SD INITIALIZATION PART,wifi stops :smiley: and sorry once more,my code is all around the place at the moment until i make sure everything works fine,and my organizing skills are pretty low :smiley:

can it be a memory problem? this code have as you can see all kinds of led blink stuff,but its just for debuging purposes at the moment,because device is outside,so i can see when i connect to it and when its sending data..later ill delete all of it :smiley:

hmm ok..i think i found a problem,and my problem literally exploded :smiley:

one of the power supply components decided to spontaneously goes to smoke,cheap stuff.

and it blew up at the exact same time when wireless part and sd card started working..so i assume when it started to pull more current my component didnt survive :smiley: i love this kind of problems :smiley:

..as I said.. Too much curreent...