Using XBee with Arduino - arduino

I use Xbee in my project with arduino. I have set up Xbee configuration(i can send massge in xctu serial consol), but i have problems with arduino code. I try to use "SoftwareSerial" library, but it doesn't work properly. For example I send data using Xctu, but Xbee connected to arduino cannot receive data. Can you please help me with receiver and transmiter arduino code? Thank you, in advance.
The code:
#include <SoftwareSerial.h>
#define rxPin 1
#define txPin 0
SoftwareSerial xbee = SoftwareSerial(rxPin, txPin);
void setup(){
xbee.begin(9600);
Serial.begin(9600);
//Serial.println("Starting XBee Comunication");
xbee.listen();
}
void loop(){
if(Serial.available()){
xbee.write(Serial.read());
}
else{
Serial.println("not available");
}
if(xbee.available()){
byte x = xbee.peek();
Serial.println(x);
}
else{
Serial.println("none to read");
}
delay(2000);
//Serial.println(rec);
}

Some quick debugging tips:
Disconnect the XBee and short your TX and RX pins together. Make sure you read back what you send.
Are you sure you have the TX and RX pins connected to the XBee module correctly? TX out of the Arduino goes to RX of the XBee and vice versa.
Have you powered the XBee module correctly? XCTU should have support for finding nodes on the network and interacting with them. Make sure the module is powered up and responding on the network.

Related

5volt Arduino Pro Mini Not Able to Drive 5 Volt actuator But The same work perfectly Done by Arduino Uno

I want to drive an actuator from 5 volt Arduino pro mini and it's control by Bluetooth signal from mobile .
circuit detail:
1)Arduino Promini 5 volt
2) Hc05 Bluetooth Module
3)5volt Actuator
I was powering 11.8 Volt directly to the RAW pin of Arduino pro mini .
When It was receiving 1 or 0 it is unable to control the actuator and after connecting the data pin of actuator with pin 13 of arduino pro-mini the flash light continuously blinking
But Above same operation perfectly done by Arduino Uno Board. So is there any possible to control the actuator using arduino promini over bluetooth signal. Reason behind I am using Arduino pro mini instead of Arduino Uno it's took less space.
Arduino Code:
#include<SoftwareSerial.h>
SoftwareSerial BT(2, 3);
#include <Servo.h>
Servo myservo;
int ServoPin =13;
void setup()
{
Serial.begin(9600);
myservo.attach(ServoPin);
pinMode(ServoPin, OUTPUT);
digitalWrite(ServoPin, LOW);
myservo.write(40);
// set digital pin to control as an output
pinMode(9, OUTPUT);
// set the data rate for the SoftwareSerial port
BT.begin(9600);
// Send test message to other device
BT.println("Hello from Arduino");
}
char a; // stores incoming character from other device
void loop()
{
if (BT.available())// if text arrived in from BT serial...
{
a=(BT.read());
Serial.println(a);
if (a=='1')
{
digitalWrite(9, HIGH);
BT.println(" You have to turn oN the LED/servo| I got the command : 1 ") ;
Serial.println("I got the command :");
Serial .println(a);
myservo.write(180);
a=' ';
}
else if (a=='0')
{
myservo.write(40);
digitalWrite(9, LOW);
BT.println(" You have to turn Off the LED!/servo| I got the command :0");
Serial.println("I got the command :");
Serial .println(a);
a=' ';
}
}
}
i think the issue is with the current. first check how much power is required to drive the actuator. if the current is insufficient you can use ULN2003 it's a relay driver ic but you can use it for your ckt if you are less in space you can use single darlington pair.

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.

master slave communication between two attiny 85 IC

