Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data logger RTC DS1307 + SD #6

Open
nicolasdb opened this issue Sep 12, 2022 · 7 comments
Open

Data logger RTC DS1307 + SD #6

nicolasdb opened this issue Sep 12, 2022 · 7 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@nicolasdb
Copy link
Owner

nicolasdb commented Sep 12, 2022

Data logger module - RTC DS1307 + SDcard

image

Features:

With this Data Log Shield for WiFi D1 Mini board, can saving data to files on any FAT16 or FAT32 formatted MicroSD card.
The included RTC (Real Time Clock) can be used to timestamp all your data with the current time, so that you know precisely what happened when!
SD card interface works with FAT16 or FAT32 formatted cards.
Real time clock (RTC) keeps the time going even when the power disconnected. The coin cell battery backup last date and time.
RTC protected from wrong connecting of battery.

Pinout:

RTC:
D1 - SCL
D2 - SDA

SD card:
D5 - CLK
D6 - DO
D7 - DI
D8 - CS

https://github.com/wemos/D1_mini_Examples/blob/master/examples/04.Shields/Micro_SD_Shield/Datalogger/Datalogger.ino

@nicolasdb
Copy link
Owner Author

nicolasdb commented Sep 12, 2022

image

image

@nicolasdb
Copy link
Owner Author

nicolasdb commented Sep 12, 2022

pinout

pinout2

@nicolasdb
Copy link
Owner Author

nicolasdb commented Sep 12, 2022

Pinout SPI?

https://forum.m5stack.com/topic/4197/stamp-c3-c3u-spi/2

First of all I really really like the Stamp C3(U), I find the plastic cover totally great. But what frustrates me (maybe I'm doing something wrong) is that SPI is not usable.
The reason is that for classic full-duplex SPI on a ESP32C3 you need SPI2 (Fast SPI) which leads to the following:

  • MOSI = FSPID = GPIO7 --> nicely on the PIN header
  • MISO = FSPIQ = GPIO2 --> the status LED on Stamp C3(U), not on the header
  • CLK = FSPICLK = GPIO6 --> nicely on the PIN header
  • CS = FSPICS0~5 = GPIO10 for CS0 --> nicely on the PIN header and in general chip select is a bit easier
    I really don't get why GPIO2 was used for the status LED, from what I get there's nothing special about it. So I think / strongly believe / am convinced that SPI peripherals just don't work on the stamp...

Hello @dominik
the nice thing about ESP32 and its variants (like the C3) is that different functions (like SPI) can use almost any GPIOs.
With the Arduino environment you can define the GPIOs to be used for SPI like this:

#define SCK GPIO_NUM_6
#define MISO GPIO_NUM_4
#define MOSI GPIO_NUM_7
#define CS GPIO_NUM_5

SPI.begin(SCK, MISO, MOSI, -1);

So depending version, it should match like that with my selection of pins :
SD card:
D5 = CLK = SCK = FSPICLK = GPIO10
D6 = DO = MISO = FSPIQ = GPIO8
D7 = DI = MOSI = FSPID = GPIO7
D8 = CS = FSPICS0~5 = GPIO6

@nicolasdb nicolasdb changed the title Data logger + SD Data logger RTC DS1307 + SD Sep 12, 2022
@nicolasdb
Copy link
Owner Author

nicolasdb commented Sep 12, 2022

https://github.com/PaulStoffregen/DS1307RTC > doesn't work.
https://wiki.seeedstudio.com/Grove-RTC/ > doesn't work
https://github.com/adafruit/RTClib > working following this tutorial https://lastminuteengineers.com/ds1307-rtc-arduino-tutorial/
, but:

I needed to add:
#include <SPI.h> and of course define my I2C pins. It look like that the library use SPI.h and I had errors during compilation.

@nicolasdb nicolasdb added the ⚔️ WIP ⚔️ work in progress label Sep 12, 2022
@nicolasdb
Copy link
Owner Author

#include "Arduino.h"
#include <SPI.h>
#include "FS.h"
#include <SD.h>
#include <Adafruit_I2CDevice.h>

#define SCK 10
#define MISO 8
#define MOSI 7
#define CS 6

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
SPI.begin(SCK, MISO, MOSI, CS);

Serial.print("Initializing SD card...");

// see if the card is present and can be initialized:
if (!SD.begin(CS)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}

void loop()
{
// make a string for assembling the data to log:
String dataString = "";

// read three sensors and append to the string:
//for (int analogPin = 0; analogPin < 3; analogPin++) {
// int sensor = analogRead(analogPin);
// dataString += String(sensor);
// if (analogPin < 2) {
// dataString += ",";
// }
//}
// The WeMos D1 Mini only has one analog pin A0.
int sensor = analogRead(3);
dataString += String(sensor);

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}

delay(1000);
}

@nicolasdb
Copy link
Owner Author

nicolasdb commented Sep 13, 2022

Ok, I get that I need to define SPI pins.

#define SCK 10
#define MISO 8
#define MOSI 7
#define CS 6

And launch it in Setup:
SPI.begin(SCK, MISO, MOSI, CS); and SD.begin(CS);
but then,
I still get "Card failed, or not present" or nothing.
I tried example from several library and tutorial, with a focus on the Setup to just get to initialize the module....

I quit.
I will try something else, like writing my log on a internal SPIFFS partition

@nicolasdb

This comment was marked as off-topic.

@nicolasdb nicolasdb added bug Something isn't working help wanted Extra attention is needed and removed ⚔️ WIP ⚔️ work in progress labels Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant