Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't RX doesn't work inside of another C++ class? #31

Closed
smurthas opened this issue Sep 13, 2016 · 0 comments
Closed

Doesn't RX doesn't work inside of another C++ class? #31

smurthas opened this issue Sep 13, 2016 · 0 comments

Comments

@smurthas
Copy link

I've been trying to use the ESP8266 to control an iRobot Create 2 (via software serial). I can interact with the Create directly if I import this library into an Arduino sketch and upload to my Adafruit HUZZAH, however if I try to incorporate this code into another C++ class, I can send but not receive. Here is a trivial example:

// SSWrapper.h

#include "SoftwareSerial.h"

#ifndef SSWrapper_h
#define SSWrapper_h

class SSWrapper {
public:

    SSWrapper();

    // just wrap the basics
    void begin();
    void swWrite(uint8_t b);
    int swRead();
    int swAvailable();

private:
    SoftwareSerial softSerial;
};

#endif /* SSWrapper_h */
// SSWrapper.cpp

#include "SSWrapper.h"
#include <inttypes.h>


SSWrapper::SSWrapper() {
}

void SSWrapper::begin() {
    // just hard code in some values, because that's how I had it set up
    softSerial = SoftwareSerial(12, 5, false, 64);
    softSerial.begin(19200);
}

// these are just pass through
void SSWrapper::swWrite(uint8_t b) {
    softSerial.write(b);
}

int SSWrapper::swRead() {
    return softSerial.read();
}

int SSWrapper::swAvailable() {
    return softSerial.available();
}

And finally, an Arduino Sketch:

#include <SSWrapper.h>

SSWrapper ssw;
void setup() {
  ssw.begin();
}

void loop() {
  // now, the other side has sent some bytes to the ESP, so I expect ssw.swAvailable()
  // to be > 1, but it isn't, it's always 0.

  if (ssw.swAvailable() > 0) {
    byte inByte = ssw.swRead();
    Serial.println("some data:");
    Serial.println(int(inByte));
  }
}

I also tried adding some debug code to the interrupt handler readRx function and it doesn't seem to be getting called.

@dok-net dok-net closed this as completed Mar 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants