Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ Other IDE can be used, including Visual Studio Code or
* 2 [tactile switches](https://sten-eswitch-13110800-production.s3.amazonaws.com/system/asset/product_line/data_sheet/184/TL59-TL58.pdf)


## Code Cleanliness and Automation

1. This repo uses `poetry` for python dependency management. See the [docs](https://python-poetry.org/docs/) for an installation guide and introduction.
1. Once `poetry` is installed on your computer, you may run `poetry install` to create a virtualenv in which all of your dependencies will be installed (separate from the system python path).

2. `pylint` is as a dev dependency for static code analysis. `pylint` is best described in the [docs](https://pylint.readthedocs.io/en/stable/):
> Pylint analyses your code without actually running it. It checks for errors, enforces a coding standard, looks for code smells, and can make suggestions about how the code could be refactored.
1. One may run pylint in this environment by typing: `poetry run pylint *`

3. `mypy` is added as a dependency for type checking. This ensures you don't do silly things like suming an int with a string.
1. One may run mypy in this environment by typing: `poetry run mypy *`

4. `pre-commit` is added as a dev dependency for a pre-commit hook for `git`. This tool is configured with the `.pre-commit-config.yaml` and is one of the most convenient tools when collaborating with teams, as it automatically fixes your files or alerts you about problems before a commit is made.
1. `black` (an automatic python code formatter) is run before you make a commit with git.
2. You can run `pre-commit` before commiting code by entering `poetry run pre-commit run --all`


## Reference

* [Pico WH pinout diagram](https://datasheets.raspberrypi.com/picow/PicoW-A4-Pinout.pdf) shows the connections to analog and digital IO.
Expand Down
7 changes: 7 additions & 0 deletions assignment/exercise01-resp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Exercise: applications of analog input
**Ryan Lagoy**


1. With minimum light (hand covering the photoresistor), the max value was 44000. When shining the light on the photocell, the min value was approximately 3300.

Note: I adjusted the duty cycle to 0.01 so the LED looked like it was dimming and not blinking (as seen by eye).
9 changes: 9 additions & 0 deletions assignment/exercise02-resp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Exercise: PWM sound output
**Ryan Lagoy**


I wanted to play Sweet Caroline on my Rasp Pi, and so I followed these steps:
1. Found the sheet music here: https://musescore.com/user/34214067/sweet-caroline-2012-neil-diamond-piano-arrangement
2. I noticed the song used the A major scale, so I defined a dictionary of all of the notes in the scale that were needed.
3. I created a Note dataclass which stores the pitch and the duration.
4. Using the output from the previous steps I was able to play the first few bars of Sweet Caroline.
28 changes: 28 additions & 0 deletions assignment/exercise03-resp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Exercise: Game
**Ryan Lagoy**

This excercise required both a hardware and cloud based solution.

On the hardware side of things, the Ras Pi micropython code required some implementation. The following key tasks were:

1. Implement the scorer, and define a data structure to hold each score.
2. Post the data to a REST API (see cloud section).

Note 1: the data dict included a user pk number so that the cloud could differentiate between users. For this implementation, 2 users
were created. Additionally, an ID was assigned for each score record.

Note 2: I linted the exercise_game.py file, so it meets the Python coding standards.

On the cloud side of things, a Django project was created that implemented the following features:

1. Allauth for Google/social log-ins
2. Implemented a PostGres Database
3. Implemented a REST API for the score data
4. Created a dashboard with bootstrap formating

The source code for this project can be found here: https://github.com/rlagoy/2024-mini-cloud.
There is a deploy folder which includes all of the required files for deploying to a Digital Ocean droplet.

View the webUI at halara.cloud in your browser.

Lastly, the final code wasn't tested on the RasPi, since one of the students borrowed mine, and I wasn't able to re-test.
102 changes: 0 additions & 102 deletions assignment/exercise_game.py

This file was deleted.

45 changes: 0 additions & 45 deletions assignment/exercise_light.py

This file was deleted.

39 changes: 0 additions & 39 deletions assignment/exercise_sound.py

This file was deleted.

Empty file added mini_2024/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions mini_2024/django_rest_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import requests
import struct
import time
import random


def generate_uuid4():
# Generate 16 random bytes
random_bytes = bytearray(random.getrandbits(8) for _ in range(16))

# Set the version to 4 (UUID version 4)
random_bytes[6] = (random_bytes[6] & 0x0F) | 0x40

# Set the variant to RFC 4122
random_bytes[8] = (random_bytes[8] & 0x3F) | 0x80

# Convert bytes to a UUID string
uuid_str = struct.unpack(">IHH8B", random_bytes)
return f"{uuid_str[0]:08x}-{uuid_str[1]:04x}-{uuid_str[2]:04x}-{uuid_str[3]:02x}{uuid_str[4]:02x}-77{uuid_str[5]:02x}{uuid_str[6]:02x}{uuid_str[7]:02x}{uuid_str[8]:02x}{uuid_str[9]:02x}"


now = time.localtime()
now_str = "-".join(map(str, now[:3])) + "T" + ":".join(map(str, now[3:6]))

score_list = [random.random(), random.random()]
data_dict = {
"id": generate_uuid4(),
"user": [2],
"timestamp": now_str,
"max_time_s": max(score_list),
"min_time_s": min(score_list),
"average_time_s": sum(score_list) / len(score_list),
"score": 3,
}

print(data_dict)
database_api_url = "https://halara.cloud/pico/pico-data/"
response = requests.post(database_api_url, json=data_dict)
print(response.text)
Loading