# Serialising a data signal with a Raspberry Pi

I'm working on a project to transmit and receive data by radio. For the transmission, I'm using a Raspberry Pi 3 and the NTX2B transmitter for the transmission. For the receiving end, I am using NooElec Mini 2 SDR as the receiver and the CubicSDR program to see a waterfall diagram of the received signal.

I've used instructions from Yannick, Linking an Arduino to a Radiometrix NTX2B Transmitter and Dave Akerman to get as far as I have. The image below shows the circuit diagram (from Dave Akerman).

Sending 1s and 0s using a GPIO port

Initially, rather than connecting the transmitter input to the TX port on the pi, I connected it to one of the GPIO ports, number 18. I instructed port 18 to switch on and off every five seconds, and was able to see the frequency shift on the waterfall diagram on my laptop. :) Success!

from time import sleep
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.OUT)
GPIO.output(26, True)

while 1:
GPIO.output(18, False)
sleep(5)
GPIO.output(18, True)
sleep(5)


Serialising data using the TXD port

The next step was to send data by connecting the NTX2B to the TXD port on the Pi. I was expecting to see a double peak, one for 0, and another for 1 at a higher frequency, on the waterfall diagram. However, I get just a single peak, and so I'm not sure if I'm actually transmitting the data. I tried using setRTS to digitise my signal (similar to the previous experiment), however the waterfall diagram didn't show any change. Can anyone help me with this? :(

import serial
import time
from time import sleep
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.OUT)
GPIO.output(26, True)

ser = serial.Serial("/dev/serial0",
baudrate = 115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1)
ser.setRTS(False)
time.sleep(5)
ser.setRTS(True)
time.sleep(5)
ser.setRTS(False)
time.sleep(5)
while True:
ser.write(b'hello!')
# ser.close()


• Reduce and simplify the problem. Think the Tx port isn't working? Try blinking an LED instead. – Phil Frost - W8II Jul 23 '17 at 11:24
• @PhilFrost-W8II the Tx port is definitely working. I connected the output of the Tx port to the Rx port on the pi, and then wrote a script that reads the data. I got the output h, e, l, l, o as I expected. – bluprince13 Jul 23 '17 at 11:27
• So if it's definitely working, why isn't it working? Check the output voltage with a voltmeter. Simplify. – Phil Frost - W8II Jul 23 '17 at 11:28

Package your data in packets (for example: take 8 byte of data at once). Each time before you start sending, send a preamble byte (e.g. 10101010b==0xAA==170) so that your receiver can find your transmission, and achieve clock synchronization (yep! that's necessary!).