hi all, nice to meet you. I'm new to Arduino and I want to learn more about Arduino.
i have a project about Water Flow Measurement. and I'm currently having trouble communicating with the bk-7000 v2 module (SIM7000E). when i upload the sketch to the arduino mega 2560 pro board, i get the error message "failed to set the baud rate". i use example sketch dfrobot/tinygsm library. can anyone here help me with the problem i'm having? thank you very much for your kind feedback.
wiring illustration
here the sketch:
#define _PINRST 3
#define _PINCE 4
#define _PINDC 5
#define _PINDIN 6
#define _PINBL 7
#define _PINCLK 12
#define _PINMODRX 14
#define _PINMODTX 15
#define _PINLED 20
#define _PINBTN1 21
#define _PINBTN2 22
#define _PINBTN3 23
#define console Serial
#define RATE_CSL 115200
#define RATE_MDL 115200
#define TINY_GSM_MODEM_SIM7000
#define TINY_GSM_DEBUG console
#define DUMP_AT_COMMANDS
#include <LCD5110_Basic.h>
extern uint8_t SmallFont[];
LCD5110 n5110(_PINCLK, _PINDIN, _PINDC, _PINRST, _PINCE);
boolean oldSwitchState = LOW;
boolean newSwitchState = LOW;
boolean LEDstatus = LOW;
#include <SoftwareSerial.h>
SoftwareSerial serialAT(_PINMODRX, _PINMODTX);
#include <TinyGsmClient.h>
uint32_t rateBAUD = 0;
#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(serialAT, console);
TinyGsm modem(debugger);
#else
TinyGsm modem(serialAT);
#endif
TinyGsmClient client(modem);
#include <PubSubClient.h>
PubSubClient mqtt(client);
int initLoop = 0;
void setup()
{
console.begin(RATE_CSL);
serialAT.begin(RATE_MDL);
pinMode(_PINLED, OUTPUT);
digitalWrite(_PINLED, LOW);
pinMode(_PINBL, OUTPUT);
digitalWrite(_PINBL, HIGH);
n5110.InitLCD();
n5110.setFont(SmallFont);
n5110.clrScr();
}
void loop()
{
testLED();
backlightLCD();
// initModem();
}
void initModem()
{
digitalWrite(_PINBL, LOW);
if (!rateBAUD) {
n5110.clrScr();
n5110.print("Initializing", CENTER, 16);
n5110.print("modem...", CENTER, 24);
rateBAUD = TinyGsmAutoBaud(serialAT);
}
if (!rateBAUD) {
initLoop++;
console.println(F("***********************************************************"));
console.println(F(" Module does not respond!"));
console.println(F(" - Check your Serial wiring"));
console.println(F(" - Check the module is correctly powered and turned on"));
console.println(F("***********************************************************"));
n5110.clrScr();
n5110.print("Module does", CENTER, 16);
n5110.print("not respond!", CENTER, 24);
delay(5000);
n5110.clrScr();
n5110.print("Initializing", CENTER, 16);
n5110.print("Modem x"+String(initLoop), CENTER, 24);
delay(5000);
delay(20000L);
return;
}
n5110.clrScr();
n5110.print("Connected to", CENTER, 16);
n5110.print("Modem", CENTER, 24);
modem.setNetworkMode(38); //38-LTE, 13-GSM
modem.setPreferredMode(2); //2-NB-IoT, 1-CAT, 3-GPRS
delay(10000L);
serialAT.begin(rateBAUD);
console.println(F("***********************************************************"));
console.println(F(" You can now send AT commands"));
console.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
console.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
console.println(F("***********************************************************"));
while(true) {
if (serialAT.available()) {
console.write(serialAT.read());
}
if (console.available()) {
serialAT.write(console.read());
}
delay(0);
}
digitalWrite(_PINBL, HIGH);
}
void backlightLCD()
{
if (digitalRead(_PINBTN1) == HIGH) {
digitalWrite(_PINBL, LOW);
delay(6000);
digitalWrite(_PINBL, HIGH);
}
/*newSwitchState = digitalRead(_PINBTN1);
if ( newSwitchState != oldSwitchState )
{
if ( newSwitchState == HIGH )
{
// if ( LEDstatus == LOW ) { digitalWrite(_PINLED, HIGH); LEDstatus = HIGH; }
// else { digitalWrite(_PINLED, LOW); LEDstatus = LOW; }
if ( LEDstatus == LOW ) { digitalWrite(_PINBL, HIGH); LEDstatus = HIGH; }
else { digitalWrite(_PINBL, LOW); LEDstatus = LOW; }
}
oldSwitchState = newSwitchState;
}*/
}
void testLED()
{
if (digitalRead(_PINBTN2) == HIGH) {
for (int i = 0; i < 1 && digitalRead(_PINBTN2) == HIGH; i++) {
digitalWrite(_PINLED, HIGH);delay(200);
digitalWrite(_PINLED, LOW);delay(200);
}
}
if (digitalRead(_PINBTN3) == HIGH) {
for (int i = 0; i < 1 && digitalRead(_PINBTN3) == HIGH; i++) {
digitalWrite(_PINLED, HIGH);delay(500);
digitalWrite(_PINLED, LOW);delay(500);
}
}
}