XBee S2C and XBee S1 Pro communication - arduino

I have an XBee S1 Pro, which is configured as a coordinator. and an XBee S2C, which is configured as an end-node. Both are loaded with the 802.15.4 firmware. By using XCTU, I sent and received the data in Transparent mode.
I have now configured the end-node to API-1 mode and connected it to an Arduino Nano. I want to read the payload. Here is my Arduino code:
void setup() {
Serial.begin(9600);
Serial.println("Setup done...");
while (!Serial) {;}
}
void loop() {
if (Serial.available()) {
for (int i = 0; i < 8;i++) {
byte discard = Serial.read();
}
Serial.write(Serial.read());
Serial.print(",");
}
When I send 'hello' from the coordinator I get:
Setup done...
FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,FFFFFFFF
,
Is there an easier way to do this like using the Arduino XBee library?
Could someone kindly help me?

Have you confirmed that the two XBee modules are joined to the same network? My understanding was that S1 was just 802.15.4, and S2 was ZigBee. You should probably start your project with identical networking hardware to eliminate that as a source of problems.
I'd recommend following a tutorial and using that code to establish a working starting point for any code you want to write.
Edit: adding some code
First off, you need to have two serial ports. One for your console where you can see the output of Serial.print() and the other for communicating with the XBee module.
Second, start with this loop:
void loop() {
// echo bytes received on XBee module to serial console
if (XBee.available()) {
Serial.write(XBee.read());
Serial.print(",");
}
// echo bytes received on serial console to XBee module
if (Serial.available()) {
XBee.write(Serial.read());
}
}
This way you're dumping every byte you receive, and only calling XBee.read() when there's data available to read.
You might want to keep your XBee module at 9600 baud, but increase your stdio interface (Serial) to 115200 since you're printing more than one character per byte received from the XBee module.

Related

How to use SoftwareSerial with ESP8266

I'm trying to get an ESP8266 to work with Arduino by using PlatformIO. But, I get errors when importing SoftwareSerial.h
Tried: Arduino IDE, PlatformIO, Change baudrate, change port
How can I get SoftwareSerial to work with the ESP8266?
#include <SoftwareSerial.h>
SoftwareSerial BTserial(3, 1); // RX | TX
char Bluetooth_Name = ' ';
void setup()
{
// Arduino IDE serial monitor
Serial.begin(9600);
// HC-05 default serial speed for AT mode is 38400
BTserial.begin(38400);
// Wait for hardware to initialize
delay(1000);
// Print debug string
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTserial.available())
{
reading = BTserial.read();
Serial.println(reading);
}
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
{
reading = Serial.read();
BTserial.write(reading);
}
}
I want to use the SoftwareSerial without errors.
Error code:
Compiling .pio\build\huzzah\lib0be\EspSoftwareSerial_ID168\SoftwareSerial.cpp.o
In file included from C:\Users\Bart\.platformio\lib\EspSoftwareSerial_ID168\src/SoftwareSerial.h:27:0,
from C:\Users\Bart\.platformio\lib\EspSoftwareSerial_ID168\src\SoftwareSerial.cpp:23:
C:\Users\Bart\.platformio\lib\EspSoftwareSerial_ID168\src/circular_queue/circular_queue.h:144:10: error: expected ';' at end of member declaration
bool IRAM_ATTR push(T&& val);
^
Actually the standard software serial library didn't work for me with my NodeMCU v1.0... And in the rare cases when it worked, it was very limited. Maybe check out this library:
ESP 8266/32 Software Serial Library
in platformio.ini you can add the following line to choose a specific version which compiles with the latest released 8266 platform
lib_deps_external =
plerup/espsoftwareserial#5.0.3 ; this version compiles with a standard 8266 platform
Using this way the code is directly fetched from github.

i want to transmit data from avr to pc.whats wrong in below connection or code

