AT works at half for HC05 - arduino

I am currently trying to send my sensor data from my Arduino to an android app made on android studio using an HC05 module for Arduino.
I tried to configure the HC05 as every tutorial on the internet says, but i meet some problems.
I am using the arduino code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
int PotPin = A7;
int Vdata = 15;
void setup() {
Serial.begin(9600);
pinMode(9,OUTPUT); digitalWrite(9,HIGH);
Serial.println("Enter AT commands:");
mySerial.begin(38400);
}
void loop()
{
Vdata = analogRead(PotPin);
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
When I type "AT" in the Serial monitor, it returns me "OK" (that is normal).
But when I try to see the name/the address/the password of the module, it returns me "Error:(0)". The strangest thing is that the command " AT+NAME="NameWanted" " or even " "AT+PWD="4321" " works since it correctly changes the name of the module.
I looked on the internet but I didn't see someone with the same problem as mine, I hope someone will lead me to the solution!
Thanks

I found out what's the problem. My mcu's bauderate was bigger (115200), then my hc05's bauderate (38400). With this bauderate, my MCU sent the messages faster, then hc05 could read it. So, I decreased the bauderate of my MCU and now it's working

Related

Data are not sent between Arduino uno and NodeMcu esp8266 at all time

I am sending data from Arduino UNO R3 to nodeMcu esp8266. In that case sometime data are send properly but at sometime data are are not send by arduino or not get by nodemcu esp8266.Also tx light not blinks after i upload the code to the Arduiono.
enter code here
Code Uploaded to Arduino:
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
SoftwareSerial s(10,11);
SoftwareSerial h(10,11);
int i=0;
void setup() {
// put your setup code here, to run once:
s.begin(9600);
Serial.begin(9600);
}
int f1=0;
int f2=0;
String st="sy";
void loop() {
f1=f1+1;
f2=f2+2;
// put your main code here, to run repeatedly:
StaticJsonBuffer <1000> bf;
StaticJsonBuffer <1000> rec;
JsonObject& root=bf.createObject();
JsonObject& receives=rec.parseObject(h);
if (receives==JsonObject::invalid())
{
Serial.println("no data from nodemcu");
root["data3"]="no data from nide";
}
else
{
root["data3"] = receives["data3"];
//st = (const char*)receive["data3"];
}
root["data1"]=f1;
root["data2"]=f2;
//root["data3"]=st;
if(s.available()>0)
{
root.printTo(s);
Serial.println("send");
}
else
{
Serial.println("NOt Available");}
//i=i+1;
//s.write(i);
delay(1000);
}
In your code thera are two reasons I can spot on the first look:
1 Never use delay in server client applications. Delay stops proccessing and inhibts communication. For more details how to avoid look at the blinkwithoutdelay built in Example in the Arduino IDE.
2. You use ArduinoJSON: This lib is absolute overkill for 99% of the applications it is used for. Don't get me wrong - the lib offers fantastic features, but if not needed this can be regarded as bloat-ware.
I wrote my own simple JSON coding/decoding (~250 lines of code) for a performant application using an Arduino as "Signal generator" and the ESP8266/ESP32 as a webserver. Communication between Arduino and ESPis time critical and so far it works over a year without problems,

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.

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.

CANbus simulation for Automotive purpose

i explain a bit...
I repair Electric powered steering systems for cars, especially Fiat/Alfa/Lancya (Delphi manufacturers) and i'm in need of making some tool to test these reparations, i mean just turning it on for example.
I have researched during some time, and i figured i need Can-bus signals to be simulated as the eps ECU is receiving ignition packets from CAN, here i go..
I need to know what way i could Read/Send CAN packets from/to BUS, i mean what tool or anything else. I have been trying with Arduino UNO + Sparkfun Shield, but i dont get any results, when everything connected, my serial console isnt sniffing any packets, i have connected all correctly i think, tried different bitRates, changed Arduino boards and shield, tried many different examples, i invested lots of hours with no profit... i was using Seat Ibiza 2010 for I+D, connected CAN-H AND CAN-L on OBD PORT, in the CAN lines from radio,etc...
Any idea of what could be wrong is welcome, as new method to make my project.. Thanks in advance!!
Info:
https://dl.dropboxusercontent.com/u/47864432/arduino/IMG_9358.JPG
https://dl.dropboxusercontent.com/u/47864432/canbus/LIBRARYS_USED.rar
There are two potential issues here:
H/W problem
CAN bus library problem
The first step is try loopback test. If all is OK, try CAN bus from any car OBD port, the speed should be 500Kb.
This one tries a couple of bus speeds -- works with sparkfun canbus shield:
#include <SPI.h>
#include <SD.h>
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
const int chipSelect = 9;
File dataFile;
void setup() {
// put your setup code here, to run once:
pinMode(chipSelect, OUTPUT);
Serial.begin(115200); // For debug use
Serial.println("CAN Read - Testing receival of CAN Bus message");
delay(1000);
if (Canbus.init(CANSPEED_500)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok: 500k");
else if (Canbus.init(CANSPEED_250)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok: 250k");
else if (Canbus.init(CANSPEED_125)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok: 125k");
else
Serial.println("Can't init CAN");
delay(1000);
if (!SD.begin(chipSelect)) {
Serial.println("uSD card failed to initialize, or is not present");
return;
}
else {
Serial.println("uSD card initialized.");
delay(1500);
}
dataFile = SD.open("caninfo.txt", FILE_WRITE);
}
void loop() {
tCAN message;
if (mcp2515_check_message())
{
if (mcp2515_get_message(&message))
{
if (dataFile) {
int timeStamp = millis();
//write to uSD card
dataFile.print(timeStamp);
dataFile.print("ID: ");
dataFile.print(message.id, HEX);
dataFile.print(", ");
dataFile.print("Data: ");
dataFile.print(message.header.length, DEC);
for (int i = 0; i < message.header.length; i++)
{
dataFile.print(message.data[i], HEX);
dataFile.print(" ");
}
dataFile.println("");
Serial.println("Writing to SD");
}
else
{
Serial.println("Problem writing to SD");
}
}
}
}
If you want to communicate via CAN with Steering controller for example for an OEM like Delhpi .. this is not possible as the ECU (ELectronic control units) in the communication network are secured and the CAN protocol software decides who can participate and who can't.
As a tester tool you can read the trouble codes but you can't hack it to simulate the Ignition signal etc...

Sending sensor readings over SMS

Simple question regarding 1-wire temp sensor DS18B20 and SIM900 GPRS Shield
I've done quite a bit of reading and googling, but need some support to figure out how to get my DS18B20 temp sensor reading to send via SMS on the GPRS Shield. I have already ran successful sketches to view the temperature readings through the Serial monitor, send an SMS with random text, and send an SMS with just the temperature reading. Now I am looking to combine them into one sketch.
This is my configuration:
Arduino Leonardo (currently using an UNO, but want to use the Leonardo I have here
Seeed Studio GPRS Shield V2.0, with unlocked SIM
Dallas/Maxim DS18B20
Connected via breadboard
Image here: http://i.stack.imgur.com/9YdyW.png
The GPRS Shield is not pictured here, but it is on top of the Arduino, and the jumpers going into the headers on that.
What I would like the code to do is the following:
Send an SMS that says "The temp is currently " and insert the reading after that (see textForSMS below)
Perform this at an interval of every 5 minutes
I know that the string stuff associated with this line "textForSMS = textForSMS + (currentTemp)" in the code below is incorrect, but I can not quite figure out how to fix it.
#include <SoftwareSerial.h>
#include <String.h>
#include <OneWire.h>
#include <DallasTemperature.h>
String textForSMS;
float currentTemp;
SoftwareSerial cellSerial(7,8);
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup()
{
cellSerial.begin(19200); // the GPRS baud rate
Serial.begin(9600); // temp sensor rate
delay(500);
sensors.begin();
}
///SendTextMessage()
///this function is to send a sms message
void SendTextMessage(String message)
{
cellSerial.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode
delay(100);
cellSerial.println("AT + CMGS = \"+1XXXXXX4470\"");//send sms message,
delay(100);
cellSerial.println(message);//the content of the message
delay(100);
cellSerial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
cellSerial.println();
}
void loop()
{
currentTemp = sensors.getTempCByIndex(0);
textForSMS = "Temp is ";
Serial.println(currentTemp);
textForSMS = textForSMS + (currentTemp)
SendTextMessage(textForSMS);
do {} while (1);
}
void ShowSerialData()
{
while(cellSerial.available()!=0)
Serial.write(cellSerial.read());
}
I am buried in tabs in Firefox of projects that are slightly different and don't quite answer the questions above through digging through the code. Any ideas here? I want to be able to build this with some students in a STEM workshop next week so we would really appreciate any pointers.
Thanks!

Resources