-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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!