So far I connected the GPS to the standard serial port of the Raspberry Pi (Rx/Tx), the IMU to the I2C lines and the Sonar to the USB port. But I will also need a serial port for my radio. So that is one port short. The solution to this could be using a 'software serial port', as you can easily get on any Arduino. But that's not so simple on the Pi. I could find just one library that supports a software serial port : PiGPIO. And that only supports reading. But that could be enough, as I can use that to read the GPS.
And that works surprisingly well. Connect the Tx of the GPS to GPIO18, and test it using the following code :
#include <iostream>
#include <stdio.h>
#include <pigpio.h>
int main(int argc, char *argv[])
{
char serial_buff[1024];
int chars_read =0;
if (gpioInitialise() < 0) return 1;
gpioSerialReadOpen(18,9600,8);
while(true)
{
chars_read=gpioSerialRead(18,serial_buff,1024);
if(chars_read>0){for(int i=0;i<chars_read;i++){printf("%c",serial_buff[i]);}}
}
gpioTerminate();
}
Works great. There is only one drawback in using the pigpio library: it needs root privilege to run. So Every time I start it from the Code::Blocks IDE, it refuses to run, and I have to open a terminal and enter the 'sudo' command to start it. The solution to that appears to be starting Code:Blocks from the XTerm console using 'sudo codeblocks'. That sometimes works, but most of the time gives me a 'Failed to init GTK+' error. But that could be caused by the fact I'm working through Remote Desktop.
So now I have GPS input, and the standard Tx/Rx serial port available for other purposes.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.