+ All Categories
Home > Documents > Setting up the Raspberry Pi Software (Windows)PurdueX+nano525x+2015_T3+type@... · Setting up the...

Setting up the Raspberry Pi Software (Windows)PurdueX+nano525x+2015_T3+type@... · Setting up the...

Date post: 11-May-2018
Category:
Upload: duongque
View: 229 times
Download: 2 times
Share this document with a friend
21
Setting up the Raspberry Pi Software (Windows) Installing the Raspbian OS 1. On your PC, navigate to http://downloads.raspberrypi.org/raspbian_latest. This will prompt you to download a file with a name like “2015-05-05-raspbian-wheezy.zip.” This file is ~1 GB, so it may take a while to download. 2. Once downloaded, unzip the file by double-clicking on it. This should create a file with the same name, but with a .img extension instead of a .zip. 3. Insert the microSD card into your PC using the MicroSD Adaptor. If you do not have an SD card reader on your computer, you will have to use an SD adaptor in a USB port. Note which drive letter was assigned (for example G:) when the card is inserted. You can check this in left column of Windows Explorer. 4. Download the Win32DiskImager utility from http://sourceforge.net/projects/win32diskimager/ 5. Run the installation executable (.exe) file. 6. Run the Win32DiskImager utility (program) as an administrator (right click then select “Run as administrator”). 7. Navigate to and select the .img file extracted in step 2. The file you selected will be displayed in the Image File textbox. 8. Under the “Device” dropdown menu, select the drive letter for the MicroSD card noted in step 3. WARNING: be careful to select the correct drive as selecting the wrong one can destroy data on your computer’s hard disk. 9. Click “Write” and wait for the write to complete 10. Exit Win32DiskImager and eject the SD card. 11. Good job! You have now installed an operating system on the SD card. You may now insert the SD card into the Raspberry Pi. Connect to the Raspberry Pi through Your Computer 1. Plug in the Edimax W-iFi USB adaptor into a USB port of your Raspberry Pi
Transcript

Setting up the Raspberry Pi Software (Windows)

Installing the Raspbian OS 1. On your PC, navigate to http://downloads.raspberrypi.org/raspbian_latest. This will prompt you

to download a file with a name like “2015-05-05-raspbian-wheezy.zip.” This file is ~1 GB, so it

may take a while to download.

2. Once downloaded, unzip the file by double-clicking on it. This should create a file with the same

name, but with a .img extension instead of a .zip.

3. Insert the microSD card into your PC using the MicroSD Adaptor. If you do not have an SD card

reader on your computer, you will have to use an SD adaptor in a USB port. Note which drive

letter was assigned (for example G:) when the card is inserted. You can check this in left column

of Windows Explorer.

4. Download the Win32DiskImager utility from http://sourceforge.net/projects/win32diskimager/

5. Run the installation executable (.exe) file.

6. Run the Win32DiskImager utility (program) as an administrator (right click then select “Run as

administrator”).

7. Navigate to and select the .img file extracted in step 2. The file you selected will be displayed in

the Image File textbox.

8. Under the “Device” dropdown menu, select the drive letter for the MicroSD card noted in step

3. WARNING: be careful to select the correct drive as selecting the wrong one can destroy data

on your computer’s hard disk.

9. Click “Write” and wait for the write to complete

10. Exit Win32DiskImager and eject the SD card.

11. Good job! You have now installed an operating system on the SD card. You may now insert the

SD card into the Raspberry Pi.

Connect to the Raspberry Pi through Your Computer 1. Plug in the Edimax W-iFi USB adaptor into a USB port of your Raspberry Pi

2. Connect your Raspberry Pi to your router using an Ethernet cable.

3. Plug the Raspberry Pi into an outlet and wait 90 seconds for it to fully boot up.

4. To log into your Raspberry Pi from your PC, you will need to find out its IP address. This can be

done by logging into your router. In order to log into your router you will need to know its IP

address. First, determine your PC’s IP address by opening a command prompt window (press

Win+R then type cmd.exe).

5. Type ipconfig in the command prompt and press enter

6. If you are connected by Ethernet you can find your computer’s IP address under “Ethernet

adapter Ethernet”. If you are connected by Wi-Fi you will find your computer’s IP address under

“Wireless LAN adapter Wi-Fi”. Your IP address will be listed next to IPv4 Address and will be in

the form ###.###.###.### and might look something like this: 10.0.0.195 (for example).