connection:
USB to TTL interface modules four pins:
1)0v-volt of avr
2)vcc-5 volt avr
3)TXD-TX of avr
4)RXD-RX of avr
and the USB to TTL serial interface module connected to PC using USB to RS-232 convertor DB9 cable.
below is the code:
#include<avr/io.h>
void UART_transmit(unsigned char data);
int main(void)
{
unsigned char i,message[]="i love india\r\n";
DDRD=0x00;
PORTD=0xFF;
UCSRA=0;
UCSRB=1<<TXEN; // transmitter enable
UCSRC=1<<URSEL | 1<<UCSZ1 | 1<<UCSZ0; // 8 data bit, a stop, none parity
UBRRH=0;
UBRRL=5; // for 9600 baud at 1MHz
while(1)
{
for(i=0;message[i];i++)
{
UART_transmit(message[i]);
}
} // while(1) end
} // main() end
void UART_transmit(unsigned char data)
{
while(!(UCSRA & (1<<UDRE)));
UDR=data;
}
RX of each device must be connected to TX of the other, and vice versa, unless you are using a null modem cable, in which case your connections are correct. You might try using a multimeter and google to determine if your connecting cable is straight or null-modem.
I also recommend that you revise your code as outlined in the manufacturer's application note AVR306: Using the AVR® UART in C. This is the authoritative reference on setting up and using the UART on AVR microcontrollers.

Arduino GSM GPS Shield doesn't do the GSM_READY check

