Skip to content

VeganPorkChop/Engineering-4_Notebook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Engineering_4_Notebook

 

Raspberry_Pi_Assignment_Template

Assignment Description

Write your assignment description here. What is the purpose of this assignment? It should be at least a few sentences.

Evidence

Pictures / Gifs of your work should go here. You need to communicate what your thing does.

Wiring

This may not be applicable to all assignments. Anything where you wire something up, include the wiring diagram here. The diagram should be clear enough that I can recreate the wiring from scratch.

Code

Give me a link to your code. Something like this. Don't make me hunt through your folders, give me a nice link to click to take me there! Remember to COMMENT YOUR CODE if you want full credit.

Reflection

What went wrong / was challenging, how'd you figure it out, and what did you learn from that experience? Your goal for the reflection is to pass on knowledge that will make this assignment better or easier for the next person. Think about your audience for this one, which may be "future you" (when you realize you need some of this code in three months), me, or your college admission committee!

Test Link

Hyperlink text

Test Image

Picture Name Here

Test GIF

Picture Name Here

 

Launch_Pad_Part_1

Assignment Description

The purpose of this assignment is to create a countdown from ten for a rocket launch. You need to use a Raspeberry Pi pico and VS Code.

Evidence

Code

Launch_Pad_Part:1 Code
import board
import time
import digitalio

while True:
    for x in range(10, -1 ,-1):
        time.sleep(1)
        print(x)
        if x == 0:
            print('LAUNCH')

Reflection

Originally my code counted up from zero, but to create a negative intervol with the for function you need to start from a large number, go to a small number, but the second number will not be included in the count down. Then you need to create a negative intervol for the for loop. Additionally, the code needs to be uploaded to the Pico through code.py. To access it you need to go to File/Open File/CIRCUITPY (D:)/Code.py.

Launch_Pad_Part_2_(Lights)

Assignment Description

In this assignment you have to Countdown from 10 seconds to 0 (liftoff), and print that countdown to the serial monitor. Additionally, you must blink a red light each second of the countdown, and turn on a green LED to signify liftoff.

Evidence

Wiring

Code

Launch Pad Part 2 (Lights) Code
import board
import time
import digitalio

ledRed = digitalio.DigitalInOut(board.GP0)
ledRed.direction = digitalio.Direction.OUTPUT
ledGreen = digitalio.DigitalInOut(board.GP1)
ledGreen.direction = digitalio.Direction.OUTPUT
count = 0

while True:
    for x in range(10, -1 ,-1): # for loop, in range(FROM THIS NUM, TO THIS NUM, AT THIS INTERVOL)
        if count == 0:
            if x > 0:
                print(x)
            if x == 0:
                print('LAUNCH')
                ledGreen.value = True # LED ON
                count = 1
            ledRed.value = True  #TIMED BLINK--
            time.sleep(0.5)      #--
            ledRed.value = False #--
            time.sleep(0.5)      #--
        else:
            print('Countdown Finished')

Reflection

Problems I had were the light setup code, the direction of the lights, and preventing the code from printing 0:

  • The light setup code requires a lot of folder retrieval from libraries. It confused me, but I looked it up and now its right.
  • The direction of the lights is OUTPUT, make sure to specify otherwise whenever they turn on they won't and you'll get a positive value.
  • The code prints 0 at the end of the count down, if I removed zero from the count down, it would be 9 seconds instead of 10, my solution was to print the number when x was greater than 0, simple solve, hours of pain.

Launch_Pad_Part_3_(Button)

Assignment Description

This assignment uses the last assignment and you need to add a button so the countdown starts when the button is clicked, and then also add an abort option.

Evidence

Wiring

Code

Launch Pad Part 3 (Button) Code
import board
import time
import digitalio

ledRed = digitalio.DigitalInOut(board.GP0)
ledRed.direction = digitalio.Direction.OUTPUT
ledGreen = digitalio.DigitalInOut(board.GP1)
ledGreen.direction = digitalio.Direction.OUTPUT
button_a = digitalio.DigitalInOut(board.GP15) # at GP15 because button interfeared with leds, refrence pico pinmap
button_a.direction = digitalio.Direction.INPUT
button_a.pull = digitalio.Pull.UP        # requires only two wires one to ground and the other to pin, prevents excess wires. Definition of, "fix it in code".

