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

Serial Reading Gibberish (if anything at all) #306

Open
RembiTime opened this issue Dec 3, 2024 · 0 comments
Open

Serial Reading Gibberish (if anything at all) #306

RembiTime opened this issue Dec 3, 2024 · 0 comments

Comments

@RembiTime
Copy link

Hello!

I’ve been trying to get this library to work for hours and can’t figure something out. I’m using an Arduino Nano and have a very simple program running on it that just prints out “Hi” every second, along with a very simple infinite loop to print out whatever the Arduino sends in (code attached below). For some reason, no matter if I change the length of the string that the Arduino sends and how many bytes are available, the Arduino always outputs 4 seemingly random bytes and then stops each second. Any ideas why this could be?

Example output:

Port opened successfully
40
6f2a6c20
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
6f2a6c20
0
0
0
0
0
0
0
0
0
8
6f2a6c20
0
0
// Etc...

Arduino code:

void setup() {
// initialize serial:
Serial.begin(9600);
}

void loop() {
Serial.println("Hi");
delay(1000);
}

C++ code:

#include "include/serial/serial.h"
#include
#include "thread"
int main()
{
serial::Serial my_serial("/dev/cu.usbserial-210", 19200, serial::Timeout::simpleTimeout(3000));

if (my_serial.isOpen())
{
    std::cout << "Port opened successfully" << std::endl;
}
else
{
    std::cout << "Port failed to open" << std::endl;
}
my_serial.flushOutput();

while (true) {
    printf("%d\n", my_serial.available());
    if (my_serial.available() > 0) {
        std::string response = my_serial.read(my_serial.available());
        printf("%x\n", response);
    }
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

}

Thank you!

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

1 participant