I have a problem when I try to use SoftwareSerial in a class..
Here my detail My class
class MyEsp8266
{
protected:
SoftwareSerial *esp8266;
public:
MyEsp8266(SoftwareSerial *_esp8266){
esp8266 = _esp8266;
}
void begin(int baud){
esp8266->begin(baud);
}
String testAT(){
esp8266->println("AT");
return esp8266->readString();
}
}
My Arduino code
#include <SoftwareSerial.h>
#include "MyEsp8266.h"
// the setup function runs once when you press reset or power the board
SoftwareSerial _esp(10, 11);
MyEsp8266 wifi(&_esp);
void setup() {
Serial.begin(9600);
wifi.begin(115200);
Serial.println(wifi.testAT());
}
It doesn't log anything But when I have used all code in Arduino code it worked.
#include <SoftwareSerial.h>
// the setup function runs once when you press reset or power the board
SoftwareSerial _esp(10, 11);
void setup() {
Serial.begin(9600);
_esp.begin(115200);
_esp.println("AT");
Serial.println(_esp.readString());
}
Thank any tips. Regards.
1 Answer 1
This is more of a work-around than a solution, but the code you're trying to get to work, worked for me once I changed
wifi.begin(115200);
to
wifi.begin(9600);
(sorry I don't have enough karma to just comment)
answered Mar 13, 2017 at 22:24
-
Hi baud 115200 worked with secondary code.HoangHieu– HoangHieu2017年03月14日 02:55:15 +00:00Commented Mar 14, 2017 at 2:55
-
I agree! and when testing your desired block of code, I got it to output the test line by changing the baud from 115200 to 9600.pizzaisdavid– pizzaisdavid2017年03月14日 03:02:15 +00:00Commented Mar 14, 2017 at 3:02
-
I think that means your Wifi module use baud 9600.HoangHieu– HoangHieu2017年03月14日 03:08:27 +00:00Commented Mar 14, 2017 at 3:08
-
To clarify, I was using the bluetooth HC-05 which a quick Google search tells me It can go up to 1382400. But besides, I tried both code samples, the second worked without modification (meaning my hardware can handle 115200) and then when I tried the first, and once I changed the baud to 9600 it worked. Did adjusting the baud rate on the first code sample not fix the problem for you?pizzaisdavid– pizzaisdavid2017年03月14日 03:13:09 +00:00Commented Mar 14, 2017 at 3:13
lang-cpp
wifi.testAT();
...?