Therefore, your router IP address will be the first three numbers with the fourth number being

one: 10.0.0.1 (for example).

7. You can log into your router by navigating to http://###.###.###.1 (fill in your specific router

number) using a Web Browser. Once you log into your router (default credentials are usually

‘admin’ and ‘password’) look at the list of connected devices. You should see your Raspberry Pi

in the list (the default name is raspberrypi). Click on it and note its IP address.

8. If you’re having difficulty connecting to your router, consult the router’s manual any specific

instruction for accessing the router’s configuration page.

9. You will now download PuTTY, which will allow you to connect to and log into your Raspberry Pi.

The program can be downloaded from the following page: http://www.putty.org/

10. Launch the PuTTY software (putty.exe).

11. Under “Host Name (or IP address)” type the IP address of your Raspberry Pi and click ‘Open’. If

prompted to continue connecting, click on ‘yes’.

12. The PuTTY prompt will read ‘loginas’. Type ‘pi’ (default user name) and press enter. For the

password, enter ‘raspberry’ (default). If connected properly, the output should look like this:

13. Some final initialization steps must now be run on the Raspberry Pi. Do this by entering in the

following terminal command on the Raspberrp Pi terminal:

‘sudo raspi-config’

The output should look like this:

14. Expand the Filesystem by highlighting the “Expand Filesystem” and then pressing the right-

arrow key, selecting ‘Select’, and then pressing the Enter key. Once the Filesystem has been

expanded, navigate to the “Advanced Options” menu. The output should look like this:

15. Select the “SPI” menu and enable it. When prompted if the SPI kernel module should be loaded

by default, say “Yes”.

16. Exit the setup menu by selecting “Finish”. When prompted to reboot, select “Yes”. This will

cause the Raspberry Pi to reboot, which will automatically end your PuTTY session.

Obtaining Software Packages to Run the EMG Acquire Software The EMG Acquire software requires some optional software to be installed. This can be done by running

one of the scripts contained in the ‘scripts.zip’ file provided with this tutorial. To run this script on the

Raspberry Pi, it must first be transferred to the Raspberry Pi from your PC. You will do this using the

Cyberduck program from here: https://cyberduck.io/

1. Make sure that your Raspberry Pi is connected to your router and is powered on.

2. Make sure that your PC is connected to the same router.

3. Make sure that your router has internet access.

4. Obtain the IP address of your Raspberry Pi using the techniques described in the previous

section. (If you haven’t changed your setup, it’s probably OK to assume that the IP address

hasn’t changed).

5. Launch the Cyberduck program. Click ‘Open Connection’ in the upper left corner. From the

dropdown menu select “SFTP (SSH File Transfer Protocol). In the server box type your Raspberry

Pi’s IP address. In the Username and Password boxes, type ‘pi’ and ‘raspberry’, respectively.

Click ‘Connect’. The window should look like this:

6. Click ‘Upload’ at the top of the screen and select the .zip file that contains the python scripts

provided with this tutorial.

7. Log into your Raspberry Pi as described in the section titled “Connect to the Raspberry Pi with

Your Computer”.

8. Once you are logged on, confirm that the .zip file has been transferred to the Raspberry Pi by

entering in the following terminal command on the Raspberry Pi terminal:

‘ls -l’

This will list all of the files and directories in your home folder. You should see a file named

‘scripts.zip’

9. Unzip the ‘scripts.zip’ file by entering the following terminal command in the Raspberry Pi

terminal:

‘unzip scripts.zip’

This should create a directory named ‘scripts’. Go into this directory by entering the following

terminal command in the Raspberry Pi terminal:

‘cd scripts’

10. The script we want to run is named ‘setup_PiEMG.sh’. To run this script, we must first change its

permissions. Do this by entering the following terminal command in the Raspberry Pi terminal:

‘chmod 755 setup_PiEMG.sh’

11. Now, run the script by entering the following terminal command in the Raspberry Pi terminal:

‘./setup_PiEMG.sh’

This script will install five software packages, all of which must be downloaded from various

servers. It will take a few minutes (depending on your network speed). When the script is done

running, the terminal output should look like this:

12. Running the EMG Acquire software at this moment will only confirm that all of the necessary

software packages are present on the Raspberry Pi. Do this by entering the following terminal

command in the Raspberry Pi terminal (where ###.###.###.### is your Raspberry Pi’s IP

address):

