Skip to content

Commit

Permalink
Merge pull request #4 from TheDataScienceLabs/mpu-6050-accelerometer
Browse files Browse the repository at this point in the history
Fix mpu 6050 accelerometer code
  • Loading branch information
jaxsonp committed Sep 26, 2023
2 parents 024ec14 + a051d2a commit c2e0379
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions book/labs/4_measure_tall_things/b_build_an_inclinometer/lab4b.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@
"fi\n",
"mkdir lab4B\n",
"cd lab4B\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/ssd1306.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/procedural_clock.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/classy_clock.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/button.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/imu.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/vector3d.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/accelerometer.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/scripts/ssd1306.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/scripts/procedural_clock.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/scripts/classy_clock.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/scripts/button.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/scripts/imu.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/scripts/vector3d.py\n",
"wget -q -N https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/scripts/accelerometer.py\n",
"cd .."
]
},
Expand Down Expand Up @@ -183,9 +183,9 @@
"id": "8709c814-ff00-4808-88ae-ea1d9a11647c",
"metadata": {},
"source": [
"You have been provided a button. It is a very common type, more precisely called a *tactile switch*. It has four legs, but opposite pairs of them are connected internally, so there are only two electrical connections to be made. Have a look at the [data sheet](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/TL1105.pdf) for the TL1105 tactile switch, which shows a schematic of how the legs are connected. _Hint: look at the numbers assigned to each leg of the switch._\n",
"You have been provided a button. It is a very common type, more precisely called a *tactile switch*. It has four legs, but opposite pairs of them are connected internally, so there are only two electrical connections to be made. Have a look at the [TL1105 data sheet](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/TL1105_datasheet.pdf) for the TL1105 tactile switch, which shows a schematic of how the legs are connected. _Hint: look at the numbers assigned to each leg of the switch._\n",
"\n",
"Connect one side of the button to a ground pin of the Pico and connect the other side to any GP (general purpose) pin with wires on the breadboard (you may need to use the [pico_datasheet.pdf](https://datasheets.raspberrypi.com/pico/pico-datasheet.pdf)). Then open up [button.py](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/button.py) in Thonny and configure it according to what pin you chose, replacing the zero with the GP number of the pin, the one in the green box (eg GP0 would be 0, GP10 would be 10). Go ahead and run the program, the built-in LED should turn on only while the button is pressed.\n",
"Connect one side of the button to a ground pin of the Pico and connect the other side to any GP (general purpose) pin with wires on the breadboard (you may need to use the [pico datasheet](https://datasheets.raspberrypi.com/pico/pico-datasheet.pdf)). Then open up [button.py](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/scripts/button.py) in Thonny and configure it according to what pin you chose, replacing the zero with the GP number of the pin, the one in the green box (eg GP0 would be 0, GP10 would be 10). Go ahead and run the program, the built-in LED should turn on only while the button is pressed.\n",
"\n",
"### <span style=\"color:red\"> Exercise 1 </span> (10 pts)\n",
"Modify `button.py` so that instead of coming on while the button is pressed, pressing the button toggles the LED on and off. There are many ways to do this; try and be creative, and if you get stuck, ask for help from an instructor or a classmate. Here are a couple ideas which might get you moving:\n",
Expand Down Expand Up @@ -242,7 +242,7 @@
"\n",
"### Two clocks\n",
"\n",
"Usually the easiest way to learn a new tool is to see it used. As an example, we have provided two programs (which you have installed earlier) that do the same thing using the OLED display. [procedural_clock.py](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/procedural_clock.py) draws a clock on the display by performing a sequence of actions one after another, inside a `while True` loop. [classy_clock.py](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/classy_clock.py) does the exact same steps, but wraps everything to do with the display into one class and defines methods on the class to do the various parts. Note that in practice you would usually define any classes you are using in a separate module, and import those classes into your main file. We have chosen to put the class definition at the bottom of the file to make it easier for you to compare them.\n",
"Usually the easiest way to learn a new tool is to see it used. As an example, we have provided two programs (which you have installed earlier) that do the same thing using the OLED display. [procedural_clock.py](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/scripts/procedural_clock.py) draws a clock on the display by performing a sequence of actions one after another, inside a `while True` loop. [classy_clock.py](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/scripts/classy_clock.py) does the exact same steps, but wraps everything to do with the display into one class and defines methods on the class to do the various parts. Note that in practice you would usually define any classes you are using in a separate module, and import those classes into your main file. We have chosen to put the class definition at the bottom of the file to make it easier for you to compare them.\n",
"\n",
"In terms of what they do, both of these programs are identical. Their difference lies in how easy they are to read and how easy they are to modify.\n",
"\n",
Expand Down Expand Up @@ -278,11 +278,14 @@
"\n",
"If you are uncertain about your wiring, then ask for an instructor to check it over. If you are confident in your wiring you can continue. It should look as shown in the image below.\n",
"\n",
"![wired screen](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/3c582703e2eac9b14caafe1b89b16e4872ff7f2b/book/labs/4_measure_tall_things/b_build_an_inclinometer/display_example.jpg?raw=true)\n",
"<div>\n",
"<img src=\"https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/display_example.jpg\" width=\"700\"/>\n",
"</div>\n",
"\n",
"\n",
"### <span style=\"color:red\"> Exercise 3 </span> (5 pts)\n",
"\n",
"You should have uploaded the file [ssd1306.py](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/ssd1306.py) onto your Pico using Thonny earlier. This provides a class for interacting with the specific OLED displays we are using. Then, pick your favorite of the clock programs and run it. If you choose to use different I2C pins than the examply above you may need to modify the line which sets up the I2C bus according to the specific SCL and SDA pins you choose (using the number labeled with GP on the datasheet, not the SCL or SDA numbers) as well as the `id` to 0 for I2C0 or 1 for I2C1. Once you have one of the clocks up and running, just write a note below indicating that you have done so.\n",
"You should have uploaded the file [ssd1306.py](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/scripts/ssd1306.py) onto your Pico using Thonny earlier. This provides a class for interacting with the specific OLED displays we are using. Then, pick your favorite of the clock programs and run it. If you choose to use different I2C pins than the examply above you may need to modify the line which sets up the I2C bus according to the specific SCL and SDA pins you choose (using the number labeled with GP on the datasheet, not the SCL or SDA numbers) as well as the `id` to 0 for I2C0 or 1 for I2C1. Once you have one of the clocks up and running, just write a note below indicating that you have done so.\n",
"\n",
"<h3 style=\"background-color:lightblue\"> Write Answers for Exercise 3 Below </h3>"
]
Expand Down Expand Up @@ -322,7 +325,9 @@
"| SDA | SDA |\n",
"\n",
"It should look as shown in the image below.\n",
"![wired accelerometer](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/3c582703e2eac9b14caafe1b89b16e4872ff7f2b/book/labs/4_measure_tall_things/b_build_an_inclinometer/accelerometer_example.jpg?raw=true)\n",
"<div>\n",
"<img src=\"https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/accelerometer_example.jpg\" width=\"700\"/>\n",
"</div>\n",
"\n",
"Verify that `imu.py` and `vector3d.py` are loaded onto the Pico, and then run the file `accelerometer.py` in Thonny. Again you may need to modify ```accelerometer.py``` so that the line where the I2C bus is configured uses the right pins. You should see it printing values in Thonny.\n",
"\n",
Expand Down Expand Up @@ -565,7 +570,9 @@
"\n",
"The pins on the 7805 are not labeled. You will have to check the [data sheet](https://github.com/TheDataScienceLabs/DSLab_Calculus/blob/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/L7805CV_datasheet.pdf). **Do not connect the battery until you have had your circuit checked by an instructor.** The correctly wired voltage regulator should look as shown in the image below.\n",
"\n",
"![voltage regulator example](https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/3c582703e2eac9b14caafe1b89b16e4872ff7f2b/book/labs/4_measure_tall_things/b_build_an_inclinometer/battery_wiring.jpg)\n",
"<div>\n",
"<img src=\"https://raw.githubusercontent.com/TheDataScienceLabs/DSLab_Calculus/main/book/labs/4_measure_tall_things/b_build_an_inclinometer/battery_wiring.jpg\" width=\"700\"/>\n",
"</div>\n",
"\n",
"Once you have had your circuit checked, try turning it on. **Do not take your circuit apart this time**. You will need it next week."
]
Expand Down

0 comments on commit c2e0379

Please sign in to comment.