I'm using WiringPi's library to read information from my Arduino on my Raspberry Pi 3b. The RPi is connected to the Arduino as so:
RPi <-----> Arduino
8 (TX) <-> 17 (RX2)
10 (RX) <-> 16 (TX2)
I'm doing a very simple test to make sure it works. From my Arduino, I have the following code:
void setup()
{
Serial2.begin(9600);
}
void loop()
{
Serial2.write("Just a test");
}
Now, for my C code on the Pi:
msgLength = serialDataAvail(fd);
printf("%i \n",msgLength);
read(fd,ArduinoMsg,255);
printf("%s \n", ArduinoMsg);
I removed everything else so it's easier to read and gets straight to the point.
Here's My Issue:
serialDataAvail is suppose to return the number of bytes it has to read BUT it always returns 0. No matter what. The thing is, it still outputs values, as can be seen in the image below:
./Receive
is just the name of my C code. I have Transmit
and Receive
and am only having issues with Receive
now.
My Thoughts:
Since it keeps outputting Putty every two tries, I believe maybe the SSH program is somehow effecting the serial communication.
I have searched around to find why the function serialDataAvail()
is giving me a 0 when there is clearly something in the buffer but could not find any answers.
EDIT
I experimented with minicom -b 9600 -o -D /dev/ttyAMA0
and I am receiving the characters from the Arduino clearly. Which means there is an issue with my code. When I figure it out, I will post it for those who run into similar issues in the future.