Arduino Micro with HC-05: receiving data in weird encoding - arduino

I'm just starting using HC-05 Bluetooth module and having some troubles.
Firstly, I connected HC-05 bluetooth module to Arduino Micro board in programming mode (with Key pulled up) and was able to communicate with it sending AT commands (changed name, password, etc).
After that I was pulled down Key pin to let HC-05 operate normally. I was able to find and connect to it (with new name and password, as expected), and even transmit data in both directions. However what I'm receiving is not what I'm expecting. I'm sending some character and receiving sequence of bytes:
When I send a char I receive sequence of bytes 120 248.
b -> 128 0 248.
c -> 248 0 248.
d -> 0 128 248.
Actually, I've tried few mobile apps (Bluetooth Terminal, Bluetooth Terminal HC-05, Serial Bluetooth Terminal) which provides Bluetooth terminal functionality, and they all are producing different bytes sequences. Ones provided above is for Bluetooth Terminal app. I'm obviously missing something..
Could someone give me direction?
P.S. My latest version of sketch is following:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 8);
void setup() {
pinMode(9,INPUT);
pinMode(8,OUTPUT);
Serial.begin(9600);
while (!Serial);
Serial.println("welcome");
mySerial.begin(38400);
}
void loop() {
if (mySerial.available()) {
while (mySerial.available())
{
char c = mySerial.read();
Serial.print((int) c);
Serial.print(" ");
delay(5);
}
Serial.println("");
}
}

Related

Failed to connect ESP8266: Invalid head to Packet (0xf0) D:

I am working with an arduino, rather learning to use it, I bought the esp8266 module to transmit data over wifi, but every time I upload a script it throws me the following error:
Failed to connect ESP8266: Invalid head to Packet (0xf0)
The selected port does not exist or the board is not connected
I already installed the drivers and libraries, select the COM4 port and checked in the device manager that it is correct.
As I was asked, here is the code I am trying to use.
#include <SoftwareSerial.h>
void setup()
{ Serial.begin(115200);
BT1.begin(115200);
}
void loop()
{ String B= "." ;
if (BT1.available())
{ char c = BT1.read() ;
Serial.print(c);
}
if (Serial.available())
{ char c = Serial.read();
BT1.print(c);
}
}
I connected the arduino via usb, the esp8266 using the breadboard, it is an ESP8266 ESP-01.
I hope you can help me.
(It's my first time on this site, sorry for the lack of info the first time)

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.

XBee S2C and XBee S1 Pro communication

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.

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.

Resources