EENG 383

RPi interfacing with the Dev'17 board

Overview

Welcome to the optional Raspberry Pi (RPi) configuration page. Our development board was designed to connect to the third generation of RPi through the 2x20 pin header on the RPi. Before you can do this, you will need to purchase and then solder a 2x20 pin female header to the development board. You can purchase this header through Sparkfun electronics at this web page. Once you have the header soldered to your development board, you can carefully slide the development board onto the RPi's header pins and the two will operate together from a single power supply via the RPi's USB connector. This configuration is shown in the following image.


Please note that I did not solder all the header pins in place on the development board. You should solder all the pins to make a more secure mechanical connection. You can program the development board while connected to the RPi using the regular 6-pin header on the development board and the PIC Kit 3.

Finally, note that the RPi is being run in a headless configuration, meaning that there is no CRT, keyboard or mouse connected to the RPi. In the short run this is a pain because you will have to do all your RPi configuration through a terminal interface. However in the long-run this configuration allows you to embedded the RPi in many more application. Hauling around a monitor, keyboard and mouse makes the RPi unusable in most embedded applications. Trust me, this trade-off is worth it.

RPi configuration

There is a lot of good information about how to get a RPi up and running posted on the web. However, I would suggest following my RPi configuration instruction because they include instructions to:

Web Interface to Dev board

You will need to populate the /var/www/html directory with the following files: Now let's go through these files in order and build them. Since it takes super-user permission to read/write into the /var/www/html directory, all file operations will be preceded by "sudo", which means super-user do.
  • mic.py - Start by editing the mic.py file.
    linux% sudo nano /var/www/html/mic.py
    
    Once you have the nano editor open, cut-and-paste the following contents into the file.
    #!/usr/bin/python
    import serial
    serialport = serial.Serial("/dev/ttyS0", 9600, timeout =0.5)
    serialport.write("m")
    response = serialport.readlines(None)
    print response
    
    Finally save and exit.
  • mic.php - Start by editing the mic.php file.
    linux% sudo nano /var/www/html/mic.php
    
    Once you have the nano editor open, cut-and-paste the following contents into the file.
    <?php
    $output = shell_exec('python mic.py');
    $pos = strrpos($output,'[');
    $len = strlen($output);
    $rest = substr($output,$pos+2,3);
    echo "<pre>$rest</pre>";
    ?>
    
    Finally save and exit.
  • tx.py - Start by editing the tx.py file.
    linux% sudo nano /var/www/html/tx.py
    
    Once you have the nano editor open, cut-and-paste the following contents into the file.
    #!/usr/bin/python
    import serial
    serialport = serial.Serial("/dev/ttyS0", 9600, timeout =0.5)
    serialport.write("l")
    response = serialport.readlines(None)
    print response
    
    Finally save and exit. Before you leave, take a look at the code to see what is going on. First the Python script creates a serial connection to the /dev/ttyS0 port at 9600 baud. NExt it writes an "l" to the serial port. This command will be interpreted by the development board as an order to toggle the illumination level of the LED. Finally the python script expects no response from the serial port and exits after printing the NULL response.
  • tx.php - Start by editing the mic.php file.
    linux% sudo nano /var/www/html/tx.php
    
    Once you have the nano editor open, cut-and-paste the following contents into the file.
    <?php
    shell_exec('python tx.py');
    ?>
    
    Finally save and exit.
  • index.html - This file is larger, so start by opening index.html in a seperate web page and use the "view page source" feature of your browser to see the raw HTML code. Copy this code into your computer buffer (Ctrl-C in windows) and then edit the index.html file on your RPi.
    linux% sudo nano /var/www/html/index.html
    
    Paste the contents of the index.html file into the RPi (right-mouse click in PuTTY).
  • Download web.c to your Dev'17 board.
  • Load the "home" web page on your RPi, for me that meant setting 192.168.0.105 as the URL. When I did all this, I got the following web page (index.html). Clicking the "Toggle LED" button turned the Dev'18 LED on/off. Clicking the Read Mic, updated the microphone value in the table.


    Troubleshooting