Is it possible to communicate between two ATtiny85? I can use my Arduino to communicate with ATtiny85 by using Arduino Uno as the master and ATtiny85 as a slave. But I want to use one ATtiny85 as the master and one as a slave. Is this possible ?
I am not able to understand the examples given in TinyWireM library. I want a simple master and slave code for communication. For example, master should ask for 1 integer value and slave should reply.
My slave code :
#define I2C_SLAVE_ADDRESS 0x14 // Address of the slave
#include <TinyWireS.h>
int i=0;
void setup()
{
TinyWireS.begin(I2C_SLAVE_ADDRESS); // join i2c network
TinyWireS.onRequest(requestEvent);
}
void loop()
{
TinyWireS_stop_check();
}
void requestEvent()
{
if(i==1000)
{
TinyWireS.send(1);
i=0;
}
else
i++;
}
My master code
#include <TinyWireM.h>
#define DS1621_ADDR 0x14
void setup()
{
TinyWireM.begin();
pinMode(4, OUTPUT);
}
void loop()
{
TinyWireM.requestFrom(DS1621_ADDR,4); // Request 1 byte from slave
int tempC = TinyWireM.receive();
if(tempC)
{
digitalWrite(4, HIGH);
delay(1000); // wait for a second
digitalWrite(4, LOW);
delay(1000); // wait for a second
}
if(tempC>1)
{
digitalWrite(4, HIGH);
delay(1000); // wait for a second
digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
}
I tried the above code but still I cannot see the LED blinking. But if I keep slave code as it is and use the following master code on an Arduino then everything works fine.
Arduino Uno code as master.
#include <Wire.h>
float i1=-1, i2=-1;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.requestFrom(4, 1); // request 1 byte from slave address 4
while(Wire.available()) // slave may send less than requested
{
i1 = Wire.read(); // receive a byte as character
Serial.println(i1); // print the character
}
}
connection is and connections are SDA to SCL pins
pin 5 of master attiny85 - pin 7 of slave attiny85
pin 7 of slave attiny85 - pin 5 of master attiny85
I also tried by no cross connecting them. example and connections are SDA to SDA pins
pin 5 of master attiny85 - pin 5 of slave attiny85
pin 7 of slave attiny85 - pin 7 of master attiny85
but still no success.
Yes, it is possible to use 1 ATtiny85 as a master, and another as a slave. The TinyWireM and TinyWireS libraries are both well-written and easy to use.
Handling a request and sending back bytes is as simple as setting the onRequest slave read event handler to a function of your choice that sends the correct data back. There are examples of this in the TinyWireS library.
Did you use the pull-up resistor for both, the SDA and SCL? They are important for the I2C protocol.
FYI: The logic '0' on the either bus is set by device driving actual '0' on the pin. On the other hand, the logic '1' is set on the bus by putting the device pin in the high impedance, in case on the ATtiny, it means setting pin into INPUT direction. When the both, the master and slave set pins to hiZ, the pull-up resistor pulls the voltage on the bus to value representing logic '1'. This solution allows avoiding contention on bi-directional bus (one device driving '1' and second driving '0') than can lead to short-circuit and damaging devices. So, if you don't use the pull-up resistor, the bus will be left floating whenever logic '1' is driven and it will lead to protocol errors.

Serial communication does not work on Intel Galileo Gen 2

I cannot get serial communication working on Intel Galileo Gen 2. I'm using Serial1 on port /dev/ttyS0 assigned to pin 0 and 1. For testing purposes I created loopback on that serial port (connected RX and TX together). Unfortunately, it seems that nothing works. After few test it seems that my board can receive data, but cannot send any.
void setup() {
Serial.begin(9600);
Serial1.begin(19200);
Serial.println("Ready");
}
void loop() {
while(Serial1.available() > 0) {
Serial.print(Serial1.read());
Serial.print(' ');
}
uint8_t buf[3] = {0xC0, 0xFF, 0xEE};
Serial1.write(buf, 3);
delay(2000);
}
I run same sketch with same configuration on Arduino Yún and it worked well. Where the problem could be? Thanks.
For this particular Galileo board, the baud rate for Serial object is always 115200 baud no matter the argument you give it. Since you connected Serial1 to Serial it could be just a synchronisation error due to different baud rate. Did you try to change this Serial1.begin(19200); to this Serial1.begin(115200); ?

Simulation of arduino mega 2560 with GSM Module using proteus

have really been suffering with my simulation! Tried connecting my arduino mega 2560 to COMPIM (used as GSM Module) in my circuit and also loaded sample code but damn! In vain! I wanted to view the data sent in virtual terminal but am getting nothing! and its also complaining of excessive CPU usage.
And thereafter, the messages are displayed as shown below.
Someone please help me out. Am I making a mistake oh? Infact the arduino code for displaying in the simulation is also giving me hard time. The one am using is as shown below.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}
void loop() // run over and over
{
if (mySerial.available())
mySerial.println("Hello, world?");
if (Serial.available())
mySerial.println("Hello, world?");
}
Will b every grateful for any help offered.

Resources