I am trying to get an Arduino Uno to send data via Sigfox. Using a Libelium Xbee Shield and Sigfox Module for Arduino (Cooking Hacks).
I tried to send a string using the example found in the Arduino library. The Arduino sketch is simple:
#include <Wire.h>
// Cooking API libraries
#include <arduinoClasses.h>
#include <arduinoUART.h>
#include <arduinoUtils.h>
#include <arduinoSigfox.h>
// Pin definition for Sigfox module error LED:
const int error_led = 13;
//////////////////////////////////////////////
uint8_t socket = SOCKET0; //Asign to UART0
//////////////////////////////////////////////
uint8_t error;
void setup()
{
Serial.begin(9600);
pinMode(error_led, OUTPUT);
//////////////////////////////////////////////
// 1. switch on
//////////////////////////////////////////////
error = Sigfox.ON(socket);
// Check status
if( error == 0 )
{
//"Switch ON OK"
digitalWrite(error_led, LOW);
Serial.println("Sigfox Switch ON -> SUCCES");
}
else
{
//"Switch ON ERROR"
digitalWrite(error_led, HIGH);
Serial.println("Switch Switch ON -> FAILED");
}
//////////////////////////////////////////////
// 2. send data
//////////////////////////////////////////////
// Send 12 bytes at most
error = Sigfox.send("000102030405060708090A0B");
// Check sending status
if( error == 0 )
{
//"Sigfox sending -> SUCCES"
digitalWrite(error_led, LOW);
Serial.println("Sigfox sending -> FAILED");
}
else
{
//"Sigfox packet sent ERROR"
digitalWrite(error_led, LOW);
Serial.println("Sigfox packet sent ERROR");
}
}
void loop()
{
//////////////////////////////////////////////
// 3. sleep
//////////////////////////////////////////////
}
The output on Serial port is the following:
AT
Sigfox Switch ON -> FAILED
AT$SF=000102030405060708090A0B
Sigfox sending -> FAILED
Connection between the Sigfox module and the board seems to be OK, because Sigfox.getID() is working, and the correct ID is retrieved. Also subscription of the device on the Sigfox platform seems to be OK.
How can I debug this? I have no idea how to start a diagnosis: something in the libraries? something in the sending? something in the hardware?. All help on this is appreciated.
Please double check Arduino TX is connected to Sigfox RX, and Arduino RX is connected to Sigfox TX
Check also, that the module has VCC on pin 1, and GND on pin 9.
If it still don't work, it's probably because there is something else connected to RX and TX lines. Remove it.
Personnaly, I put a logic analyser on these lines to check the dialog.
for the "ON": AT\r\n is sent, and "OK\r\n" is answered.
Hope this helps
The problem was relatively simple to solve. It turns out that it is not possible to run the combination Arduino/Xbee/Sigfox with the serial cable connected (I used it for power, and for sending debugging info to my computer).
All I had to do was:
put switch to USB
upload new code via serial cable
unplug the serial cable
put switch to Xbee
power the arduino via the 12V jacket (or other power input)
Then it works.
Related
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);
}
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.
Goal: Send two integer values from Arduino Nano to internet via ESP8266 using Arduino IDE
I am new to embedded programing and currently working on a project which sends some integer value from Arduino analog pins to an online database (IP address, port) via esp8266.
At this moment I know how to individually send data from ESP8266 to an IP keeping ESP in client mode. But I don't know how to transfer data generated at Arduno Nano to ESP8266.
#include <ESP8266WiFi.h>
#include<Wire.h>
const char *ssid = "SSID";
const char *password = "asdfghjkl";
const char* host = "192.222.43.1";
int portNum = 986;
WiFiClient client;
WiFiServer server(portNum);
void setup() {
Serial.begin(115200);
Wire.begin();
delay(10);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("WIFI OK");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
Serial.println("Connected to Wifi");
}
String message="";
void loop() {
message = "12,13"; // Message to be sent to ESP8266
if(!client.connected())
{
client.connect(host,portNum);
}
if(message.length()>0)
{
Serial.println(message);
client.println(message);
message="";
}
I can understand I would have to connect the TX-RX pin of Arduino - ESP to pass the data. But for some reason I am not able to make it work.
I would really appreciate if someone can help me understand the process with a simple example.
Thanks.
PS: The reason I had to use Arduino is because the sensor I am using need 2 analog Pins and ESP just have 1.
You connect Arduino Tx to Esp Rx
You connect ESP Tx to your serial device to your PC (so you can read the messages from the ESP in your Terminal window)
On the ESP you use the Wire library you have loaded.
You use the Serial object to listen for incoming data on the ESP's Rx pin.
void loop()
{
while (Serial.available())
{
Do something;
}
}
This works exactly the same as Arduino to Arduino serial comms and there is a nice tutorial here:
Arduino to Arduino comms
WARNING: ESPs use 3.3V and Arduinos use 5V on the Tx and Rx pins. You must not allow 5v to reach the pins of the ESP or it may burn out.
This tutorial shows a safe wiring diagram.
safe wiring diagram
1) Try this sample: simple sample that looks good
2) You have a logic problem in your loop function
a) Your message will be send out as fast as possible because after you leave the loop function you will enter the function again
b) You don't wait for incoming data
I hope the sample helps: I didn't try it because I directly used AT comands instead.
I have a ladyada xbee adapter on the computer side and an arduino xbeeshield which I am trying to communicate with over wireless. Both xbees are configured correctly in that I can receive data from the xbeeshield to the computer. However it doesn't work the other way i.e. xbeeshield does not echo a byte sent from the computer serially. Any idea what I might be doing wrong? (Note: When I connect the arduino board to the computer using USB cable, the echo program works just fine. It seems to be a problem in wireless mode only)
processing code
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
Serial.print((char) Serial.read());
delay(10);
}
}
I am just sending keystrokes from computer and waiting for a reply. I am not getting any.
I use the code I answered to the following question in regards to sending serial bytes from PC to Xbee/Arduino. It's been working fine for months. Ensure you've configured both your Xbee modules on the PC and Arduino side. Ensure your PAN ID's are the same as well.
Arduino making decision according to a packet received from serial port
What version of the Xbee modules are you using? My code works with Series 1 but should work with newer versions as well.
Try using softwareSerial library and connecting Tx and Rx to pin 4 and 2. Run the following sketch and tell me what happens. Change the Baudrate value to match your own
#include <SoftwareSerial.h>
uint8_t pinRx = 2 , pinTx = 4; // the pin on Arduino
long BaudRate = 57600; // Please set your Baudrate. It should match the one in XC-TU
char GotChar, getData;
// Xbee SoftwareSerial initialization
SoftwareSerial xbee(pinRx, pinTx); // RX, TX
void setup()
{
Serial.begin(9600);
Serial.println( "Welcome to the XBee Communication Test" );
Serial.print("BaudRate:");
Serial.println(BaudRate);
Serial.print(" Rx Pin#");
Serial.println(pinRx,DEC);
Serial.print(" Tx Pin#");
Serial.println(pinTx,DEC);
// set the data rate for the SoftwareSerial port
xbee.begin( BaudRate );
xbee.println("Setup Completed!");
}
void loop()
{
if (Serial.available())
{
GotChar = Serial.read();
xbee.print(GotChar);
Serial.print(GotChar);
}
while (xbee.available()>0)
{
Serial.println("Ohohoh");
getData = xbee.read();
Serial.print(" Received: );
Serial.print(getData);
Serial.println();
if(getData == 'a')
{
Serial.println(" sbam");
}
else if(getData == 'b')
{
Serial.println(" sbo");
}
}
}
Upload the program and open the serial monitor. Do you get the 'Setup completed' message on the computer? What happens if you send 'a' or 'b' from the Pc to the Arduino?