SD.h and SoftwareSerial compatibility issue

I was trying to program an ESP8266 which will send data on ThingSpeak and also save the data sent to an SD card. But after
some trials I always get error in AT command. But I first start the Wifi.begin next with the wifi_init(); I get an OK.

I am confused, that this has to be a problem with the library of SD.h and SoftwareSerial.h. I am a newbie in arduino. I dont even know anything about Libraries

the code below is what I used.

SD_esp.ino (3.8 KB)

Leave out the Arduino. Program the ESP directly. It has on-board flash memory of up to 4MB. Plenty of space for saving sensor data etc. It's also much faster than most Arduinos, and it has many times more RAM.
Using AT commands is extremely cumbersome, and SoftwareSerial is a hack.

If you really do need the Arduino to read your sensors, use it as a slave to the ESP8266, not the other way around. You could use I²C or SPI instead of SoftwareSerial.

A Beginner's Guide to the ESP8266

Pieter

This line

SoftwareSerial client(51,53);

suggests you are using an Arduino Mega.

Two questions ....
{1} With all the available pins on a Mega how did you manage to choose the SPI pins for SoftwareSerial?
{2} With 3 spare HardwareSerial ports on a Mega, why are you using SoftwareSerial at all?

...R

Robin2:
This line

SoftwareSerial client(51,53);

suggests you are using an Arduino Mega.

Two questions ....
{1} With all the available pins on a Mega how did you manage to choose the SPI pins for SoftwareSerial?
{2} With 3 spare HardwareSerial ports on a Mega, why are you using SoftwareSerial at all?

...R

Yep, I am using Mega.

For your first question, I am planning to use OPEN SMART tft Screen which ocuppies the pin 0 to 13 and the analogs,. which the left softserial pins are 51,52,53,and 54.
Second question, Is it possible to use those HardwareSerial ports for sending AT commands from arduino?, As what I read It is only used for pc to arduino communication. if its possible could it solve the problem in SD library?

PieterP:
Leave out the Arduino. Program the ESP directly. It has on-board flash memory of up to 4MB. Plenty of space for saving sensor data etc. It's also much faster than most Arduinos, and it has many times more RAM.
Using AT commands is extremely cumbersome, and SoftwareSerial is a hack.

If you really do need the Arduino to read your sensors, use it as a slave to the ESP8266, not the other way around. You could use I²C or SPI instead of SoftwareSerial.

A Beginner's Guide to the ESP8266

Pieter

Hello Pieter, Thanks for the Advise, I will read those link you gave. I think its a great idea to used arduino as a slave. So ther is a really problem with SD library and SoftwareSerial?

kernel23:
So ther is a really problem with SD library and SoftwareSerial?

No, but since the SD Library uses the SPI pins, you cannot use those SPI pins for SoftwareSerial at the same time.

srnet:
No, but since the SD Library uses the SPI pins, you cannot use those SPI pins for SoftwareSerial at the same time.

Thanks for the answer! it solves the problem. since I am using arduino mega, the SPI pins are 51,52,53, and 54. Which I used for Software Serial connection. Thank you for the advice. Now, I change the pin to A13, and A12. SD and ESP are now functioning at the same time.

kernel23:
Thanks for the answer! it solves the problem. since I am using arduino mega, the SPI pins are 51,52,53, and 54. Which I used for Software Serial connection. Thank you for the advice. Now, I change the pin to A13, and A12. SD and ESP are now functioning at the same time.

Best advice is to check the pinout diagrams when allocating pins in a project.