Wireless Coms with Pi

This month we began to make real progress with the Pi, Alex and Phil transmitted the wind direction using a Telit RF transmitter connected to the Cortex L4’s Tx (Transmitting) pin. An identical Telit was on the other side of the lab connected to the Pi’s UART Rx (Receiving) pin.

 

Image result for stm32l4 mcu clone
L4 Chip

 

To connect the Rx on the Pi, UART had to enabled in the Pi configuration due to it being disabled by default. To change this the following commands were used:

$ cd /boot/  # changes directory to boot

$ ls  # this shows the contents of the boot directory

$ sudo nano config.txt # uses nano to edit config.txt (nano is a text editor in Linux)

At the end of the file UART was enabled: UART = 1, the Pi was restarted to apply changes.

UART: Universal Asynchronous Receiver-Transmitter, part of the computer used to handle asynchronous serial communications.

To wire the Pi, the Tx wire from the Telit was connected to the Rx of the Pi and the Tx of the Pi was connected to Rx of the Telit. Ground was also connected as well as the 3.3V to power the Telit from the Pi.

Pi Uart.png
Pi UART Pinout

 

To display the serial data on the Pi, pyserial needed to be installed. This followed the same procedure as with other programs. To set up the serial port the following code was used in a Python script.

import serial
ser = serial.Serial( # using the serial library
  port =' /dev/ttyS0', # setting the port as com port 0
  baudrate = 9600, # = transfer rate, must match the L4 setting
  parity = serial.PARITY_NONE, # must match the L4 setting
  stopbits = serial.STOPBITS_ONE, # must match the L4
  bytesize = serial.EIGHTBITS, # usually 7/8, match the L4
  timeout = 5) # determines how long the port is open 

print("Connected ") # to tell the user that it's connected

try:
  while True: # infinite loop
    if not ser.in_waiting(): # if the serial port is waiting
      data = ser.read() # variable made equal to what is read
      print data # prints out Rx data in single characters 

finally:
  ser.close() #cleanup

The transfer was a success, printing the wind direction as the magnet was moved across the array of sensors on the other end of the transmission. Unfortunately, bytes were being transferred meaning only single characters were received.

The next objective is to receive the data as a string which would be easier to work with and could pass the data to a text or HTML file.

Leave a comment