while True:
    if button_a.value == True:
        time.sleep(0.1)# debounce
        while button_a.value == false:
            for x in range(10, -1 ,-1):
                if x > 0:
                    print(x) # Prints for loop val
                if x == 0:
                    print('LAUNCH')
                    ledGreen.value = True
                    time.sleep(0.1)
                    print('Countdown Finished!')
                    time.sleep(5)
                ledRed.value = True   #Blinks Light--
                time.sleep(0.5)       --
                ledRed.value = False  --
                time.sleep(0.5)       --
        print('ABORT')# code accurs when button is true
        quit() # quits script
        
    else:
        ledGreen.value = False
        print('Waiting For Button')

Reflection

Three things that went wrong were the countdown debounce optimization, the abort button, and the buttons input pullup:

  • If the debounce is too long, the code is really blocky and barely works, if its too short it auto aborts.
  • The abort function took a while too find, still isn't 100% reliable, something about how the function stops the code doesn't always work on VS Code.
  • The input pullup up took too long because the pins on the pico connect in weird ways so the "highways" can have multiple pins sprouting from them, but they can't receive more than one input.

Launch_Pad_Part_4_(Servo)

Assignment Description

Countdown from 10 seconds to 0 (liftoff). Print that countdown to the serial monitor. Blink a red light each second of the countdown, and turn on a green LED to signify liftoff. Include a physical button that starts the countdown. Actuate a 180 degree servo on liftoff to simulate the launch tower disconnecting.

Evidence

Wiring

Code

Launch_Pad_Part_4_(Servo) Code
import board                 # Imports                  
import time                  -
import digitalio             -
import pwmio                 -
from adafruit_motor import servo

pwm_servo = pwmio.PWMOut(board.GP22, duty_cycle=2 ** 15, frequency=50) # sets frequency of pin, idk how it works, visit(https://docs.circuitpython.org/en/latest/shared-bindings/pwmio/index.html)
redLED = digitalio.DigitalInOut(board.GP0) 
greenLED = digitalio.DigitalInOut(board.GP1)
button = digitalio.DigitalInOut(board.GP15)
redLED.direction = digitalio.Direction.OUTPUT
greenLED.direction = digitalio.Direction.OUTPUT
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP
servo1 = servo.Servo(pwm_servo, min_pulse=500, max_pulse=2500) # this sets the allowed pulses and also creates an object in code

servo1.angle = 0 #setting initial values
count = 0                        

while True:
    print('waiting for button')
    if button.value == False:
        count = 10
    while count > 3:                               
        print(count)
        redLED.value = True   
        count = count - 1
        time.sleep(.5)
        redLED.value = False
        time.sleep(.5)
    while count > 0 & count <= 3: # begins turning servo
        print(count)
        redLED.value = True
        count = count - 1
        for x in range(10):
            servo1.angle = servo1.angle + 3
            time.sleep(.05)
        redLED.value = False
        for x in range(10):
            servo1.angle = servo1.angle + 3
            time.sleep(.05)
        if count == 0:                              
            print("launch")
            greenLED.value = True
            servo1.angle = 180
            time.sleep(5)

Reflection

Three things went wrong with this assignment:

  • The servo spinning is very blocky if you chunk the code and move the servo x degrees every loop. So instead I spent 2 classes making it smooth by creating delays and timed intervol and moved it three degrees at a time.
  • The abort button was difficult to employ, so, sense it isn't required, I deleted it.
  • when you ask an object what its value is, you have to type: object.value

Crash_Avoidance_Part_1_(Accelerometer)

Assignment Description

In this assignment you have to wire an accelerometer and print it's values as it's collecting them.

Evidence

Wiring

Code

Crash Avoidance Part 1 (Accelerometer) Code
import adafruit_mpu6050    # Imports
import busio               -
import board               -                             
import time                -
import digitalio           -

sda_pin = board.GP14                # Defining SDA and SCL pins
scl_pin = board.GP15                -
i2c = busio.I2C(scl_pin, sda_pin)   # defining i2c function
mpu = adafruit_mpu6050.MPU6050(i2c)

while True:
    print("My Values:")      # Printing values
    print(mpu.acceleration)  -
    time.sleep(1)

Reflection

There are three things that went wrong:

  • Units: They're in m / s^2. If you're printing units make sure to add that.
  • Wiring: SDA and SCL are located on the GP14 and GP15 wires respectfully.
  • Direction: The board has the directions its facing written on it.