Before you mark this question as duplicate, please note that I have already tried this, this & this
I bought an Arduino UNO R3 & a SIM808 GSM/GPS shield recently. The RX of the Shield is connected to Pin 11 of Arduino, TX to Pin 10 with both the GNDs connected to each other. I have connected my Arduino to my computer with the USB & the shield is connected to an external power supply with a 12V Adapter. Additionally, I have connected the 3.3V of the Arduino to Vcc of the shield.
Following is the sketch I have used:
// Include the GSM library
#include <GSM.h>
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
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 Sender");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
}
void loop() {
Serial.print("Enter a mobile number: ");
char remoteNum[20]; // telephone number to send sms
readSerial(remoteNum);
Serial.println(remoteNum);
// sms text
Serial.print("Now, enter SMS content: ");
char txtMsg[200];
readSerial(txtMsg);
Serial.println("SENDING");
Serial.println();
Serial.println("Message:");
Serial.println(txtMsg);
// send the message
sms.beginSMS(remoteNum);
sms.print(txtMsg);
sms.endSMS();
Serial.println("\nCOMPLETE!\n");
}
/*
Read input serial
*/
int readSerial(char result[]) {
int i = 0;
while (1) {
while (Serial.available() > 0) {
char inChar = Serial.read();
if (inChar == '\n') {
result[i] = '\0';
Serial.flush();
return 0;
}
if (inChar != '\r') {
result[i] = inChar;
i++;
}
}
}
}
Problem here is same as that mentioned in those linked posts.
The condition if (gsmAccess.begin(PINNUMBER) == GSM_READY) never gets executed. Neither does the else part execute.
Serial monitor never goes past SMS Messages Sender.
Please note that I am using AirTel India, I have a fully activated Data Plan & the PIN Number has been changed to 0000.
Would really appreciate if someone could suggest something helpful.
Thanks for your time!!
You cannot power a GSM module from the 3.3V of Arduino! a GSM needs peak currents of 3A (yes, Amps, not milli-amperes). You really need a LiPo battery to power the GSM. You could power a 3V Arduino from the same LiPo battery, actually, if you need a mobile solution, but not the other way around.
Please first check if the module responds with the next code Example Code
Other thing the Supply voltage range must be 3.4 ~ 4.4V, try not using less voltage .
The GSM library of the Arduino is for the Quectel M10 GSM/GPRS module and is not compatible with SimCom SIMxxx modules.
Here is the library that you can use for your SIM808 module https://github.com/MarcoMartines/GSM-GPRS-GPS-Shield (examples included in the repo). Note that this library uses the SIM900 library which allows low level interface with SimCom modules.
For further reading here two adafruit links:
http://wiki.iteadstudio.com/SIM808_GSM/GPRS/GPS_Module
https://www.adafruit.com/products/2637
the shield is connected to an external power supply with a 12V
Adapter. Additionally, I have connected the 3.3V of the Arduino to Vcc
of the shield.
What do you mean by that? You need to supply your shield with the required voltage that can deliver the required amps. And also you need to have a common ground with your arduino.
In addition, if your shield is a 3.3V you need to shift Tx line comming from arduino as well (because it's a 5V) using a voltage divider.
Note that these shields have also a soft power-up button that needs to be connected as well, to allow the code to power up your module.

Booting programs from an Intel Edison board

I just bought an Intel Edison Breakout Board Kit with the Grove Starter Kit Plus I want to write a program which gives the board an IP address, checks for a temperature in a room and if that temperature is exceeded it turns a LED on. I can check what's going on with a RGB display. When I connect the USB OTG port to the my laptop the wifi connection is perfectly detected, the IP address is perfectly received and the temperature control works fine. The program works as I ask for. Now the questions. I would like to execute the same program unplugging the USB connection, so I would like to make this board independent from PC, like if it is a standing alone device
1) if I upload this working program in the board, unplugging the USB and of course giving just the power supply through the jack on the breakout board it does not work anymore and stops on the message "preparing network connection...". But Intel Edison has an integrated wifi module and I really can't understand why it is not able to establish an internet connection anymore without the help of the USB connection with my laptop. What's wrong with it? how to boot and execute this program just with the power supply? This is the setup function() of my program, we don't reach the loop() one so I will not post it
void setup()
{
// ------ LCD IN ACTION ------ //
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// setting the color for the connection
lcd.setRGB(colorR, colorG, colorB);
lcd.print("preparing network connection...");
// scroll 40 positions (string length) to the left
// to move it offscreen left:
for (int positionCounter = 0; positionCounter < 40; positionCounter++)
{
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(350);
}
// ------ SERIAL CONNECTION ------ //
// opening the serial connection
// Serial.begin(9600); // initialize serial communication
// ------ SETTING I/O PINS ------ //
pinMode(potentiometer, INPUT); // angle sensor's pin for input.
pinMode(12, OUTPUT); // set the blue LED pin mode
pinMode(13, OUTPUT); // set the red LED pin mode
pinMode(pinLed, OUTPUT); // set the green LED pin mode
// ------ WIFI CONNECTION CONTROLS ------ //
// check for the presence of the wifi shield:
if (WiFi.status() == WL_NO_SHIELD)
{
// Serial.println("WiFi shield not present");
while(true); // don't continue
}
// check firmware version
String fv = WiFi.firmwareVersion();
// if( fv != "1.1.0" )
// Serial.println("Please upgrade the firmware");
// ------ WIFI CONNECTION ------ //
// attempt to connect to Wifi network:
while (status != WL_CONNECTED)
{
// Serial.print("Attempting to connect to Network named: ");
// Serial.println(ssid); // print the network name (SSID);
// connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 3 seconds for connection:
delay(3000);
}
server.begin(); // start the web server on port 70
printWifiStatus();
where
void printWifiStatus() {
// print the SSID of the network you're attached to:
// Serial.print("SSID: ");
// Serial.println(WiFi.SSID());
colorR = 255;
colorG = 180;
colorB = 0;
lcd.clear();
lcd.setRGB(colorR, colorG, colorB);
lcd.print(WiFi.SSID());
delay(3000);
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
// Serial.print("IP Address: ");
// Serial.println(ip);
colorR = 0;
colorG = 255;
colorB = 0;
lcd.setCursor(0, 1);
lcd.setRGB(colorR, colorG, colorB);
lcd.print(ip);
delay(3000);
/*
delay(5000);
colorR = 180;
colorG = 255;
colorB = 255;
lcd.setRGB(colorR, colorG, colorB);
lcd.noDisplay();
*/
// print the received signal strength:
long rssi = WiFi.RSSI();
// Serial.print("signal strength (RSSI):");
// Serial.print(rssi);
// Serial.println(" dBm");
// print where to go in a browser:
// Serial.print("To see this page in action, open a browser to http://");
// Serial.println(ip);
}
2) always about the execution of pre-loaded programs: if I load the default blink program of ArduinoIDE, unplug the USB and just give the power supply it works perfectly [this one is correctly self-booted, yes] but if I upload the same program with a Serial.begin() and a Serial.print("Arduino blinking") it doesn't work anymore without the USB connection to my laptop [this is why I commented the Serial stuff before]. Is it because the board is so smart to detect that in the first case the serial connection is not really happening?
3) last question about program storage: when I compile a program with the arduino IDE it gives me the percentage of memory used related to the available one for programs
Sketch is using 103.266 byte (1%) of program memory. The limit is 10.000.000 byte
but Intel Edison has a 4GB eMMC so why there are only 10MB available to programs? in which memory are the programs uploaded?
Thanks in advance to those who will try to help
Do you know how can I do to check where is it stored?
You can check your files on serial communication terminal. If you have possible directories that your file could be in, you can use linux commands like:
cd directory and ls
or even you can 'search' the file if you know the name. You may want to check this site.
or you can use SCP, FTP client programs like WinSCP to see the files on your Edison.
if I upload this working program in the board
Are you sure that your program is flashed into persistent memory ? I do not know this board. In most cases this kind of problems comes when your program is only transferred to RAM memory, but not stored in Flash.
Sketch is using 103.266 byte (1%) of program memory. The limit is
10.000.000 byte
10MB RAM, or Flash memory ?
As far as I understand you use Arduino + Edison ?
Which board 10MB limit corresponds to ? Sketch is using 103.266 byte: is it RAM or Flash ?
Try typing these commands in through putty
ifconfig usb0 down
ifconfig wlan0 down
ifconfig usb0 up
ifconfig wlan0 up
that might do it

