The Raspberry Pi GPIO serial port configuration has changed under Jessie and also with the Raspberry PI 3. By Default serial port is disabled and on RPI 3 Bluetooth made it even made it more confusing to enable Serial Port on GPIO. In this post i’ll describes how to enable serial port on GPIO.

Raspberry pi

As i m not interested in Bluetooth so i m going to disable it and keep GPIO serial. In order to enable serial port edit /boot/config.txt and add enable_uart=1 at the end of file.

Login to your Raspberry pi via putty or any other shell software and run following command to edit /boot/config.txt

Because Bluetooth and serial port on gpio there are two serial port /dev/ttyS0 and /dev/ttyAMA0, by default ttyS0 is serial port and mapped to GPIO pins 14 and 15. Before enable uart and modifying config.txt file:

After modification you should see following:

We are not using our serial port other then communicating to ardunot gateway and receving message and send out messages we need to disable it.

Pre-Raspberry Pi 3

For Raspberry Pi3

Now we need to remove console from cmdline.txt file.

if file contain line or text console=serial0, just remove it, here is example from my RPI 3

Here is example from Raspberry pi B+ model

Last settings to swap serial on Raspberry Pi 3, all pre-Raspberry pi 3 model can ignore this. Edit config.txt file and look for dtoverlay=pi3-miniuart-bt and remove comments, if this line isnt there just add it to config.txt file.

Here are the last few lines from my config.txt file

Pre-RPI 3 Model – Settings

By default, raspberry pi serial port display login screen hence we need to disable this so we can use this serial port. Open inittab file and locate T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 line and comment out it.

Now we need to remove one more line from /boot/cmdline.txt to prevent raspberry pi from sending data during boot to serial port.

Now it’s time to reboot your raspberry pi, once rpi rebooted successfully login via ssh and issue command sudo dmesg, this will bring lots of text but we only need to look for UART line to identify our serial port which in my case is ttyAMA0

Installing dependencies

Login to your raspberry pi via ssh and issue following commands one by one to install Python, PySerial, MSQL-Python for interfacing with serial port from python and save data to MySQL database.

If you want to continue building PiHome with MySensors Serial Gateway please following this Post.