Crash_Avoidance_Part_2_(Light_+_Power)

Assignment Description

The module must have an accelerometer that continuously reports x, y, and z acceleration values. The module must have an LED that turns on if the helicopter is tilted to 90 degrees. The module must be powered by a mobile power source.

Evidence

Wiring

Code

Crash Avoidance Part 2 (Light + Power) Code
import adafruit_mpu6050
import busio
import board                                   
import time
import digitalio

led = digitalio.DigitalInOut(board.GP0)         # pin setup
led.direction = digitalio.Direction.OUTPUT      --

sda_pin = board.GP14                            --
scl_pin = board.GP15                            --
i2c = busio.I2C(scl_pin, sda_pin)               --
mpu = adafruit_mpu6050.MPU6050(i2c) # i2c, idk how it works, look here, https://adafruit.github.io/Adafruit_MPU6050/html/class_adafruit___m_p_u6050.html

while True:
    led.value = False
    print(mpu.acceleration)
    while mpu.acceleration[2] < 0.95: # mpu.acceleration[2], value of only the z axis 
        led.value = True
        print(mpu.acceleration) # prints all acceleration values

Reflection

Two things went wrong with this assignment:

  • I used the wrong function. I was using mpu.gyro, which measures acceleration of rotation. The correct way to do this was to measure the acceleration based on gravity.
  • I put the less than symbol the wrong way. The acceleration of gravity on the y axis is greater than .95 UNTIL it reaches about a 90* tilt.

Crash_Avoidance_Part_3_(OLED_Screen)

Assignment Description

In this assignment the The module must have an accelerometer that continuously reports x, y, and z acceleration values. The module must have an LED that turns on if the helicopter is tilted to 90 degrees. The module must be powered by a mobile power source. The module must have an onboard screen that prints x, y, and z angular velocity values (rad/s) rounded to 3 decimal places.

Evidence

Wiring

Code

Crash_Avoidance_Part_3_(OLED_Screen) Code
import adafruit_mpu6050                    #Imports:--
import busio                               #--
import board                               #--  
import time                                #--
import digitalio                           #--
from adafruit_display_text import label    #--
import adafruit_displayio_ssd1306          #--
import terminalio                          #--    
import displayio                           #--

displayio.release_displays() #initializes displays

sda_pin = board.GP14 #init SDA pin
scl_pin = board.GP15 #init SCL pin


i2c = busio.I2C(scl_pin, sda_pin)
display_bus = displayio.I2CDisplay(i2c, device_address=0x3d, reset=board.GP16)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)
mpu = adafruit_mpu6050.MPU6050(i2c, address=0x68)

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

# create the display group
splash = displayio.Group()

# add title block to display group
title = "ANGULAR VELOCITY"
text_area = label.Label(terminalio.FONT, text=title, color=0xFFFF00, x=5, y=5)
splash.append(text_area)
display.show(splash)

while True:
    # the order of this command is (font, text, text color, and location)
    text_area.text = f"Rotation: \n X:{round(mpu.gyro[0],3)} \n Y:{round(mpu.gyro[1],3)} \n Z:{round(mpu.gyro[2],3)}"
    led.value = False
    print(mpu.acceleration)
    while mpu.acceleration[2] < 0.95: 
        led.value = True
        print(mpu.acceleration)
        text_area.text = f"Rotation: \n X:{round(mpu.gyro[0],3)} \n Y:{round(mpu.gyro[1],3)} \n Z:{round(mpu.gyro[2],3)}"

Reflection

Three Things went Wrong:

  • the fString. If you want to format an fString go to this site: adafruit/circuitpython#4723
  • The I2C adresses. Adding another adress to the I2C mixed everything up. I didn't have enought space on the bread board so I had to move some pins around, in turn, this messed up my wiring and I had to redo it.
  • Finding the I2C adress. The code for this is located here. It took a while to get the wiring right.

Crash_Avoidance_Part_4_(Altimeter)

Assignment Description

The module must have an accelerometer that continuously reports x, y, and z acceleration values. The module must have an LED that turns on if the helicopter is tilted to 90 degrees. The module must be powered by a mobile power source. The module must have an onboard screen that prints x, y, and z angular velocity values (rad/s). The module should NOT show a warning light if the device is more than 3 meters above its starting point.

Evidence

Wiring

Code

