pibot:lesson4:softwaremac
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
pibot:lesson4:softwaremac [2021/09/30 14:54] – jstruebel | pibot:lesson4:softwaremac [2022/10/20 19:53] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Software Setup ====== | ||
+ | |||
+ | - Open the terminal app\\ \\ <WRAP round tip> | ||
+ | - Type the following command and press enter to connect to the Raspberry Pi terminal via SSH\\ \\ <WRAP round important> | ||
+ | - Perform the following steps to enable the CSI interface on the Raspberry Pi board | ||
+ | - Type the following command and press enter to run the Raspberry Pi configuration utility\\ \\ < | ||
+ | - Use the up and down arrow keys to select the " | ||
+ | - Use the up and down arrow keys to select the " | ||
+ | - Use the left and right arrow keys to select the " | ||
+ | - Select the " | ||
+ | - Use the left and right arrow keys to select the " | ||
+ | - Use the left and right arrow keys to select the " | ||
+ | - Open the Visual Studio Code from the Applications directory on the flash drive | ||
+ | - Click on the small green square in the bottom left corner of the screen\\ \\ <WRAP box>{{ : | ||
+ | - Select the " | ||
+ | - Type " | ||
+ | - Click the "Open Folder" | ||
+ | - Select the " | ||
+ | - Open a terminal in Visual Studio Code from the Terminal-> | ||
+ | - Type the following commands and press enter after each line to download the MJPEG Streamer code for this lesson\\ \\ < | ||
+ | wget http:// | ||
+ | bash webcam.sh</ | ||
+ | - Type the following command and press enter to start the MJPEG Streamer server for this lesson\\ \\ < | ||
+ | - Open the Safari App, type http:// | ||
+ | - Open another terminal in Visual Studio Code from the Terminal-> | ||
+ | - Type the following commands and press enter after each line to download the Python and HTML code for this lesson\\ \\ <WRAP round tip> | ||
+ | bash osoyoowebcar.sh</ | ||
+ | - Close the current folder in Visual Studio Code from the File-> | ||
+ | - Click the double pages icon on the left and click the "Open Folder" | ||
+ | - Select the " | ||
+ | - Select the webcar.py file in the list\\ \\ <WRAP box>{{ : | ||
+ | - Replace the **192.168.0.32** on line 15 with **0.0.0.0** | ||
+ | - Save the change by using the File-> | ||
+ | - Click on the templates directory and select the index.html file\\ \\ <WRAP box>{{ : | ||
+ | - Replace the **192.168.0.32** on line 34 with **pibot## | ||
+ | - Save the change by using the File-> | ||
+ | - Open a terminal in Visual Studio Code from the Terminal-> | ||
+ | - Type the following command and press enter to run the Python code for this lesson\\ \\ < | ||
+ | - Open the Safari App, type http:// | ||
+ | |||
+ | ====== Software Explanation ====== | ||
+ | |||
+ | The webcar.py file uses a Python library called Flask that handles the details of serving a webpage to your web browser. Using libraries like Flask is a powerful way to get advanced capabilities in your software without having to write a lot of code from scratch. By using the Flask library there are only a few lines of code that are required to make the PiBot drive around from your web browser. | ||
+ | |||
+ | - In the webcar.py file find the last line of code. What do you think this line does?\\ \\ <WRAP round tip>The app.run function is what calls the Flask library and tells it to send pages to your web browser.</ | ||
+ | - In the webcar.py file, find where the action function is defined. What do you think this function does?\\ \\ <WRAP round tip>If you don't remember what a variable is, review the description from [[: | ||
+ | - How do the '< | ||
+ | - What are some valid paths that will cause the the action function to do something? Find what the code does when that path is requested by your web browser.\\ \\ <WRAP round tip>Each path ends up calling another function in the code as determined by the ' | ||
+ | - Add code to the action function so that when the path '/ | ||
+ | - Save your changes by using the File-> | ||
+ | - Type control + C in the terminal window and then run the following command in the Visual Studio Code terminal to get your new code\\ \\ < | ||
+ | - In the Safari App type http:// | ||
+ | - In the webcar.py file find the call to the render_template function. What is the name of the file that it will send?\\ \\ <WRAP round tip>The render_function template takes the file name that is passed as its parameter and sends it to the web browser that is accessing it. All of the files must be in the ' | ||
+ | - Open the ' | ||
+ | - In the index.html file find where it requests one of the paths that you saw in the webcar.py file. What function is it part of?\\ \\ <WRAP round tip>The " | ||
+ | - Find the '< | ||
+ | - Find where one of the Javascript functions is called in the HTML above. What do you think causes the function to get called?\\ \\ <WRAP round tip>HTML uses tags that are contained between '<' | ||
+ | - Add a button to the HTML that when clicked will request the '/ | ||
+ | - Save your changes by using the File-> | ||
+ | - Reload the web page in the Safari app to see your new button. Click on it and see if it prints the right message in the terminal window. | ||
+ | - When you're finished driving the PiBot around, hold down the control + C keys and type the following command in the Visual Studio Code terminal to shutdown the PiBot\\ \\ < | ||
+ | - Click on the small green rectangle in the bottom left corner of the screen and select "Close Remote Connection" | ||
+ | - Wait 3-5 minutes for the green light on the Raspberry Pi to stop flashing and turn off the switch on the PiBot battery | ||
+ | |||
+ | [[: | ||
+ | |||
+ | |||