Scribbler in C++ Complete Tutorial

 Special thanks to John Robert Hoare  http://web.eecs.utk.edu/~jhoare/Main/HomePage

Windows XP / Vista / 7 instructions:

The overall setup of the project involves getting VirtualBox player and running an Ubuntu virtual machine. You will be programming in C++ on your Ubuntu virtual machine. PROTIP: A virtual machine is basically a simplified computer OS (like Windows or Ubuntu) that runs on your computer (think Inception; a computer in a computer).

First, please download VM VirtualBox. You can find it here: https://www.virtualbox.org/wiki/Downloads

Make sure you choose the download for your Operating System. Download and install it on your machine. Next download the image for the Ubuntu virtual machine we will be using. It is a large download (1.4 Gb), so it might take a few minutes. It can be found here: http://ee-classes.usc.edu/cs101/Ubuntu_10.04_StudentVM.zip

Now you will want to unzip the image you just downloaded. Once that is finished, open VirtualBox. Select Machine->Add from the menu at the top. Navigate to the unzipped version of the Ubuntu image you downloaded. You will want to open the file called Ubuntu 10.04 VM.vbox. Once it is loaded, please open the virtual machine by clicking “Start”. Click “Ok” for each box that pops up.  The password for the student account is “myro”

Once the machine loads, right click on the USB picture, and select your bluetooth adapter.

If you do not see your adapter, then you may have to turn off your computer’s Bluetooth Adapter and turn it on again so it will connect to your virtual machine. Insert the fluke and turn on the Scribbler.

Troubleshooting Section

If you are still having trouble finding or adding your adapter, you may need to “add a new filter.” In order to do this, go to the virtual box window

Then you will click on “settings->usb->(the little USB with a green + symbol). Select your device, and it should now work.

 

If you are on a Mac and STILL cannot activate Bluetooth (after following the above steps to add a filter) because the Bluetooth adapter is “in use,” please follow these steps:

  1. Disable Bluetooth from OSX TaskBar
  2. Open Terminal and run commands [will need to enter OS-X password]
  3. kextstat | grep -i bluetooth
  4. sudo kextunload -b com.apple.driver.BroadcomUSBBluetoothHCIController
  5. sudo kextunload -b com.apple.driver.AppleUSBBluetoothHCIController
  6. Ensure the Bluetooth icon has a line through it in the TaskBar in OSX
  7. Launch the VirtualBox VM Image
  8. In the VirtualBox application, take control of the USB Bluetooth Device if Ubuntu doesn’t already capture it on startup.
  9. Use myro (connect twice to get it to work)

After you have completed these steps if you would like to re-enable bluetooth on your Mac operating system, the easiest thing to do is restart your machine. If you do not want to restart you machine, you can use the following steps to re-enable bluetooth on your mac OS:

  1. Close virtualbox (Shutdown the Ubuntu OS)
  2. At the terminal run the following commands (or script — unsetBTScribbler.sh)
  3. sudo kextload -b com.apple.driver.BroadcomUSBBluetoothHCIController
  4. sudo kextload -b com.apple.driver.AppleUSBBluetoothHCIController
  5. Reactive Bluetooth on the TaskBar

End of Troubleshooting Section: Tutorial Continues

 

 

Go back to your ubuntuvirtual box.

Open a terminal (you can hit ctr+alt+t as a shortcut).

hcitool scan

This will show you the bluetooth devices in range. Your Scribbler should be the entry that says IPRE followed by some numbers.     On my computer it looks like this: B4:D8:A9:00:02:0E         Fluke2-020E

The first part of the text with the : colons is the MAC address. Copy that mac address. You will need it in a minute. In the above example, the MAC address was B4:D8:A9:00:01:0E. Yours will be different. If you do not see an entry with IPRE in it, make sure your scribbler is on and that you have clicked on the bluetooth logo on the outer VMware window and enabled it. Also make sure that the Bluetooth light is blinking on the Scribbler as shown below.

 

 

Now in the terminal type:

sudo -s

PROTIPThis command will give you the highest permissions for each successive command, until you say otherwise. You might think that it would be wise to always stay in this mode, however it is not. Whenever you make a new file in this mode, you will be unable to edit said file by simply clicking on it (you have to find the file in the command prompt, then open it). This can be a huge pain, so when this guide tells you to exit this mode, you should probably do so. It will ask for a password, which you should enter. Then type:

gedit /etc/bluetooth/rfcomm.conf

PROTIP: Gedit is a text editor which you can use to write and edit C++ code. You will learn about this and a few more C++ code editing environments later in this course.A text file will open. You should see:

#
# RFCOMM configuration file.
#

rfcomm0 {
    bind yes;
    device B4:D8:A9:00:01:0E;
    channel 1;
    comment "IPRE Scribbler ID 185783";
}

You should change the entry after the word “device” (the part in bold) to match the MAC address of your scribbler. Make sure there is a space between the word device and your MAC address. Also make sure the line ends with a semi-colon. Save and exit the file. Back in the terminal type:

rfcomm bind all

The  port for your robot is now:

/dev/rfcomm0

The port name is everything on the above line, including the “/” and “dev.” It looks weird but you will need all of it when you connect. At this time, we want to exit out of “sudo” and give ourselves normal permissions. We do this by typing:

exit

Now in the terminal type :

cd  /home/student/

PROTIP: The “cd” command is what’s known as a UNIX command. It stands for “change directory” and helps you to navigate files on your computer (or virtual machine) though the command prompt (i.e. without using a visual file navigator like windows explorer). Some useful commands include: . – a single period refers to the directory you are currently inside. .. – two periods refers to the parent directory of the directory you are currently inside. ls – stands for “list”; lists the files/directories that are in the directory you are inside. ~ – refers to the home (or root) directory of your computer 

 

Then type:

make myrotest

Lastly, type this to run your program:

./myrotest

PROTIP: As stated before, . (period) stands for the directory you are currently in. This command runs the file in the current directory named “Driver”, which you created with the previous command. It should then say Hello, I’m ���������������� Connected to Robot At this point it will think for a few secconds, let out a small beep and move forward a tiny amount. Congratulations! You have written and compiled your first C++ Scribbler program!