0

I'm using sim800l EVB and I have two codes one for Sd card and another for GSM. When I put the two codes together so I have one code, the sd card is able to initialize but the gsm does. When I debug to find out what wasnt executing, it was the isReady() function. The code for GSM initialization works without the sd card. When I put the Sd card on top, the sd card initializes but the gsm doesnt. Below is the code.

#include <SoftwareSerial.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include "EmonLib.h"
#include "SIM800L.h"
#include <SPI.h>
#include <SD.h>

// Define pin constants
#define SIM800_RX_PIN 2
#define SIM800_TX_PIN 3
#define SIM800_RST_PIN 7

// Define configuration constants
const int chipSelect = 4;
const char APN[] = "internet";
const char URL[] = "http://api.restful-api.dev/objects";
const char CONTENT_TYPE[] = "application/json";
const char PAYLOAD[] = "{\"name\": \"Apple MacBook Pro 16\", \"data:{\"year\": 2019, \"price\": 1849.99, \"CPU model\": \"Intel Core i9\", \"Hard disk size\": \"1 TB\"}}";


void setup() {
  // Initialize LCD display
  lcd.init();
  lcd.backlight();

  // Initialize serial communication for debugging
  Serial.begin(115200);
  while (!Serial);




  initializationOf("GSM");

  // Initialize GSM and SIM800L module
  initializeGSM();

  initializationOf("SD card");

  // Initialize SD card module
  //initializeSDCard();
  // Configure EnergyMonitor
  emon1.voltage(A0, 110.75, 1.7);

  // Clear LCD display
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("MEASURED VOLTAGE");
}

void loop() {
  // Calculate voltage
  emon1.calcVI(20, 2000);
  volt = emon1.Vrms;

  // Display voltage on LCD
  lcd.setCursor(0, 1);
  lcd.print("VOLTAGE = ");
  lcd.print(volt);
  lcd.print("V         ");

  // Check if counter has reached 5
  if (counter >= 5) {
    // Perform data upload and reset counter
    timeUpForPushToDB();
    counter = 0;
  }

  // Increment counter
  counter++;

  // Add delay to control loop frequency
  delay(500);
}

// Function to initialize GSM and SIM800L module
void initializeGSM() {
  // Initialize SoftwareSerial for SIM800 module
  SoftwareSerial* serials = new SoftwareSerial(SIM800_RX_PIN, SIM800_TX_PIN);


  serials->begin(9600);
  delay(1000);

  // Initialize SIM800L module

  sim800l = new SIM800L((Stream*)serials, SIM800_RST_PIN, 200, 512);

  // Perform module setup
  setupModule();
}


void initializeSDCard() {
  Serial.print("Initializing SD card...");

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

void setupModule() {
  // Wait until the module is ready to accept AT commands
 

  while (!sim800l->isReady()) {
    Serial.println(F("Problem to initialize AT command, retry in 1 sec"));
    delay(1000);
  }

  Serial.println(F("Setup Complete!"));

  // Wait for GSM signal
  uint8_t signal = sim800l->getSignal();
  while (signal <= 0) {
    delay(1000);
    signal = sim800l->getSignal();
  }
  Serial.print(F("Signal OK (strength: "));
  Serial.print(signal);
  Serial.println(F(")"));
  delay(1000);

  // Wait for operator network registration
  NetworkRegistration network = sim800l->getRegistrationStatus();
  while (network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
    delay(1000);
    network = sim800l->getRegistrationStatus();
  }
  Serial.println(F("Network registration OK"));
  delay(1000);

  // Setup GPRS configuration
  bool success = sim800l->setupGPRS(APN);
  while (!success) {
    success = sim800l->setupGPRS(APN);
    delay(5000);
  }
  Serial.println(F("GPRS config OK"));
}

I tried Printing debug messages to find out what wasnt running and it was the isReady() for the GSM that wasnt running.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
BR41NE
  • 1
  • 1
  • There are problems with a lot of SD card modules where they don't like to share the SPI bus. – Delta_G Aug 27 '23 at 17:32
  • So i need to change the Sd card module? Or do you think it can be because I'm using Uno and the resources might be just too much for it? – BR41NE Aug 29 '23 at 03:38
  • Most likely you will need a different SD module. The cheap one's don't share the bus. They won't release the MOSI line so anything else can use it. You may be able to find some more expensive modules that will work. Or you can move the SD module to a software spi port. – Delta_G Aug 29 '23 at 16:13

0 Answers0