Crash Avoidance Part 4 (Altimeter) Code
import adafruit_mpu6050
import busio
import board                                   
import time
import digitalio
from adafruit_display_text import label
import adafruit_displayio_ssd1306
import terminalio
import displayio
import adafruit_mpl3115a2

displayio.release_displays()

sda_pin = board.GP14
scl_pin = board.GP15

i2c = busio.I2C(scl_pin, sda_pin)
display_bus = displayio.I2CDisplay(i2c, device_address=0x3d, reset=board.GP16)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)
mpu = adafruit_mpu6050.MPU6050(i2c, address=0x68)

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

sensor = adafruit_mpl3115a2.MPL3115A2(i2c, address=0x60)

# create the display group
splash = displayio.Group()

# add title block to display group
title = "ANGULAR VELOCITY"
text_area = label.Label(terminalio.FONT, text=title, color=0xFFFF00, x=5, y=5)
splash.append(text_area)
display.show(splash)

tim = sensor.altitude

while True:
     # the order of this command is (font, text, text color, and location)
    text_area.text = f"Rotation: Altitude: \n X:{round(mpu.gyro[0],3)} {round(sensor.altitude, 3)}m \n Y:{round(mpu.gyro[1],3)} Pressure: \n Z:{round(mpu.gyro[2],3)} {round(sensor.pressure, 3)}Pa"
    print(mpu.acceleration)
    if mpu.acceleration[2] < 0.95 and sensor.altitude < tim + 3: 
        led.value = True
    else:
        led.value = False
    

Reflection

Two Things Went Wrong:

  • The wiring: I Stripped everything before taking a video.
  • I couldn't get the I2C function to work, the problem was the wiring, make sure that the GND rail on your breadboard is connected to GND on your pico.

 

Onshape_Assignment_Template

Assignment Description

Write your assignment description here. What is the purpose of this assignment? It should be at least a few sentences.

Part Link

Create a link to your Onshape document. Don't forget to turn on link sharing in your Onshape document so that others can see it.

Part Image

Take a nice screenshot of your Onshape document.

Reflection

What went wrong / was challenging, how'd you figure it out, and what did you learn from that experience? Your goal for the reflection is to pass on knowledge that will make this assignment better or easier for the next person. Think about your audience for this one, which may be "future you" (when you realize you need some of this code in three months), me, or your college admission committee!

FEA_Part_1_(Beam_Design)

Assignment Description

A beam must stick straight out from a predetermined platform, and the beam gets a bucket screwed into the side of it, then weight gets added. You need to maximize the ammount of weight that that bucket can hold. This is constrained by these contraints:

  • The beam must use the provided attachment block with no modifications
  • The beam with the attachment block must be able to fully engage with the holder
  • The beam must use the example eye bolt mounting geometry
  • The center of the eyebolt hole must be 180 mm from the front face of the attachment block (in a direction perpendicular to the front face)
  • No part of the beam may extend below the bottom face of the attachment block
  • All vertical angles must be >= 45° measured relative to the horizontal plane (no overhangs)
  • The beam must be PLA material
  • The entire beam, including attachment block, must weight <= 13 grams

Part Link

Create a link to your Onshape document

Part Image

Reflection

For this assignment, three things went wrong:

  • The weight of the object was way too large, so we took advantage of the fact that the nozel is 0.04mm. We removed a 0.03mm layer so that the computer would think that it weighs less than it actually does.
  • We had too much weight again, so this time we filleted the edges down.
  • Originally, the document was unable to be copyed, so we spent a portion of the first class trying to export the object and import it into our own doc which eventually failed because STEP files dont save individual parts, so we couldnt accuratly measure weight.

FEA_Part_3_(Analysis)

Assignment Description

For this assignment we were instructed to take our previous part and use FDA to analyse the stress on our part. We Examined the beams we just created in Onshape, and try to optimize the beam in two ways. Our goal was to minimize beam bending while maximizing the mass the beam can support before failing.

Part Link

Onshape Link

Part Image

Reflection

The FDA simulation forced us to make a big decision fix our curent design or scrap it and start over with the new information we have learned. We decided to do both and redesign the previous part in a new part studio with some new additions. This proved to be the most efective path as we where much faster in creating the new part. Unfortunatly, this was a group project and one of the two groupmates, Jakob, didn't manage to help.

FEA_Part_4_(Iterative_Design)