Sending AT commands to a GSM/GPRS and displaying the reply on a Serial Monitor

I am quite rusty when it comes to Serial ports. I want to send an AT command to a GSM/ GPRS shield connected to my Arduino UNO. The AT command I want to pass in particular is the command to get a networks signal strength.
I am using the SIM900 and SoftwareSerial library to send the command as the GSM library does not compile correctly for me. Meaning I have to use the SoftwareSerial library.
I have this example code from the SIM900 library working that relies on reading inputs from the serial monitor to carry out commands but I need it to be automated and the command to be passed in hardcoded. In this example code, the place of interest is the simplehwread() method.
#include "SIM900.h"
#include <SoftwareSerial.h>
int numdata;
char inSerial[40];
int i=0;
void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(9600))
Serial.println("\nstatus=READY");
else Serial.println("\nstatus=IDLE");
};
void loop()
{
//Read for new byte on serial hardware,
//and write them on NewSoftSerial.
serialhwread();
//Read for new byte on NewSoftSerial.
serialswread();
};
void serialhwread()
{
i=0;
if (Serial.available() > 0) {
while (Serial.available() > 0) {
inSerial[i]=(Serial.read());
delay(10);
i++;
}
inSerial[i]='\0';
if(!strcmp(inSerial,"/END")) {
Serial.println("_");
inSerial[0]=0x1a;
inSerial[1]='\0';
gsm.SimpleWriteln(inSerial);
}
//Send a saved AT command using serial port.
if(!strcmp(inSerial,"TEST")) {
Serial.println("SIGNAL QUALITY");
gsm.SimpleWriteln("AT+CSQ");
} else {
Serial.println(inSerial);
gsm.SimpleWriteln(inSerial);
}
inSerial[0]='\0';
}
}
void serialswread()
{
gsm.SimpleRead();
}
No matter how I modify this code, the command does not get passed in and response displayed while the method here does it but not the way I want it to be done. i.e Direct input. Could anyone assist here?
i have dealt with exactly this scenario at a company with a cellular radio on board. there are many status signals that come over and if not dealt with appropriately these status flags from the cell modem will be lost
you need to look at the data sheets associated with your cell modem and its protocol so you know what flags to watch for at the various steps taken along the way from configuration, to eventual connection to cellular service.
multi-threaded coding techniques must be followed as well.
keep in mind that the comm channel is not ideal and there WILL be failures. provided your coding techniques are sound and you follow protocol requirements, then it should work.
Ron
Boise, ID

Resources