SMS notification not working with Arduino Nano with a GSM module - arduino

I want to use an Arduino Nano to monitor SMS traffic of a GSM module. I'm able to read and send SMS but the notification system is not working: when I send an SMS (to the SIM card that is in the GSM module) no new data becomes available in the Serial port. Any idea why or how can I debug to find the problem?
The communication is done through pins 9 and 10 of Arduino and RX and TX for the GSM module, which is an Quectel EC25. The code I'm using:
#include <SoftwareSerial.h>
#define DEBUG Serial
SoftwareSerial EC25(10,9); // RX, TX - 9600 baud rate
// pin 8 of raspi -> pin 9 of arduino nano
// pin 10 of raspi -> pin 10 of arduino nano
#define AT_RESPONSE_LEN 100
#define TIMEOUT 1000
void setup() {
// put your setup code here, to run once:
EC25.begin(9600);
DEBUG.begin(9600);
// some AT commands just to see if the coms are ok
sendATComm("AT","OK\r\n");
sendATComm("AT+IPR?","OK\r\n");
sendATComm("AT+CGSN","OK\r\n");
sendATComm("AT+CNMI=2,1,0,0,0","OK\r\n");
DEBUG.println("listennig");
}
void loop() {
// put your main code here, to run repeatedly:
if (EC25.available()){
DEBUG.println("Notification received!");
}
}
// function for sending at command.
const char* sendATComm(const char *command, const char *desired_reponse)
{
uint32_t timer;
char response[AT_RESPONSE_LEN]; // module response for AT commands.
memset(response, 0 , AT_RESPONSE_LEN);
EC25.flush();
sendATCommOnce(command);
timer = millis();
while(true){
if(millis()-timer > TIMEOUT){
sendATCommOnce(command);
timer = millis();
}
char c;
int i = 0;
while(EC25.available()){
c = EC25.read();
DEBUG.write(c);
response[i++]=c;
delay(2);
}
if(strstr(response, desired_reponse)){
return response;
memset(response, 0 , strlen(response));
break;
}
}
}
// send at comamand to module
void sendATCommOnce(const char *comm)
{
EC25.print(comm);
EC25.print("\r");
delay(100);
}

So, it turns out that I had to define the output port of URC to use UART communication (not using it as default).
The default configuration was set to either usbat or usbmodem, meaning that the notification information I was waiting for was being sent to one of these serial ports. But I was listening to UART (through RX and TX pints) and therefore I was not getting any notification.
AT command QURCCFG can be used to set which port URC signals should be sent to. In this case I want them to be sent to UART:
AT+QURCCFG="urcport","uart1"

Related

How does my ESP8266/NodeMCU communicate with my GSM Module SIM800L?

