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

Software serial support #20

Closed
redemption95 opened this issue Jul 26, 2021 · 2 comments
Closed

Software serial support #20

redemption95 opened this issue Jul 26, 2021 · 2 comments

Comments

@redemption95
Copy link

Hi @lexus2k & contributors,
I have a situation where I want to reliably send high-speed data from RPi and Arduino.
The problem is I am using an Arduino Nano which has one HW Serial.
The problem is I cannot connect the RPi to the HW Serial because it creates issues in uploading
sketches with the Serial USB, so I am using Software Serial to communicate with the Pi.
Now exploring very few solutions I stumped across this beautiful library as it will serve the purpose
of the Pi communicating with TinyProto in python as well.
But I see now the library uses only Hardware Serial library and provides hardware redirects
beginToSerialX() wehre X-> No of serial ports.
Is there any issue with adding something like
beginToSoftwareSerial(Rx, Tx). and begin with SoftwareSerial.
Please let me know if is possible through some code hack in the stable version.
I would really like to see this as an official feature.
Let me know what you think about it.

Thank you,
Sasank Panda

@lexus2k
Copy link
Owner

lexus2k commented Jul 26, 2021

Hi Sasank,

The library is flexible enough to let you use SoftwareSerial without any changes to the library itself.
See how beginToSerialX method is implemented inside the library:

    inline void beginToSerial1()
    {
        begin([](void *p, const void *b, int s) -> int { return Serial1.write((const uint8_t *)b, s); },
              [](void *p, void *b, int s) -> int { return Serial1.readBytes((uint8_t *)b, s); });
    }

Thus, instead of calling beginToSerialX method in your sketch, use can call just begin method with your own implementation of callbacks:

    #include <SoftwareSerial.h>
    SoftwareSerial mySerial(2, 3);
    ...
    proto.begin([](void *p, const void *b, int s) -> int { return mySerial.write((const uint8_t *)b, s); },
              [](void *p, void *b, int s) -> int { return mySerial.readBytes((uint8_t *)b, s); });

Let me know, if you have any issues with the example above.
Also, I would recommend to carefully test Software Serial library communication, because unlike Hardware implementation, the Software one may miss some bits due to higher load off AVR MCU.

Best regards,
Alexey

@redemption95
Copy link
Author

Thank you @lexus2k ,
I was unsure of the implementation but now I have a clear idea.
I will try to implement this and let you know of any issues.
Thanks for the prompt response and direction.
Thank you,
Sasank Panda

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