‘sudo python3 ~/Desktop/EMG_Acquire.py ###.###.###.###

Because there is no Analog Frontend attached, there is no data to stream. To stop the software,

press ctrl-C. This confirms that the necessary software packages have been properly installed.

The terminal output should look like this:

c

13. You can now disconnect from the Raspberry Pi by executing the command ‘exit’.

Setting up the Raspberry Pi as a Wireless Router If the Raspberry Pi is left in the above configuration, it must always be attached to a router via an

Ethernet cable in order to stream its data out. The following steps will set the Raspberry Pi up as a

wireless router that can be directly connected to by your PC (or any computer with a wireless card).

1. Make sure that your Raspberry Pi is connected to your router and is powered on.

2. Make sure that your PC is connected to the same router.

3. Make sure that your router has internet access.

4. Connect to you Raspberry Pi as described in the section titled “Connect to the Raspberry Pi with

Your Computer”.

5. Navigate into the scripts directory that you created in the previous section by entering the

following terminal command in the Raspberry Pi terminal:

‘cd scripts’

6. The script we want to run is named ‘setup_wifi_access.sh’. To run this script, we must first

change its permissions. Do this by entering the following terminal command in the Raspberry Pi

terminal:

‘chmod 755 setup_wifi_access.sh’

7. Now, run the script by entering the following terminal command in the Raspberry Pi terminal:

‘./setup_wifi_access.sh’

This script will install a couple of external software packages and will replace a handful of

network configuration files on your Raspberry Pi. A few failure messages may show up in the

console while the script is running. Ignore these messages.

8. When the script has finished running, restart your Raspberry Pi by entering the following

terminal command in the Raspberry Pi terminal:

‘sudo reboot -h’

This will force your PuTTY session to end. You can close the PuTTY window.

9. Once the Raspberry Pi has finished rebooting, it will broadcast a Wi-Fi connection named

Pi_EMG. Look for this connection using your computer. Connect to this Wi-Fi network using the

password ‘Raspberry’ Note that your Raspberry Pi is working as a wireless router now, so if it is

still connected to the internet using its Ethernet port, your computer will still be able to access

the internet while connected to the Raspberry Pi Wi-Fi network!

10. Now, you can connect to your Raspberry Pi directly through its Wi-Fi network. The IP address of

the Raspberry Pi’s wireless connection is 192.168.42.1. Open a new PuTTY session on your

computer and enter this IP address in the Host Name (or IP address) box. Congratulations, you

are now remotely accessing your Raspberry Pi using a direct Wi-Fi connection!

11. You may wish to change the name of your Raspberry Pi’s wireless network, especially if you are

doing this project in the same area as others. You can do this by editing the hostadp.config file.

Enter the following terminal command in the Raspberry Pi terminal:

‘sudo nano /etc/hostapd/hostapd.conf’

This will open up a file that you can edit. It should look like this:

12. Find the line that says:

ssid=Pi_EMG

Change ‘Pi_EMG’ to a unique name of your choice. Make sure not to add any extra spaces or

lines to this file.

If you would like to change the password, you can do that by finding the following line:

‘wpa_passphrase=Raspberry’

Change ‘Raspberry’ to a password of your choice.

Again, make sure you do not add any extra spaces or lines to this file! When you are done

editing this file, press ctrl-x, then press ‘Y’, then press ‘Enter’.

To update your Wi-Fi network name, reboot your Raspberry Pi by entering the following

terminal command in the Raspberry Pi terminal:

‘sudo reboot –h’

This will automatically end your PuTTY session. Wait for the Raspberry Pi to reboot and then

look for the updated Wi-Fi name using your computer (the old name may still exist in your list,

but it won’t stay there long).

13. Next, you will be building the Analog Front-End, so you will need to shut down the Raspberry Pi

board gracefully. Do this by entering the following terminal command in the Raspberry Pi

terminal:

‘sudo shutdown –h now’

Wait for about 30 seconds, or until the green light on the board stops flashing. It is now safe to

remove the power cable from the Raspberry Pi.

Building the Analog Front-End The Analog Frontend (AFE) will be built entirely on the Adafruit Raspberry Pi Prototyping Plate. The

figure below shows a top-level diagram of the Analog Front End:

EMG Analog Front End

EMG +

EMG -

+5V+3.3VGND

SCLK

MISO

CS0

BioIN

Power Ports

SPIDifferential

Amplification and Filtering

