Skip to content

hheisig51/Engineering_4_Notebook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Engineering_4_Notebook

Circuit Python Table of Contents

Launch Pad

Crash Avoidance

Landing Area

CAD Table of Contents

Pico

These assignments were completed on a Raspberry Pi Pico microcontroller, running Circuit Python 7.3.2

Countdown (Launch Pad #1)

Countdown Description

The purpose of this assignment is to print a “countdown from 10 seconds to 0 (liftoff)” to the serial monitor.

Countdown Video

01_countdown

Countdown Wiring

There’s no wiring in this assignment. Just plug the pico into the computer.

Countdown Code

01_countdown.py:

# 2022-09-02, Em Heisig (hheisig51)
# Creates a countdown from 10 seconds to 0 seconds (liftoff) and prints it to the serial monitor.

import time

for x in range(10, 0, -1): # Moves from 10 to 0 in increments of 1
    if x > 0:
        print(f"{x} seconds left!") # prints the number of seconds left
        time.sleep(1)

print(f"Liftoff!") # since x is not greater than 0, this prints

Countdown Reflection

My biggest challenge was figuring out the loop. I first tried making two while.True() loops, which didn’t work. Then, I tried using if and else inside a while.True(), which works, albeit clunky. Finally, I got to using a for loop, which makes much more sense in this use-case.

Lights (Launch Pad #2)

Lights Description

As the countdown ticks down, a red light will blink every second. At 0 seconds (liftoff), a green LED will turn on.

Lights Video

02_lights

Lights Wiring

02_lights_wiring

Lights Code

02_lights.py:

# 2022-09-09, Em Heisig (hheisig51)
# As the countdown (from 01_countdown.py) ticks down, a red light will blink every second. At 0 seconds (liftoff), a green LED will turn on.

import board
import digitalio
import time

g_led = digitalio.DigitalInOut(board.GP18)
r_led = digitalio.DigitalInOut(board.GP13)
g_led.direction = digitalio.Direction.OUTPUT
r_led.direction = digitalio.Direction.OUTPUT

for x in range(10, 0, -1): # Moves from 10 to 0 in increments of 1
    if x > 0:
        print(f"{x} seconds left!") # Prints the number of seconds left
        r_led.value = True # Turns the red LED on
        time.sleep(.3)
        r_led.value = False # Turns red LED off 0.3 seconds into the 1.0 second cycle.
        time.sleep(.7)

ppschakelrint(f"Liftoff!") # Since x is not greater than 0, this prints
g_led.value = True
time.sleep(2)
g_led.value = False

Lights Reflection

This one was simple. Just remember, the long leg of the LED is the positive leg, and always use a resistor. I’ve forgotten that before, and it completely fries your LED.

Button (Launch Pad #3)

Button Description

In addition to the previous segments (see 01_countdown.py and 02_lights.py), this assignment adds a button to start the countdown.

Button Video

03_button

Button Wiring

03_button_wiring

Button Code

03_button.py

Let’s import our libraries and set up our LEDs’ like before.

import board
import digitalio
import time

g_led = digitalio.DigitalInOut(board.GP18) # assigns a board.pin (GP18) to a variable (g_led)
r_led = digitalio.DigitalInOut(board.GP13)
g_led.direction = digitalio.Direction.OUTPUT # assigns the variable, with a pin now attached to it, as an output
r_led.direction = digitalio.Direction.OUTPUT

Now, we’ll set up the button, as an INPUT rather than an OUTPUT, and as a pull-up resistor.

button = digitalio.DigitalInOut(board.GP16) # see above
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP # sets the button to function as a "pull-up" resistor, with a default value of true.

Same code as before, except the for loop is now nested inside if butto.value == False:, making it only trigger when the button is pressed.

while True:
    if button.value == False:
        for x in range(10, 0, -1): # Moves from 10 to 0 in increments of 1
            if x > 0:
                print(f"{x} seconds left!") # Prints the number of seconds left
                r_led.value = True # Turns the red LED on
                time.sleep(.3)
                r_led.value = False # Turns red LED off 0.3 seconds into the 1.0 second cycle.
                time.sleep(.7)
        print(f"Liftoff!") # Since x is not greater than 0, this prints
        g_led.value = True
        time.sleep(2)
        g_led.value = False

Button Reflection

Figuring out the difference between a pull-up and a pull-down configuration for the button was very tricky. So, I made this little diagram to help myself out:

Pull-up Pull-down
Default value True False
“Pressed” value False True
Wired to GND 3V3(OUT)

It was very frustrating figuring that out. My advice is to ask whatever question you need to ask to actually understand the wiring. Nobody’s going to judge you unless they’re a jerk.

Servo (Launch Pad #4)

Servo Description

In addition to the previous segments (see 03_button.py), this assignment adds a servo that simulates “the launch tower disconnecting.” The servo will start at a position of 0 degrees, then move to 180 degrees when “liftoff” is achieved.

Servo Video

04-servo

Servo Wiring

04_servo.py

Servo Code

04_servo.py:

There is some new code relating to the servo, but it’s pretty standard. I recommend looking at the code file and its comments.

Servo Reflection

This reflection is less about this singular assignment, but more about this Launch Pad assignment as a whole. I think it highlights the importance of segmenting your process when making something. Not fragmenting! You need to make sure things work together. But segmenting, and building one on top of the other, rather than building a servo and a button and lights and a countdown.

Accelerometer (Crash Avoidance #1)

Accelerometer Description

This assignment just prints x, y, and z acceleration values from an MPU-6050 chip to the serial monitor.

Accelerometer Video

05_accelerometer

Accelerometer Wiring

05_accelerometer-wiring

Accelerometer Code

05_accelerometer.py:

# 2022-09-29, Em Heisig (hheisig51)
# This assignment just prints x, y, and z acceleration
# values from an MPU-6050 chip to the serial monitor.

import board
import time
import adafruit_mpu6050
import busio

sda_pin = board.GP14 # the sda_pin and scl_pin will be used for data
scl_pin = board.GP15
i2c = busio.I2C(scl_pin, sda_pin) # pairs the two pins together

mpu = adafruit_mpu6050.MPU6050(i2c) # creates a variable we can reference for values

while True: # cleans up and prints the x, y, and z values
    print(f"x = {round(mpu.acceleration[0],3)}, y = {round(mpu.acceleration[1],3)}, z = {round(mpu.acceleration[2],3)}")
    time.sleep(.5)

Accelerometer Reflection

This assigment introduced a whole new part, one I hadn't used before, which introduced some new difficulties. Working with the I2C clock working with only specific pins was hard, but it got figured out. Also, condensing multiple lines of variables into one massive print statement took some time, but f-strings are awesome.

Light and Powerboost (Crash Avoidance #2)

Light Powerboost Description

In this assignment, a red LED lights up if {x} is within a certain range (Acceleration of 0 to -4, which rougly corresponds with a rotation of 90 degrees).

Light Powerboost Video

06_light-powerboost

Light Powerboost Wiring

06_light-powerboost_wiring

Light Powerboost Code

06_light-powerboost.py:

# 2022-10-03, Em Heisig (hheisig51)
# In this assignment, a red LED lights up if {x} is within
# a certain range (Acceleration of 0 to -4, which rougly
# corresponds with a rotation of 90 degrees)

import board
import time
import adafruit_mpu6050
import busio
import digitalio

sda_pin = board.GP14 # the sda_pin and scl_pin will be used for data
scl_pin = board.GP15
i2c = busio.I2C(scl_pin, sda_pin) # pairs the two pins together

mpu = adafruit_mpu6050.MPU6050(i2c) # creates a variable we can reference for values

led = digitalio.DigitalInOut(board.GP13)
led.direction = digitalio.Direction.OUTPUT

x = 1

while True:
    for x in range(1, 5, 1): # Loops a count from 1 to 5
        if x == 4: # 1 out of 5 times, the values are printed
            print(f"x = {round(mpu.acceleration[0],3)}, y = {round(mpu.acceleration[1],3)}, z = {round(mpu.acceleration[2],3)}")
            x = 1
        if mpu.acceleration[2] < 0 and mpu.acceleration[2] > -4: # turns the LED on if x falls within this range
            led.value = True
            time.sleep(.1)
        else:
            led.value = False
            time.sleep(.1)

Light Powerboost Reflection

There was not a lot of complexity with this assignment. Most of the heavy lifting was done already (in setting up the accelerometer). But, I didn't want the LED to just flicker and be done, but I also didn't want the serial monitor to be spammed with messages. So, I had to tackle a for loop, and adjust time.sleep values constantly. I used the for loop to print the values every 5th time, but check them and trigger the LED every time. This assignment was very trial and error.

OLED (Crash Avoidance #3)

OLED Description

In addition to the previous assignments, this adds an OLED screen to print the values.

OLED Video

07_oled

OLED Wiring

07_oled

OLED Code

This assignment is rather long, so I recommend looking at it and its comments at the code file: 07-oled.py

OLED Reflection

This was a very fun assignment if you're just looking at the result. If you're looking at the process, it's very not-fun. I had quite a bit of trouble understanding how/what/when the display rendered (helped by asking others, trial and error, and using tutorials straight from the manufacturer), which led to quite a few things getting cut off. But, eventually it came together, to make a very nice little display

Functions (Landing Area #1)

Functions Description

This assignment takes 6 inputs (of 3 coordinate pairs) and returns the area of their triangle, or returns an error.

Functions Video

08_functions

Functions Wiring

No wiring was necessary for this assignment. Only the pico was used.

Functions Code

This assignment is lengthy, as its only code, no wiring. I recomend looking at it in its code file: 08_functions.py

Functions Reflection

Being such a code-heavy assigment, this was quite different. Each component was really basic! But, learning how to plug them into eachother was quite a struggle. Properly naming variables was helpful, alongside using comments to mark different sections. It was a very fun assignment, especially being able to go back and optimize it, and watch the code shrink.

Plotting (Landing Area #2)

Plotting Description

You have successfully written a script to calculate and return the area of each triangle. Now, your commander has asked that you include a small OLED screen to improve visualization of where the landing area is relative to the base.

(Description taken from Paul Schakel (pschake34), with permission)

Plotting Video

%^

Plotting Wiring

%^

Plotting Code

%^

Plotting Reflection

%^

Ring and Spinner (CAD #1)

YouTube Video

Key and Prop (CAD #2)

YouTube Video

Assembling the Launcher (CAD #3)

YouTube Video

FEA

YouTube Video

Beam Design (FEA #1)

Beam Design Description

To design a 3D-printed beam to withstand the most force before breaking, or bending more than 35 mm.

Beam Design Evidence

Beam Design Reflection

About

“Somebody is thinking today” - Mr. Miller

Hi! I’m Em Heisig, and I’m a junior at Charlottesville High School. You can reach me at hheisig51@charlottesvilleschools.org or github@eheisig.com.