Assignment Description

After simulation, you should have an idea of where your beam needs to improve. Now you’ll enter the iterative design cycle. Improve the beam based on your findings from the FEA simulation, then simulate again. You should be able to dramatically reduce the maximum stress and bending of the beam over the course of several simulations and redesigns.

Part Link

ENGR4 Beam Starter Document - Graham and Jacob

Part Image

Assembly 1

Reflection

Three things went wrong:

  • When creating the force, the window that pops up prompt you for a direction based on a mate connecter, an instance and the option to load a region. LOAD THE REGION, without any regions loaded, my design holds 25 lbs of force, but with the loading it holds 5.

  • Holes in designs are very useful, sense the restrictions were revolved around us not being allowed to create overhangs over 45*, I was at a loss as to how to make the design better, but, we're allowed to use holes at the maximum size of 5mm. These holes take away unnessisary material and allow you to use it elsewhere.
  • Corners of builds are considered breakpoints, this is because all of the stress is compiled into one small edge. Use the fillet tool to reduce this problem, but not the chamfer because that tool doesnt allow for curveness, and that's a nesesity for structural integrity.

Improvments:

  • N/A, our sedign in more complicated and gholds the same weight due to an unfortunate mishap.
  • Designing speed, I spent 8 hours designing this incorrectly, I learned how to OnShape faster and thats it.

Landing_Area_Part_1_(Functions)

Assignment Description

In this assignment you had to make a computer calculate the area of a triangle based off of three inputed coordanites.

Evidence

Code

Landing Area Part 1 (Functions) Code
import time # imports
x1 = 0 # variable values
x2 = 0 -
x3 = 0 -
y1 = 0 -
y2 = 0 -
y3 = 0 -

def triangle(x1, y1, x2, y2, x3, y3):# defininf function
    try:
        pointArray = Input.split(",")
        x1 = float(pointArray[0]) # Points location in the array
        y1 = float(pointArray[1]) -
        x2 = float(pointArray[2]) -
        y2 = float(pointArray[3]) -
        x3 = float(pointArray[4]) -
        y3 = float(pointArray[5]) -
        p = (abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)))/2.0  # finding the area of the triangle
        return p
    except:
        print("Uh Oh. Do it again.") #error message
        p = 0
        return p

while True:
    Input = input("Points: ")# taking input from computer prompt

    area = triangle(x1, y1, x2, y2, x3, y3)# calling defined function
    if area == 0:  # error for triangle not working
        print("Are you sure thats a triangle?")
        continue
    else:
        print("Here is yo area! " + str(area)) # writing the triangle area

Reflection

Three things went wrong:

  • To find the area of a triangle you have to find the absolute value of the number, line 17, you can't use "||" signs, instead you have to use the function abs().
  • When taking inputs, you can spling the string into arrays using the object.split() function. This turns your points into ARRAYS, you still have to call the value based off of its location in the array.
  • To print the points you have to turn them into strings otherwise the computer gets mad at you.

Landing Area Part 2 (Plotting)

Assignment Description

The code must ask for the user to input a set of three coordinates in (x,y) format The triangle area must be determined using a function If the user inputs coordinates incorrectly (letters or improper format) the code should return to the input stage, it should not throw an error or exit the script The triangle area must be printed to the screen in this format: “The area of the triangle with vertices (x,y), (x,y), (x,y) is {area} square km. The code must return to the input stage after printing the area, and wait for user input. An onboard OLED screen must plot each triangle on a graph relative to the base location.

Evidence

Wiring

Code

Landing Area Part 1 (Functions) Code
import adafruit_display_shapes
import busio
import board
import time
import digitalio
from adafruit_display_text import label
import adafruit_displayio_ssd1306
import terminalio
import displayio
import adafruit_mpl3115a2
from adafruit_display_shapes.triangle import Triangle
from adafruit_display_shapes.line import Line
from adafruit_display_shapes.circle import Circle

displayio.release_displays()

sda_pin = board.GP14
scl_pin = board.GP15

splash = displayio.Group()

i2c = busio.I2C(scl_pin, sda_pin)
display_bus = displayio.I2CDisplay(i2c, device_address=0x3d, reset=board.GP16)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)

x1 = 0
x2 = 0
x3 = 0
y1 = 0
y2 = 0
y3 = 0