The EMG+ and EMG- inputs will come directly from the snap-leads connected to the stick-on electrodes.

These snap-leads can be connected to the Prototyping Plate via the included screw-terminals. It may be

necessary to clip off the jack-connector of the snap-leads and strip the ends so that they can be inserted

into the screw-terminals.

The +5V, +3.3V, and GND power inputs to the AFE are supplied by the Raspberry Pi when the

Prototyping plate is connected to it. When building the AFE on the Prototyping plate, these power

supplies can be obtained using any of the labeled ports on the Prototyping Plate (i.e. 5V, GND, 3.3V).

The AFE communicates with the Raspberry Pi via a Serial Peripheral Interface (SPI). These ports (SCLK,

MISO, and CS0) should be connected to the ports labeled SCLK, MISO, and CS0 on the Prototyping Plate.

Using the provided ICs and passive parts, construct the circuit shown below on the Prototyping Plate.

This circuit can be viewed in more detail by looking at the “EMG_FrontEnd.pdf” file.

When you finish constructing the AFE, it should look something like this:

The backside of the Prototyping Plate should look something like this:

Acquiring EMG Data Now that the Raspberry Pi has been setup with all of the necessary software and the AFE has been

constructed, it is time to acquire some EMG data!

1. Make sure the Raspberry Pi is not powered on.

2. Connect the Adafruit Prototyping Plate to the Raspberry Pi.

3. Power on the Raspberry Pi.

4. Once the Raspberry Pi has booted up, find its Wi-Fi network and connect to it on your computer.

5. Your computer will have a new IP address assigned to it by the Raspberry Pi. Find this by

opening a command line terminal (press Win + R then type cmd.exe then press ‘OK’). The IP

address should be listed next to IPv4 Address under “Wireless LAN adapter Wi-Fi” in the form:

192.168.42.X.

6. Using the command line terminal, you will now launch a script that plots the incoming

bioelectric data. On your computer navigate to the folder where you saved the file

‘Plot_Acquired_Data.py’ that came with the ‘scripts.zip’ file used earlier in the tutorial.

Remember that ‘cd DirectoryName’ will move you to the child folder named “DirectoryName”

and ‘cd ..’ will move you to the parent folder. The command ‘dir’ can be used at any time to list

all files in your current directory. Once you’re in the folder where the script

‘Plot_Acquired_Data.py’ is saved, launch the script by typing the following command:

‘py -3 Plot_Acquired_Data.py 192.168.42.X’

7. Open a PuTTY session on your computer. One session will be for controlling the Raspberry Pi

EMG Acquisition software. The other will be for running the Plot Acquired Data software on the

computer.

8. Your computer will have a new IP address assigned to it by the Raspberry Pi. Find this by

opening a command prompt window (press Win+R then type cmd.exe). Your computers IP

address should be shown next IPv4 address under “Wireless LAN adapter Wi-Fi”.

9. In one of the sessions that you opened, navigate to the directory containing the

‘Plot_Acquired_Data.py’ file.

10. Start the Plot Acquired Data software by entering the following terminal command (substituting

in your IP address found in step 6):

‘python3 Plot_Acquired_Data.py 192.168.42.X’

Your command line terminal might look something like this::

A new window should also appear that looks like this:

No data is plotting yet because the Raspberry Pi has not been told to start streaming acquired

data yet. You will do this next.

11. Start a PuTTY session and connect to your Raspberry Pi using the directions from the section

“Connect to Your Raspberry Pi through Your Computer”. Note that time, though, the IP address

will be 192.168.42.1.

12. Navigate to the Desktop of the Raspberry Pi using the following command:

‘cd Desktop’

13. Start the EMG Acquire software and stream it to your computer by entering the following

command, substituting in your computer’s IP address found in step 5 above.

‘sudo python3 EMG_Acquire.py 192.168.42.X’

The terminal output should look something like this:

You should also immediately notice that the plot window is now streaming data. It probably

looks something like this:

While exciting, this doesn’t really look like a very clean signal! This is due to the Wi-Fi signal

interfering with the AFE. The easiest fix for this is to move the Wi-Fi module away from the AFE

using a USB extension cable. It may also be possible to remove this noise by fully shielding the

AFE circuit with a grounded case. This would have to be done carefully so as to not short out

anything on the AFE or on the Raspberry Pi! The next steps will use a USB extension cable to

clean up the signal.

14. Stop the EMG Acquire software by pressing ‘ctrl-C’

15. Shutdown the Raspberry Pi by entering the following terminal command in the Raspberry Pi

terminal:

‘sudo shutdown -h now’

16. Unplug the Wi-Fi module and reattach it to the Raspberry Pi using a 1-meter long USB extension

cable.

17. Move the Wi-Fi module away from the Raspberry Pi.

18. Plug the Raspberry Pi back in

19. Once it has booted up, connect to its Wi-Fi signal on your computer.

20. If the Plot Acquired Data application is still running on your computer, repeat steps 11 through

13 above. If the Plot Acquired Data application is not still running, repeat steps 6 through 13.

The output plot should look something like this:

If your plot still looks noisy, it could be related to your power source. Not all USB chargers are

created equally, and the Raspberry Pi requires a large amount of current when using a Wi-Fi

module. Try powering your Raspberry Pi using a powered USB hub or a USB port on your

computer.

You can experiment with the coupling Wi-Fi noise by moving the Wi-Fi module closer and

farther away from the AFE circuitry. It’s possible that a 1-ft long USB extension cable may be

sufficient to remove the noise.

21. Now that you have removed the Wi-Fi noise, it is time to acquire some EMG signals. Connect

two snap electrodes to your arm as shown below:

I work out a lot.

22. Now, try alternately straightening and turning your wrist inward. The resulting measured EMG

should look like this

If your signal is noisier, try moving the Wi-Fi module away from the AFE. If that does not clean it

up, try a better USB power supply.

Controlling a Virtual Prosthetic with EMG Now that you are able to acquire clean EMG data, you will be writing an algorithm that will determine

when you are flexing your bicep. You will then embed this algorithm in the provided ‘EMG_BMI.py’ code

to control a virtual prosthetic using your bicep muscle!

1. Boot up your Raspberry Pi and connect to its wireless network.

2. Now, run the EMG_BMI.py software by navigating in the command line terminal to the folder

containing the provided ‘EMG_BMI.py’ file. NOTE: always keep the provided ‘resources’

directory in the same folder as the ‘EMG_BMI.py’ file. Now, run the EMG_BMI software by

entering the following terminal command on your computer.

‘py -3 EMG_BMI.py 192.168.42.X’

This should pop up a window that looks like this:

This program is able to acquire EMG data in the same way that the Plot Acquired Data

application does. You can stream data to this application by following steps 11 through 13 in the

previous section. If you do this, however, you will notice that nothing really exciting happens.

This is because the EMG BMI application does not know how to detect flexing muscles. You’ll be

telling it how to do this next!

3. Quit the EMG BMI application by closing the main window.

4. Open the ‘EMG_BMI.py’ file using a text editor of your choice (use IDLE in order to have syntax

highlighting).

5. Near the end of the code, locate the ‘update’ function. It should look something like this:

This update function is repeatedly called when the EMG BMI application is running and is used

to update the position of the virtual arm in real time. The virtual arm will flex if the ‘flexing’

variable is set to ‘True’. It will stop flexing if the ‘flexing’ variable is set to ‘False.’

6. To see the virtual arm flex, change the default value of the ‘flexing’ variable to ‘True’ on line 117

of the code shown above. Save the file and close it. Now, run the EMG BMI application as you

did in step 3. You should see the arm flex when the application starts. It should look something

like this:

7. Now, you need to write an algorithm that analyzes the incoming EMG data and determines if

you are flexing or not. This algorithm should modify the ‘flexing’ variable to indicate the result of

this determination. To do this, you will need to look at the newly incoming data that is initially

stored in the ‘data’ list. Because the ‘data’ list is modifiable outside of the ‘update’ function, it is

not safe to read from it, so you should look at the ‘newData’ list that is created in line 109 to

find all of the most recently acquired EMG data.

Hint 1: The only code you should MODIFY is line 117. If you change any other lines of code, it

could affect the proper acquisition of EMG data.

Hint 2: The acquired data is in the form of unsigned 8-bit integers. Therefore, the signal should

vary around a baseline value of 128. Remember to take this into account whenever using

functions that care about the difference between negative and positive numbers!

8. Once you have put your algorithm in place, you can try it out by running the EMG BMI

application and setting up the Raspberry Pi to stream EMG data as described in the section

“Acquiring EMG Data”. If done correctly, the virtual arm should flex when you flex your bicep

that is connected to the EMG analog front-end.


Recommended