Draguino Lora Shield on MEGA 2560

Hi there.

I used a Draguino Lora Shield with the LoRa.h library.

https://wiki.dragino.com/index.php?title=Lora_Shield

I combined it wit ha RTC SD Card module with the DS1307RTC.h library.

Micro SD Datenlogger Modul mit RTC - Bastelgarage Elektronik Online Shop?

CS => Pin: 10

MOSI => Pin: 11

MISO => Pin: 12

SCK => Pin: 13

SCL => Pin: A5

SDA => Pin: A4

GND => Pin: GND

5V =>Pin: 5V

As the CSPin on the Draguino is fixed to 10, I changed it for the SD Module to 4.

As I use a Atmega 2560, I had an Error by initializing the SD Card, Even when I forced the Pin 10 to HIGH. As I changed to a UNO with the same Pin connection it worked (also without PIN 10 high).

Although it works like that for me, I really would like to understand why?
Has anybody an idea?

Here is the code:

#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#include <LoRa.h>


void setup() {

    //digitalWrite(10, HIGH);

    Serial.begin(9600);
    while (!Serial);

    Serial.println("LoRa Receiver");

    if (!LoRa.begin(915E6)) {
        Serial.println("Starting LoRa failed!");
        while (1);
    }
    digitalWrite(10, HIGH);
    delay(1000);
    Serial.print("Initializing SD card...");

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

}

void loop() {
    // try to parse packet
    int packetSize = LoRa.parsePacket();
    if (packetSize) {
        // received a packet
        Serial.print("Received packet '");

        // read packet
        while (LoRa.available()) {
            Serial.print((char)LoRa.read());
        }

        // print RSSI of packet
        Serial.print("' with RSSI ");
        Serial.println(LoRa.packetRssi());
    }
}

Thanks in advance. :slight_smile:

Pascal

Those are not the SPI and I2C pins on a Mega 2560.

1 Like

Ah... So true
But the Draguino LoRa shield worked on Atmega 2560 because ist goes over ICSP and not over D11,12,13 :open_mouth:

Now it's clear.
Thanks :wink: