Dear Sir,
I successfully done the project with ESP32, given on your following link
https://randomnerdtutorials.com/esp32-data-logging-temperature-to-microsd-card/
I want to do the same project with ESP 8266.
What are the changes required to be done in Circuit diagram and in the sketch.
Preferably I want to us a common sketch for both ESP 32 and ESP8266.
Please guide me
Hi.
In terms of code, this is the same:
- getting date and time;
- getting temperature from DS18B20 temperature sensor;
- the SD.h library is supported by both boards
You should include <ESP8266WiFi.h> instead of just WiFi.h.
I’m not sure if the FS.h library is supported by the ESP8266. I haven’t tried it.
In case it is not supported, you write to the SD card as shown in this example:
File dataFile = SD.open("datalog.txt", FILE_WRITE); // if the file is available, write to it:
if (dataFile) {
dataFile.println(DATA_YOU_WANT_TO_SAVE);
dataFile.close();
}
I haven’t experimented this on the ESP8266 or on the ESP32, so I’m not sure if you need any other modifications.
If both boards can write to the SD card using just the SD library, you can probably use the same code for both boards.
You just need to add a condition to load the WiFi or ESP8266 WiFi library depending on the board selected, for example:
#ifdef ESP32
#include <WiFi.h>
#if def ESP8266
#include<ESP8266WiFi.h>
You can use any pin for the DS18B20.
The microSD card uses SPI, so you need to connect it to the ESP8266 SPI pins:
- GPIO12: MISO
- GPIO13: MOSI
- GPIO14: SCLK
- GPIO15: CS
Additionally, you can check the ESP8266 GPIO Guide: https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
I hope this helps.
Let me know if you need further help.
Regards,
Sara
Ms. Sara Madam,
Thank you very much for your prompt response. I tried out with the suggestions given by you. But there were were a lot of issues as below –
1. Perhaps “FS.h” is not working with ESP8266 “error compiling for board nodemcu 1.0 (esp-12e module)”
Madam, since last 8 days I am struggling to make this program workable for both ESP32 and ESP8266, but every time some or the other problem is coming and it is becoming workable either for ESP32 or ESP8266. I will be grateful if you can give me a sketch, which work both for ESP32 and ESP8266
2. Routines, void logSDCard(), void appendFile are giving lot of errors.
3. I Bypassed all problematic lines of program. and Tried to compile but it gave errer
Hi.
Can you tell me the errors your’re getting?
Otherwise, it is very difficult to find our what might be wrong.
As I’ve told you, the FS.h library might not be compatible with the ESP8266, so you need to write data to the SD card using the snippet of code I’ve shown you.
It may not be possible having a code that works for both boards. You may need to have a different code for each board.
Regards,
Sara
Ms.Sara Madam,
Thank you very much for your prompt response. I have also tried in different ways to make a common sketch workable for both ESP8266 and ESP32. But as you said rightly it is not possible to make a common sketch. I even tried to search on google. but everywhere I got separate sketches.
Let us take this as a task to develop a common code. If I get success, I will surely share the sketch with you. meanwhile if you get success, please let me know how you could do it.
Once again thank you very much your prompt responses and really sorry to trouble you