so I want to connect my SIM800L GSM Module to my NodeMCU. I bought a LM2596 DC-DC voltage regulator to convert the output voltage to ~4V for the SIM800L. Input voltage for the regulator is 9V/1A.
Everything is connected: RX from GSM to D5 (GPIO14), TX to D6 (GPIO12) and RST to D7 (GPIO13). The GPIOs are deliberately chosen, since I've read online, that the RX/TX Pins on the NodeMCU are used internally. I tried matching RX/TX pins before, but it's the same result (that's why I am certain, it has to be my code that is defect). A SIM card is also inserted in the GSM Module (with PIN).
I'm coding on the Arduino IDE and I'm using the GSMSim and SoftwareSerial libraries for connecting to the GSM Module. I've tried the example sketches from the GSMSim to communicate to the GSM Module, but I'm not getting any answer on my serial monitor.
I also tried manually sending commands to the GSM Module.
#include <GSMSim.h>
#include <SoftwareSerial.h>
// You can use any Serial interface. I recommended HardwareSerial. Please use the library with highiest baudrate.
// In examples, i used HardwareSerial. You can change it anymore.
#define RX 14
#define TX 12
#define RESET 13
SoftwareSerial serial(RX, TX);
GSMSim gsmModule(serial, RESET);
void setup() {
serial.begin(115200); // If you dont change module baudrate, it comes with auto baudrate.
while(!serial) ;
Serial.begin(115200); // Serial for debug...
while(!Serial) ;
Serial.println("");
Serial.println("serial begin");
// Init module...
gsmModule.init(); // use for reseting module. Use it if you dont have any valid reason.
delay(100);
gsmModule.sendATCommand("AT+GMR");
if(serial.available()) Serial.println(serial.readString());
Serial.println("Sent AT");
}
OUTPUT:
serial.begin
Sent AT
Another example with the modified GSMSim_HTTP sketch:
#include <GSMSim.h>
#include <SoftwareSerial.h>
// You can use any Serial interface. I recommended HardwareSerial. Please use the library with highiest baudrate.
// In examples, i used HardwareSerial. You can change it anymore.
#define RX 14
#define TX 12
#define RESET 13
SoftwareSerial serial(RX, TX);
GSMSim http(serial, RESET);
static volatile int num = 0;
void setup() {
serial.begin(115200); // If you dont change module baudrate, it comes with auto baudrate.
while(!serial) {
; // wait for module for connect.
}
Serial.begin(115200); // Serial for debug...
// Init module...
http.init(); // use for init module. Use it if you dont have any valid reason.
Serial.print("Set Phone Function... ");
Serial.println(http.setPhoneFunc(1));
//delay(1000);
Serial.print("is Module Registered to Network?... ");
Serial.println(http.isRegistered());
//delay(1000);
Serial.print("Signal Quality... ");
Serial.println(http.signalQuality());
//delay(1000);
Serial.print("Operator Name... ");
Serial.println(http.operatorNameFromSim());
//delay(1000);
//Serial.print("GPRS Init... ");
//Serial.println(http.gprsInit("internet")); // Its optional. You can set apn, user and password with this method. Default APN: "internet" Default USER: "" Default PWD: ""
//delay(1000);
Serial.print("Connect GPRS... ");
Serial.println(http.connect());
//delay(1000);
Serial.print("Get IP Address... ");
Serial.println(http.getIP());
delay(1000);
Serial.print("Get... ");
Serial.println(http.get("sera.erdemarslan.com/test.php"));
delay(1000);
Serial.print("Get with SSL and read returned data... ");
Serial.println(http.getWithSSL("erdemarslan.com/test.php", true));
delay(1000);
Serial.print("Post... ");
Serial.println(http.post("sera.erdemarslan.com/test.php", "name=Erdem&surname=Arslan", "application/x-www-form-urlencoded"));
delay(1000);
Serial.print("Post with SSL and read returned data... ");
Serial.println(http.post("erdemarslan.com/test.php", "name=Erdem&surname=Arslan", "application/x-www-form-urlencoded", true));
delay(1000);
Serial.print("Close GPRS... ");
Serial.println(http.closeConn());
//delay(1000);
// For other methods please look at readme.txt file.
}
void loop() {
// Use your Serial interface...
if(serial.available()) {
String buffer = "";
buffer = Serial1.readString();
num = num + 1;
Serial.print(num);
Serial.print(". ");
Serial.println(buffer);
}
// put your main code here, to run repeatedly:
}
OUTPUT:
serial.begin
Set Phone Function... 0
is Module Registered to Network?... 0
Signal Quality... 99
Operator Name... NOT CONNECTED
Connect GPRS... 0
Get IP Address...
Get module date time... ERROR:NOT_GET_DATETIME
Set timezone and time server... 0
Sync date time from server... AT_COMMAND_ERROR
Get module date time after sycn... ERROR:NOT_GET_DATETIME
Close GPRS... 0
I hope it's something obvious, since I am not familiar with AT commands at all.
Thanks!

How do I repeatedly send an AT command to a Bluetooth module arduino

I've been working on a project and want an Arduino uno with an HM-19 Bluetooth module to repeatedly send an AT command to the module then print the modules result in the serial monitor. I'm having trouble and it is only returning the number 53 and not the response 'OK'. Thanks for any insight you're able to give.
//import Software Serial to communicate over comms port
#include <SoftwareSerial.h>
// 0 and 1 are the tx and rx pins ans should be where the hm-19 is
// may be 0,1 instead
SoftwareSerial HM19(1,0);
void setup() {
// begin serial monitor and wait for something(?, found online)
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
//tell user it's started
Serial.println("Started");
//I believe this begins the monitor for the HM-19
HM19.begin(9600);
delay(1000);
}
void loop() {
// give user status report
delay(1000);
Serial.println("Sending an AT command...");
// need to find if this is how you send an AT command (currenty send 'AT' as a test)
HM19.write("AT\r");
delay(30);
//wait for the HM19 to respond then print it out
int HMresponse = 0;
if (HM19.available()){}
HMresponse = HM19.read();
Serial.println(HMresponse);
}

Communication between Arduino Nano and HM-10 BLE controller is not working

I want to check if communication is working between my SerialMonitor in Arduino IDE and BLE controller.
I typed command AT to my SerialMonitor and it suppose to return OK response but nothing happened.
This is scheme what I used:
Code:
#include <SoftwareSerial.h>
SoftwareSerial bleSerial(2, 3); // RX, TX
void setup() {
//initialize serial port for logs
Serial.begin(9600);
while (!Serial) {
}
bleSerial.begin(9600);
}
void loop() {
if (bleSerial.available()) {
Serial.write(bleSerial.read());
}
if (Serial.available()) {
bleSerial.write(Serial.read());
}
}
UPDATE:
Changed values for SoftwareSerial bleSerial(3, 2); // RX, TX still doesnt work.
UPDATE2:
I've tried switching pins and code, nothing works. I should at least see HM-10 controller in my bluetooth devices on my Android phone, but I cant see anything.
UPDATE3:
I've used code from this Stackoverflow post and its working fine. I can finally see controller in my bluetooth devices on my Android phone also It returned name MLT-BT05 after AT+NAME? command. Looks like you have to read message per char and put delay 10ms between chars, otherwise it will not be possible to read message from BLE controller. That was the only problem.
You should connect RX-TX and TX-RX (not RX-RX and TX-TX like your graphic shows) so change the cables and the code from
SoftwareSerial bleSerial(2, 3); // RX, TX
to
SoftwareSerial bleSerial(3, 2); // RX, TX
Connect according to this graphic (incl voltage divider)
Abd use the following sketch to test (read comments for details):
// SerialIn_SerialOut_HM-10_01
//
// Uses hardware serial to talk to the host computer and AltSoftSerial for communication with the bluetooth module
//
// What ever is entered in the serial monitor is sent to the connected device
// Anything received from the connected device is copied to the serial monitor
// Does not send line endings to the HM-10
//
// Pins
// BT VCC to Arduino 5V out.
// BT GND to GND
// Arduino D8 (SS RX) - BT TX no need voltage divider
// Arduino D9 (SS TX) - BT RX through a voltage divider (5v to 3.3v)
//
#include <SoftwareSerial.h>
SoftwareSerial BTserial;
char c=' ';
bool NL = true;
void setup()
{
Serial.begin(9600);
Serial.print("Sketch: "); Serial.println(__FILE__);
Serial.print("Uploaded: "); Serial.println(__DATE__);
Serial.println(" ");
BTserial.begin(9600);
Serial.println("BTserial started at 9600");
}
void loop()
{
// Read from the Bluetooth module and send to the Arduino Serial Monitor
if (BTserial.available())
{
c = BTserial.read();
Serial.write(c);
}
// Read from the Serial Monitor and send to the Bluetooth module
if (Serial.available())
{
c = Serial.read();
if (c!=10 & c!=13 )
{
BTserial.write(c);
}
// Echo the user input to the main window. The ">" character indicates the user entered text.
if (NL) { Serial.print("\r\n>"); NL = false; }
Serial.write(c);
if (c==10) { NL = true; }
}
}

Android Things to Arduino using I2C - error 6: No such device or address

I try to connect an NXP i.MX7D running Android Things to a Arduino UNO using I2C. The slave code is fairly simple :
#include <Wire.h>
void setup() {
Wire.begin(0x08); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}
The two devices are connected like this:
NPX SDA Pin ---> 3.3v level converter 5v ----> Arduino PIN A4
NPX SCL Pin ---> 3.3v level converter 5v ----> Arduino PIN A5
When I use the PIO tool I can't seem to connect or read the Arduino slave. There is two BUS (I2C1, I2C2) on the NPX I tried both with the same result:
imx7d_pico:/ $ pio i2c I2C1 0x08 read-reg-byte 0x00
[WARNING:client_errors.cc(35)] error 6: No such device or address
6|imx7d_pico:/ $ pio i2c I2C2 0x08 read-reg-byte 0x00
[WARNING:client_errors.cc(35)] error 6: No such device or address
I assume the level converter work properly I did have limited success with UART connection (Arduino was able to emit to NPX but not NPX to Arduino, will investigate this after)
Here are some pictures of the connection.
Try to add on Wire.onReceive callback(together with onRequest) to your arduino code.
Like this:
#include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}

Arduino gsm shield not responding. gsmAccess.begin() doesnt work

I'm trying to get my arduino GSM shield working with the example "Send SMS" code provided. However, when I upload and compile the program, the serial monitor displays "SMS Messages Sender" and nothing else occurs.
I am using Arduino uno r3 and gsm sim 900. powered gsm with 5V 1.5A. I have connected arduino pins 7&8 to pins 7&8 of gsm. I have connected the gsm to ground too.
When I use SoftwareSerial.h it works. But I wish to use GSM.h library which now isn't working. Any help please
// include the GSM library
#include <GSM.h>
// PIN Number for the SIM
#define PINNUMBER ""
// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
// Array to hold the number a SMS is retrieved from
char senderNumber[20];
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("SMS Messages Receiver");
// connection state
bool notConnected = true;
// Start GSM connection
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
}
void loop() {
char c;
// If there are any SMSs available()
if (sms.available()) {
Serial.println("Message received from:");
// Get remote number
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);
// An example of message disposal
// Any messages starting with # should be discarded
if (sms.peek() == '#') {
Serial.println("Discarded SMS");
sms.flush();
}
// Read message bytes and print them
while (c = sms.read()) {
Serial.print(c);
}
Serial.println("\nEND OF MESSAGE");
// Delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
}
delay(1000);
}
i expected this code to enable me to receive message and i can modify it to store the message in variables
Your problem is probably the wiring.
Your board (Arduino UNO R3) has its UART (the one you intend to use when you define Serial.begin(9600) on pins 0 RX and 1 TX. See here for the schematic and picture below (top right corner with tags TX and RX).
Software emulated serial works because you're defining pins 7 and 8 to be the emulated UART TX and RX signals.

Resources