TTGO LORA V1.6 sd card example

Hello

I have TTGO Lora V1.6 with onboard sd card and i need any sd card example.
I tired a few example but sd card failed.

Please tell me which sample can i use for sd card?
Board:

First google result: GitHub - jonashoechst/ttgo-lora-sd: TTGO LoRa and SD card (working demo)

google "Arduino" + board + problem or requirement

1 Like

I changed pins like that and mounted sd card

#define SD_CS 13
#define SD_SCK 14
#define SD_MOSI 15
#define SD_MISO 2

Sweet, good work.
Please post a working sketch here to help future users.

1 Like
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
 #include <RH_RF95.h>
 #include <RHSoftwareSPI.h>

// SD SPI pins can be chosen freely, but cannot overlap with other ports!
#define SD_CS 13
#define SD_SCK 14
#define SD_MOSI 15
#define SD_MISO 2

#define LORA_FREQ 868.0

#define LOG_PATH "/lora_recv.log"

// The sd card can also use a virtual SPI bus
SPIClass sd_spi(HSPI);

// Use a virtual (software) SPI bus for the sx1278
RHSoftwareSPI sx1278_spi;
RH_RF95 rf95(LORA_CS, LORA_IRQ, sx1278_spi);

void setup() {
    // Builtin LED
    pinMode(LED_BUILTIN, OUTPUT);

    // Serial output
    Serial.begin(115200);

    // LoRa: Init
    pinMode(LORA_RST, OUTPUT);
    digitalWrite(LORA_RST, LOW);
    delay(100);
    digitalWrite(LORA_RST, HIGH);

    // the pins for the virtual SPI explicitly to the internal connection
    sx1278_spi.setPins(LORA_MISO, LORA_MOSI, LORA_SCK);

    if (!rf95.init()) 
        Serial.println("LoRa Radio: init failed.");
    else
        Serial.println("LoRa Radio: init OK!");

    // LoRa: set frequency
    if (!rf95.setFrequency(LORA_FREQ))
        Serial.println("LoRa Radio: setFrequency failed.");
    else
        Serial.printf("LoRa Radio: freqency set to %f MHz\n", LORA_FREQ);

    rf95.setModemConfig(RH_RF95::Bw125Cr45Sf128);

    // LoRa: Set max (23 dbm) transmission power. 
    rf95.setTxPower(23, false);

    // SD Card
    sd_spi.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);

    if (!SD.begin(SD_CS, sd_spi))
        Serial.println("SD Card: mounting failed.");
    else 
        Serial.println("SD Card: mounted.");

}

uint8_t lora_buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t lora_len;
uint8_t receive_counter = 0;

void loop() {
    // Blink LED
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));

    lora_len = RH_RF95_MAX_MESSAGE_LEN;
    if (rf95.recv(lora_buf, &lora_len)) {
        receive_counter++;
        Serial.printf("Received LoRa message #%i (%i bytes):\n%s\n", receive_counter, lora_len, lora_buf);

        File test = SD.open(LOG_PATH, FILE_APPEND);
        if (!test) {
            Serial.println("SD Card: writing file failed.");
        } else {
            Serial.printf("SD Card: appending data to %s.\n", LOG_PATH);
            test.write(lora_buf, lora_len);
            test.printf("\n\n");
            test.close();
        }
    }

    delay(100);
}

platform.ini

[env:ttgo-lora32-v1]
platform = espressif32
board =  ttgo-lora32-v1
 ;ttgo-lora32-v21

framework = arduino
monitor_speed = 115200

lib_deps =
    RadioHead
    ;mbed-danjulio/RadioHead @ 0.0.0+sha.e69d086cb053
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.