I am trying to connect my Arduino Uno with a SIm800L to Blynk but I get a Cannot init error.
I have tested with the AT command and the GSM module is connected correctly, my code is below
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "capgroup";
char user[] = "";
char pass[] = "";
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1
// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
TinyGsm modem(SerialAT);
// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);
// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
BLYNK_WRITE(V1)
{
// if you type "Marco" into Terminal Widget - it will respond: "Polo:"
if (String("Marco") == param.asStr()) {
terminal.println("You said: 'Marco'") ;
terminal.println("I said: 'Polo'") ;
} else {
// Send it back
terminal.print("You said:");
terminal.write(param.getBuffer(), param.getLength());
terminal.println();
}
// Ensure everything is sent
terminal.flush();
}
void setup()
{
// Debug console
Serial.begin(115200);
delay(10);
// Set GSM module baud rate
SerialAT.begin(115200);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
//modem.restart();
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
Blynk.begin(auth, modem, apn, user, pass);
// Clear the terminal content
terminal.clear();
// This will print Blynk Software version to the Terminal Widget when
// your hardware gets connected to Blynk Server
terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
terminal.println(F("-------------"));
terminal.println(F("Type 'Marco' and get a reply, or type"));
terminal.println(F("anything else and get it printed back."));
terminal.flush();
}
void loop()
{
Blynk.run();
}
Why do you have comments for raising the Internet connection in your code?
Internet connection modem raises?
mySerial.println("AT"); // Sending an AT command
updateSerial();
mySerial.println("AT+CSQ"); // Signal quality test, value range 0-31, 31 is best
updateSerial();
mySerial.println("AT+CCID"); // Reading SIM card information
updateSerial();
mySerial.println("AT+CREG?"); // Network Registration Check
updateSerial();
@Deanr you were given triple backticks to copy/paste by @John93, but you chose to use differnet characters instead.
Please edit your post again and this time use the correct characters.
Note also that the triple backticks have to be on a line of their own, immediately above and below the sketch.
I have changed the baud rate to 9600 but I still have an issue, I am powering it through a Buck Boost module to ensure it has enough power to operate.
Do you have some sample code for the Sim800L and the Arduino Uno?
I’d suggest that you re-read the topic I linked you to.
You can’t simply change the communication rate in the sketch, you also need to tell your SIM800 module to use the same baud rate, which will need to be done via an AT command.
I have managed to get the Sim800l working with the below code but now I get a login timeout when connecting to blynk.cloud:80
/************************************************************************************
* Created By: Tauseef Ahmad
* Created On: December 29, 2021
*
* Tutorial: https://youtu.be/qrxuAezlDyA
*
* ****************************************************************************
* Download Resources
* ****************************************************************************
* Download latest Blynk library here:
* https://github.com/blynkkk/blynk-library/releases/latest
* ****************************************************************************
* DHT-sensor-library
* https://github.com/adafruit/DHT-sensor-library
* ****************************************************************************
* Attention! Please check out TinyGSM guide:
* https://tiny.cc/tinygsm-readme
* Change GPRS apm, user, pass, and Blynk auth token to run :)
* Feel free to apply it to any other example. It's simple!
**********************************************************************************/
//-----------------------------------------------------------------------
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
//-----------------------------------------------------------------------
/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID "******"
#define BLYNK_DEVICE_NAME "*****"
#define BLYNK_AUTH_TOKEN "******"
//-----------------------------------------------------------------------
// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE
//-----------------------------------------------------------------------
// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30
//-----------------------------------------------------------------------
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
//-----------------------------------------------------------------------
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
//-----------------------------------------------------------------------
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "internet";
char user[] = "";
char pass[] = "";
//-----------------------------------------------------------------------
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1
//-----------------------------------------------------------------------
// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
TinyGsm modem(SerialAT);
//-----------------------------------------------------------------------
#include <DHT.h>
#define DHT11_PIN 4
#define DHTTYPE DHT11
DHT dht(DHT11_PIN, DHTTYPE);
//-----------------------------------------------------------------------
BlynkTimer timer;
#define INTERVAL 1000L
//-----------------------------------------------------------------------
/************************************************************************************
* This function sends Arduino's up time every second to Virtual Pin.
* In the app, Widget's reading frequency should be set to PUSH. This means
* that you define how often to send data to Blynk App.
**********************************************************************************/
void SendDhtData()
{
//-----------------------------------------------------------------------
//Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
//-----------------------------------------------------------------------
//Read temperature as Celsius (the default)
float t = dht.readTemperature();
//-----------------------------------------------------------------------
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
//-----------------------------------------------------------------------
//Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
//-----------------------------------------------------------------------
Serial.print("Temperature: ");
Serial.println(t);
Serial.print("Humidity: ");
Serial.println(h);
Serial.println("------------------------------------------");
//-----------------------------------------------------------------------
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, h);
//-----------------------------------------------------------------------
}
/************************************************************************************
* setup() function
**********************************************************************************/
void setup()
{
//-----------------------------------------------------------
// Debug console
Serial.begin(115200);
delay(10);
//-----------------------------------------------------------
// Set GSM module baud rate
SerialAT.begin(9600);
//SerialAT.begin(9600,SWSERIAL_8N1,D3,D4);
delay(3000);
//-----------------------------------------------------------
dht.begin();
//-----------------------------------------------------------
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
//modem.restart();
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
//-----------------------------------------------------------
Blynk.begin(auth, modem, apn, user, pass);
//-----------------------------------------------------------
// Setup a function to be called every second
timer.setInterval(INTERVAL, SendDhtData);
//-----------------------------------------------------------
}
/************************************************************************************
* loop() function
**********************************************************************************/
void loop()
{
Blynk.run();
timer.run();
}
Okay, you need to be clearer with your communication if you want sensible feedback.
The serial output you’ve just provided wasn’t produced with the latest code you posted. It may have been produced with your original sketch, which is designed for Blynk Legacy, but I have my doubts.
This is the code I am using now with the login timeout error
* Created By: Tauseef Ahmad
* Created On: December 29, 2021
*
* Tutorial: https://youtu.be/qrxuAezlDyA
*
* ****************************************************************************
* Download Resources
* ****************************************************************************
* Download latest Blynk library here:
* https://github.com/blynkkk/blynk-library/releases/latest
* ****************************************************************************
* DHT-sensor-library
* https://github.com/adafruit/DHT-sensor-library
* ****************************************************************************
* Attention! Please check out TinyGSM guide:
* https://tiny.cc/tinygsm-readme
* Change GPRS apm, user, pass, and Blynk auth token to run :)
* Feel free to apply it to any other example. It's simple!
**********************************************************************************/
//-----------------------------------------------------------------------
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
//-----------------------------------------------------------------------
/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID "TMPLrKAvPedF"
#define BLYNK_DEVICE_NAME "Dev 2 GSM"
#define BLYNK_AUTH_TOKEN "OTQ0an_SSlPvkE6r7fZU46h2IZx0mxPi"
//-----------------------------------------------------------------------
// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE
//-----------------------------------------------------------------------
// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30
//-----------------------------------------------------------------------
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
//-----------------------------------------------------------------------
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
//-----------------------------------------------------------------------
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "lte.vodacom.za";
char user[] = "";
char pass[] = "";
//-----------------------------------------------------------------------
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1
//-----------------------------------------------------------------------
// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
TinyGsm modem(SerialAT);
//-----------------------------------------------------------------------
#include <DHT.h>
#define DHT11_PIN 4
#define DHTTYPE DHT11
DHT dht(DHT11_PIN, DHTTYPE);
//-----------------------------------------------------------------------
BlynkTimer timer;
#define INTERVAL 1000L
//-----------------------------------------------------------------------
/************************************************************************************
* This function sends Arduino's up time every second to Virtual Pin.
* In the app, Widget's reading frequency should be set to PUSH. This means
* that you define how often to send data to Blynk App.
**********************************************************************************/
void SendDhtData()
{
//-----------------------------------------------------------------------
//Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
//-----------------------------------------------------------------------
//Read temperature as Celsius (the default)
float t = dht.readTemperature();
//-----------------------------------------------------------------------
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
//-----------------------------------------------------------------------
//Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
//-----------------------------------------------------------------------
Serial.print("Temperature: ");
Serial.println(t);
Serial.print("Humidity: ");
Serial.println(h);
Serial.println("------------------------------------------");
//-----------------------------------------------------------------------
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, h);
//-----------------------------------------------------------------------
}
/************************************************************************************
* setup() function
**********************************************************************************/
void setup()
{
//-----------------------------------------------------------
// Debug console
Serial.begin(115200);
delay(10);
//-----------------------------------------------------------
// Set GSM module baud rate
SerialAT.begin(9600);
//SerialAT.begin(9600,SWSERIAL_8N1,D3,D4);
delay(3000);
//-----------------------------------------------------------
dht.begin();
//-----------------------------------------------------------
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
//modem.restart();
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
//-----------------------------------------------------------
Blynk.begin(auth, modem, apn, user, pass, "blynk-cloud.com", 8080);
//-----------------------------------------------------------
// Setup a function to be called every second
timer.setInterval(INTERVAL, SendDhtData);
//-----------------------------------------------------------
}
/************************************************************************************
* loop() function
**********************************************************************************/
void loop()
{
Blynk.run();
timer.run();
}