title = "Graph"
text_area = label.Label(terminalio.FONT, text=title, color=0xFFFF00, x=5, y=5)
splash.append(text_area)
display.show(splash)

def triangle(x1, y1, x2, y2, x3, y3):
    try:
        sametriangle = False
        
        if Input == Input:
            sametriangle = True
        pointArray = Input.split(",")
        x1 = float(pointArray[0])
        y1 = float(pointArray[1])
        x2 = float(pointArray[2])
        y2 = float(pointArray[3])
        x3 = float(pointArray[4])
        y3 = float(pointArray[5])

        triangle = Triangle(int(x1) + 64, 32 - int(y1), int(x2) + 64, 32 - int(y2), int(x3) + 64, 32 - int(y3), outline=0xFFFFFF)
        splash.append(triangle)
        if sametriangle == True:
            
            p = (abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)))/2.0
            return p
        
    except:
        print("Uh Oh. Do it again.")
        p = 0
        return p

    



while True:
    vline = Line(64, 0, 64, 64, color=0xFFFFFF)
    hline = Line(0, 32, 128, 32, color=0xFFFFFF)
    circle = Circle(64, 32, 2, outline=0xFFFFFF)
    splash.append(circle)
    splash.append(hline)
    splash.append(vline)
    Input = input("Points: ")

    area = triangle(x1, y1, x2, y2, x3, y3)
    
    if area == 0:
        print("Are you sure thats a triangle?")
        continue
    else:
        print("Here is yo area! " + str(area))

Reflection

Two things went wrong with this assignment:

  • Plotting the verticies of the triangle has to be done in a certain way. You need to add 64 to the x value and subtract the y value from 32 because of how the boards coordanize system is setup.
  • The SDA and SCL pins go to SDA and SCL on the pico, but you also have to use their i2c adress, especially if you made the mistake of using i2c. Its only useful to use adresses if there is more than one thing plugged into the pico through the same pins.

Morse Code Part 1 (Translation)

Assignment Description

Your script must accept text input by the user If the user types “-q”, your script must exit If the user types anything else, your script must translate the text to morse code dots and dashes, and print those to the monitor The printed text must use a space to show breaks between letters, and a slash to show breaks between words

Evidence

Code

Morse Code Part 1 (Translation) Code
import board
import pulseio
import time

# Dictionary representing the morse code chart
MORSE_CODE = { 'A':'.-', 'B':'-...',
    'C':'-.-.', 'D':'-..', 'E':'.',
    'F':'..-.', 'G':'--.', 'H':'....',
    'I':'..', 'J':'.---', 'K':'-.-',
    'L':'.-..', 'M':'--', 'N':'-.',
    'O':'---', 'P':'.--.', 'Q':'--.-',
    'R':'.-.', 'S':'...', 'T':'-',
    'U':'..-', 'V':'...-', 'W':'.--',
    'X':'-..-', 'Y':'-.--', 'Z':'--..',
    '1':'.----', '2':'..---', '3':'...--',
    '4':'....-', '5':'.....', '6':'-....',
    '7':'--...', '8':'---..', '9':'----.',
    '0':'-----', ',':'--..--', '.':'.-.-.-',
    '?':'..--..', '/':'-..-.', '-':'-....-',
    '(':'-.--.', ')':'-.--.-', ' ':'/'}

while True:
    Input = input()
    x = Input.upper()
    for letter in x:
        print(MORSE_CODE[letter], end=" ")
    if Input == str("-q"):
        break

Reflection

  • For the break function, there is a specific word that is used to break the code and stop its running. "break".
  • The for function is vital for this code, the for loop is structured like this:
 for x in y:
     do this

Morse Code Part 2 (Transmission)

Assignment Description

Your script must accept text input by the user If the user types “-q”, your script must exit If the user types anything else, your script must translate the text to morse code dots and dashes, and print those to the monitor The printed text must use a space to show breaks between letters, and a slash to show breaks between words The script must flash an LED to transmit the morse code message using the timing sequence shown below

Evidence

Wiring

Code

Morse Code Part 2 (Transmission) Code
import board
import pwmio
import time

