I am working on a project to send an email when a button is pressed using arduino uno, wifi module ESP8266, and the Blynk App. I was able to upload the sketch on the wifi module (ESP8266), but it's not responding. Here is the output that I am getting from the serial monitor:
len 1384, room 16
tail 8
chks
I have looked online and I can't find a solution to this. Can anyone one please help?
Below is the sketch that I am uploading.
Thanks in advance!
#include <Blynk.h>
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Set this to a bigger number, to enable sending longer messages */
#define BLYNK_MAX_SENDBYTES 128
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXXXXXX";
char pass[] = "";
void emailOnButtonPress()
{
// *** WARNING: You are limited to send ONLY ONE E-MAIL PER 15 SECONDS! ***
// Let's send an e-mail when you press the button
// connected to digital pin 2 on your Arduino
int isButtonPressed = !digitalRead(2); // Invert state, since button is "Active LOW"
if (isButtonPressed) // You can write any condition to trigger e-mail sending
{
Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
Blynk.email("xxxxxxx#gmail.com", "Subject: Button Logger", "You just pushed the button...");
// Or, if you want to use the email specified in the App (like for App Export):
//Blynk.email("Subject: Button Logger", "You just pushed the button...");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
// Send e-mail when your hardware gets connected to Blynk Server
// Just put the recepient's "e-mail address", "Subject" and the "message body"
Blynk.email("xxxxxx#gmail.com", "Subject", "My Blynk project is online.");
// Setting the button
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
}
void loop()
{
Blynk.run();
}
Related
I have a few questions as to why my input isn't behaving correctly. I have 2 functioning scripts I've used:
ESP32 to Xbee using UART2, I open a serial connection to Xbee3 and type "+++" or AT Commands "ATID" and I am able to view to xbee's response via serial monitoring, works fine
Samsung Phone Serial App to ESP32 using Bluetooth, I'm also able to connect to the phone and type commands from phone to terminal and terminal to phone, works fine.
code for item 1:
//Arduino IDE
//ESP32 to Xbee UART2
//Select your modem:
#define TINY_GSM_MODEM_XBEE
// Set serial for debug console (to the Serial Monitor, speed 115200)
#define SerialMon Serial
// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
HardwareSerial SerialAT(2);
#define TINY_GSM_DEBUG SerialMon
void setup() {
// put your setup code here, to run once:
// Set console baud rate
SerialMon.begin(115200);
SerialAT.begin(9600);
delay(1000);
SerialAT.print("+++"); while (SerialAT.available()) {SerialMon.write(SerialAT.read());}
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
// Access AT commands from Serial Monitor
SerialMon.println(F("***********************************************************"));
SerialMon.println(F(" You can now send AT commands"));
SerialMon.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
SerialMon.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
SerialMon.println(F("***********************************************************"));
while(true) {
if (SerialAT.available()) {
delay(1000);
SerialAT.println("ATID");
SerialMon.write(SerialAT.read());
}
if (SerialMon.available()) {
SerialAT.write(SerialMon.read());
}
delay(0);
}
}
Code for item 2:
//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
#define TINY_GSM_MODEM_XBEE
#define SerialMon Serial
HardwareSerial SerialAT(2);
#define TINY_GSM_DEBUG SerialMon
void setup() {
SerialMon.begin(115200);
SerialAT.begin(9600);
SerialBT.begin("ESP32testBLMfalse"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
// Access AT commands from Serial Monitor
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
delay(1000);
}
My issue was when I tried to combine these. See, I wanted to know if it was possible to open a Bluetooth connection with the ESP32 and send the AT commands from the phone app to the XBEE connected to it on UART2. This is what I'm currently doing. The command looks like it sends fine, but my serial output on reads:
"
The device started, now you can pair it with bluetooth!
10:44:04.546-> OK????????????????????????????????????????????????????????????????????????????????????
"
not sure if it's due to the bit rate, let me know if anyone can assist.
Thank you
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
#define TINY_GSM_MODEM_XBEE
#define SerialMon Serial
HardwareSerial SerialAT(2);
#define TINY_GSM_DEBUG SerialMon
void setup() {
SerialMon.begin(115200);
SerialAT.begin(9600);
SerialBT.begin("ESP32testBLMfalse"); //Bluetooth device name
delay(1000);
SerialAT.print("+++"); while (SerialAT.available()) {SerialMon.write(SerialAT.read());}
delay(1000);
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
// Access AT commands from Serial Monitor
if (SerialBT.available()) {
delay(1000);
Serial.write(SerialAT.read()); //send phone input to xbee
}
if (SerialMon.available()) {
SerialAT.write(SerialBT.read()); //send xbee output to phone
SerialAT.write(SerialMon.read()); //send xbee output to serial monitor
}
delay(1000);
}
I was expecting
Samsung phone [input] --BlueTooth--> ESP32 --UART2-> Xbee
Xbee [output] --UART2--> ESP32 serial monitor --BLueTooth-->Samsung phone
I received yesterday my brand new Arduino MKR GSM 1400 and started playing around with today.
However, I'm having trouble stablishing the connection with the SIM card. I'm using the "ReceiveSMS" example from the MKRGSM library (code below), but the execution is getting stuck at the gsmAccess.begin(PINNUMBER) command.
Using AT commands and the debug mode, I got the following description for the error message:
AT+CPIN?
+CME ERROR: SIM not inserted
I have tried connecting with 3 different SIM cards, all tested beforehand with a smartphone and confirmed to be functional. I have tried removing the PIN, but still got the same error.
Does anybody have any idea on what could be going wrong?
Thanks in advance
Code:
// include the GSM library
#include <MKRGSM.h>
#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[] = SECRET_PINNUMBER;
// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
// Array to hold the number a SMS is retreived 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 connected = false;
// Start GSM connection
while (!connected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
connected = true;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
}
I am working on a project for which I need to get a panel of 7 buttons to light up led strips on a display about 5m away. So far I have made it so I can control 1 led strip with one button and this works well. I am now confused on how to get the other 6 to connect to the same arduino via BLE. The idea is to have one arduino with all the buttons connected, then 1 arduino for each led strip. You press button 1 on the button arduino and this sends a signal to the display 1 arduino, lighting the display.
Here is my code so far, what would I need to do to it to add multiple buttons in ?
Thanks !!
//this code is loaded onto the board that is connected to the led strip
//if the code doesnt work it seems to kick start it by opening the serial monitor and then it will connect, not sure why this is
#include <ArduinoBLE.h>
#include <Adafruit_DotStar.h>
#include <SPI.h>
#define NUMPIXELS 144 // Number of LEDs in strip
#define BUTTON_PIN 9 //pin the button is on
#define DATAPIN 4 //the pin the data is plugged into
#define CLOCKPIN 5 //the pin the clock wire is plugged into
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // adress of the ledstrip that is referenced in the other set of code
Adafruit_DotStar strip(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
const int ledPin = 2; // pin to use for the LED
void setup() {
// set LED pin to output mode
pinMode(ledPin, OUTPUT);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
// set advertised local name and service UUID:
BLE.setLocalName("LED");
BLE.setAdvertisedService(ledService);
// add the characteristic to the service
ledService.addCharacteristic(switchCharacteristic);
// add service
BLE.addService(ledService);
// set the initial value for the characeristic:
switchCharacteristic.writeValue(0);
// start advertising
BLE.advertise();
Serial.println("BLE LED Peripheral");
strip.begin();
strip.show(); //pixels to 'off'
}
uint32_t white= strip.Color(255, 255, 255); //colour you want the lights
uint32_t off= strip.Color(0, 0, 0); //colour 'off'
void loop() {
// listen for BLE peripherals to connect:
BLEDevice central = BLE.central();
// if a central is connected to peripheral:
if (central) {
Serial.print("Connected to central: ");
// print the central's MAC address:
Serial.println(central.address());
// while the central is still connected to peripheral:
while (central.connected()) {
// if the remote device wrote to the characteristic,
// use the value to control the LED:
if (switchCharacteristic.written()) {
if (switchCharacteristic.value()) { // any value other than 0
strip.fill(white, 0, 144); //fill(Color,first pixel,last pixel)
strip.setBrightness(5); //set the brightness of the leds here, would keep about 40, doesnt like anything above that
strip.show(); //update the leds
delay(7000); //time you want the LEDs
strip.fill(off, 0, 144); //turns off leds
strip.setBrightness(0);
strip.show();
} else { // a 0 value
strip.fill(off, 0, 144);
strip.setBrightness(0);
strip.show();
}
}
}
// when the central disconnects, print it out:
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
}
}
//this code gets loaded onto the button board
#include <ArduinoBLE.h>
// variables for button
const int buttonPin = 2;
int oldButtonState = LOW;
void setup() {
// configure the button pin as input
pinMode(buttonPin, INPUT);
// initialize the BLE hardware
BLE.begin();
Serial.println("BLE Central - LED control");
// start scanning for peripherals
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); //Put the adress of what you want the button to control here
}
void loop() {
// check if a peripheral has been discovered
BLEDevice peripheral = BLE.available();
if (peripheral) {
// discovered a peripheral, print out address, local name, and advertised service
Serial.print("Found ");
Serial.print(peripheral.address());
Serial.print(" '");
Serial.print(peripheral.localName());
Serial.print("' ");
Serial.print(peripheral.advertisedServiceUuid());
Serial.println();
if (peripheral.localName() != "LED") {
return;
}
// stop scanning
BLE.stopScan();
controlLed(peripheral);
// peripheral disconnected, start scanning again
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
}
}
void controlLed(BLEDevice peripheral) {
// connect to the peripheral
Serial.println("Connecting ...");
if (peripheral.connect()) {
Serial.println("Connected");
} else {
Serial.println("Failed to connect!");
return;
}
// discover peripheral attributes
Serial.println("Discovering attributes ...");
if (peripheral.discoverAttributes()) {
Serial.println("Attributes discovered");
} else {
Serial.println("Attribute discovery failed!");
peripheral.disconnect();
return;
}
// retrieve the LED characteristic
BLECharacteristic ledCharacteristic = peripheral.characteristic("19b10001-e8f2-537e-4f6c-d104768a1214");
if (!ledCharacteristic) {
Serial.println("Peripheral does not have LED characteristic!");
peripheral.disconnect();
return;
} else if (!ledCharacteristic.canWrite()) {
Serial.println("Peripheral does not have a writable LED characteristic!");
peripheral.disconnect();
return;
}
while (peripheral.connected()) {
// while the peripheral is connected
// read the button pin
int buttonState = digitalRead(buttonPin);
if (oldButtonState != buttonState) {
// button changed
oldButtonState = buttonState;
if (buttonState) {
Serial.println("button pressed");
// button is pressed, write 0x01 to turn the LED on
ledCharacteristic.writeValue((byte)0x01);
} else {
Serial.println("button released");
// button is released, write 0x00 to turn the LED off
ledCharacteristic.writeValue((byte)0x00);
}
}
}
Serial.println("Peripheral disconnected");
A typical way of doing this with BLE would be for the button to be the Peripheral and the LED strip to be the Central. The Central would connect to the Peripheral and subscribe to notifications on the "button" characteristic. Typically libraries/hardware aren't setup to have multiple Centrals connected at the same time to one Peripheral. This would seem to rule out doing it this way with your required hardware setup.
An alternative would be to have the buttons as the Central and the LED strips as the Peripheral. The Central would already know the details of the Peripheral device and initiate a connection and then do a write when a button is pressed. I would expect there to be a lot of lag between the button being pressed and something happening on the LED strip with this setup.
Another alternative is to do this with connection-less BLE, if security isn't a concern. The button board could act as a BLE beacon and you could encode information about which button has been pressed in the Service Data or the Manufacturer Data. The LED strips would be scanners reading the data from the beacon. I am not very familiar with BLE libraries on Arduino, there appears to be the command to set the Manufacturer Data but I couldn't find any command to read the data.
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"
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.