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

NeoSWSerial does not *write* to multiple instances without setting listen() #57

Open
eclab opened this issue Jan 3, 2024 · 1 comment

Comments

@eclab
Copy link

eclab commented Jan 3, 2024

listen() is notionally for reading, as only one software instance can listen at a time.

However, listen() is also required on NeoSWSerial for writing, or else everything you write out will be written out to the last instantiated NeoSWSerial regardless of which NeoSWSerial instance you wrote to.

Example code below. (Note this code also works around another NeoSWSerial error: you must have a valid pin on RX or it won't write out TX properly. You can't add 255 or whatnot).

#include <NeoSWSerial.h>

#define CV_POT_IN1    A2    // CC 1 Value
#define CV_POT_IN2    A1    // CC 2 Value
#define CV_POT3       A0    // CC 3 Value
#define CV_IN3        A3    // PORT 2
#define CV_AUDIO_IN   A4    // PORT 3
#define CV_AUDIO_OUT  11    // MIDI Clock (only when between start/continue and stop)
#define CV_GATE_OUT   8     // PORT 1
#define SERIAL_1_RX    5   // Blank Serial Pin
#define SERIAL_2_RX   6   // Blank Serial Pin
#define SERIAL_3_RX   7   // Blank Serial Pin

NeoSWSerial mySerial1(SERIAL_1_RX, CV_AUDIO_IN);
NeoSWSerial mySerial2(SERIAL_2_RX, CV_IN3);
NeoSWSerial mySerial3(SERIAL_3_RX, CV_GATE_OUT);


void setup() 
{
    mySerial1.begin(31250);
    mySerial2.begin(31250);
    mySerial3.begin(31250);

}

void write(NeoSWSerial* sw, uint8_t a, uint8_t b, uint8_t c)
  {
    // THIS LISTEN IS REQUIRED
    sw->listen();

    sw->write(a);
    sw->write(b);
    sw->write(c);
    }

void loop() {

    write(&mySerial1, 0x90, 60, 127);

  delay(1000);    

    write(&mySerial1, 0x80, 60, 127);
    write(&mySerial2, 0x90, 62, 127);

  delay(1000);    

    write(&mySerial2, 0x80, 62, 127);
    write(&mySerial3, 0x90, 64, 127);

  delay(1000);

    write(&mySerial3, 0x80, 64, 127);
}
@eclab eclab changed the title NeoSWSerial does not *write* to multiple instances without setting *listen()* NeoSWSerial does not *write* to multiple instances without setting listen() Jan 3, 2024
@KeerthiNadella
Copy link

I'm not able to read from mutliple neoswserial instances. can u help me with this

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