buzzer = pwmio.PWMOut(board.GP17, duty_cycle=0, frequency=1440)
OFF = 0
ON = 2**15
DOT = 0.05
DASH = 3*DOT

 
# Dictionary representing the morse code chart
MORSE_CODE = { 'A':'.-', 'B':'-...',
    'C':'-.-.', 'D':'-..', 'E':'.',
    'F':'..-.', 'G':'--.', 'H':'....',
    'I':'..', 'J':'.---', 'K':'-.-',
    'L':'.-..', 'M':'--', 'N':'-.',
    'O':'---', 'P':'.--.', 'Q':'--.-',
    'R':'.-.', 'S':'...', 'T':'-',
    'U':'..-', 'V':'...-', 'W':'.--',
    'X':'-..-', 'Y':'-.--', 'Z':'--..',
    '1':'.----', '2':'..---', '3':'...--',
    '4':'....-', '5':'.....', '6':'-....',
    '7':'--...', '8':'---..', '9':'----.',
    '0':'-----', ',':'--..--', '.':'.-.-.-',
    '?':'..--..', '/':'-..-.', '-':'-....-',
    '(':'-.--.', ')':'-.--.-', ' ':'/'}
BEEP = {'.': DOT , '-': DASH}

while True:
    Input = input()
    x = Input.upper()
    if Input == str("-q"):
        break
    for letter in x:
        if letter == " ":
            time.sleep(7*DOT)
            print("/", end=" ")
            continue
        print(MORSE_CODE[letter], end=" ")
        for pulse in MORSE_CODE[letter]:
            # print(f"pulsing for {pulse} for letter {letter}")
            buzzer.duty_cycle = ON
            time.sleep(BEEP[pulse])
            buzzer.duty_cycle = OFF
            time.sleep(DOT)
        time.sleep(3*DOT)
    print()

Reflection

  • I had some extra time and changed the light into a piezo buzzer, the only difference is the PMW. When using PMW make sure your duty cycle and frequency are consistent with your buzzer, otherwise, they won't work.
  • The code turns the buzzer on waits for x time and then turns it off, this is more efficient than turning it on for a specific amount of time because I do not have to deal with time.monotonic.
  • When coding, it helps to know that all the lengths in dots are based on the dot 0.25s. for efficiency sake, I made that 0.05s instead

 

Data_Part_1_(Storage)

Assignment Description

Your Pico must operate in “headless” mode – unplugged from the computer with a battery An LED must turn on when the Pico is tilted (same as Crash Avoidance Part 2) Your Pico must record time, X, Y, Z acceleration data, and whether or not the Pico was tilted You must save this information to the Pico’s onboard storage You must blink the onboard LED every time you save data You must be able to retrieve this data when plugged back into the computer

Evidence

Wiring

Code

Data Part 1 (Storage) Code
import adafruit_mpu6050
import busio
import board                                   
import time
import digitalio

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

sda_pin = board.GP14
scl_pin = board.GP15
i2c = busio.I2C(scl_pin, sda_pin)
mpu = adafruit_mpu6050.MPU6050(i2c)

st = time.monotonic()
tilt = False

while True:
    with open("/data.csv", "a") as datalog:
        ct = time.monotonic()
        if mpu.acceleration[2] < 9:
            led.value = True
            tilt = True
        else:
            led.value = False
            tilt = False
        datalog.write(f"{float(ct)},{round(mpu.gyro[0],3)},{round(mpu.gyro[1],3)},{round(mpu.gyro[2],3)},{str(tilt)},{mpu.acceleration[2]}\n")
        time.sleep(0.5)
        datalog.flush()

Reflection

Three things went wrong:

  • When trying to edit the code. You have to restart the pico and turn it to "code mode" otherwise you get an error that explains how stupid you are for trying to write in a read only file type.
  • When using an fString to write your data, refrenece this
  • It is very important to keep clean wiring, my wiring was very iffy and i got my board reset multiple times on end.

Data Part 2 (Analysis)

Assignment Description

Create a line graph with time on the X axis and acceleration on the Y axis. X, Y, and Z accelerations must be present on the same plot. Create a chart with time on the X axis and whether or not the Pico was tilted on the Y axis. Title each graph, and label each axis including units.

Evidence

Capture

Reflection

Two things went wrong:

  • I tried to use Excel, don't use excel.
  • When making the chart, make sure that the units are clear. For example, I used degrees/second for my acceleration of rotation, but its very possible to mess that up by saying theyre radians.

Media Test

Your readme will have various images and gifs on it. Upload a test image and test gif to make sure you've got the process figured out. Pick whatever image and gif you want!

Test Link

Test Image

Test GIF

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages