Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab-1-WENXI-WEI-worked-with-YANGBO-ZHOU #65

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
29 changes: 29 additions & 0 deletions 3.2 code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## ESE519 lab1 part 3.2

import time
import board
from adafruit_apds9960.apds9960 import APDS9960
import neopixel

pixels = neopixel.NeoPixel(board.NEOPIXEL, 1)

i2c = board.STEMMA_I2C()
apds = APDS9960(i2c)
apds.enable_color = True
apds.color_integration_time = 10

while True:
# wait for color data to be ready
while not apds.color_data_ready:
time.sleep(0.005)

# get the data and print the different channels
r, g, b, c = apds.color_data
print("red: ", r)
print("green: ", g)
print("blue: ", b)
print("clear: ", c)



pixels.fill((0, g/257, 0))
Binary file added 3.2 gif.GIF
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions 4.4 code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# ESE519 lab1 part 4.4

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import digitalio
import usb_hid
from adafruit_apds9960.apds9960 import APDS9960
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode


keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)

i2c = board.STEMMA_I2C()

apds = APDS9960(i2c)
apds.enable_proximity = True
apds.enable_gesture = True

# Uncomment and set the rotation if depending on how your sensor is mounted.
# apds.rotation = 270 # 270 for CLUE

keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)

i2c = board.STEMMA_I2C()

apds = APDS9960(i2c)

apds.enable_proximity = True
apds.enable_gesture = True

# Uncomment and set the rotation if depending on how your sensor is mounted.
# apds.rotation = 270 # 270 for CLUE
time.sleep(3)
keyboard_layout.write("There is a 'variant' in the matrix. Please try to fix it.\n")
keyboard_layout.write("Use your gesture to control the cursor.\n")
keyboard_layout.write('''
0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0''')

count = 0

while True:
dist = apds.proximity
print(dist)

if dist == 6:
count = count + 1
print("count: ", count)
if count > 20:
keyboard.send(Keycode.BACKSPACE)
keyboard.send(Keycode.ZERO)
break

gesture = apds.gesture()

if gesture == 0x01:
print("up")
keyboard.send(Keycode.UP_ARROW)
count = 0
if gesture == 0x02:
print("down")
keyboard.send(Keycode.DOWN_ARROW)
count = 0
if gesture == 0x03:
print("left")
keyboard.send(Keycode.LEFT_ARROW)
count = 0
if gesture == 0x04:
print("right")
keyboard.send(Keycode.RIGHT_ARROW)
count = 0


Binary file added 4.4 gif.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Diagram of Embedded System.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
University of Pennsylvania, ESE 5190: Intro to Embedded Systems, Lab 1

(TODO) YOUR NAME HERE
(TODO) LinkedIn, personal website, twitter, etc.
Tested on: (TODO) MacBook Pro (14-inch, 2021), macOS Monterey 12.5.1
Wenxi Wei
[email protected]
Tested on: XiaoXinPro 16ACH 2021

(TODO: Your README)
`Part 3.3:` In this part, color sensor in APDS-9960 will send signal to RP2040. Thus, RGB LED in RP2040 tracks the brightness reading from APDS-9960. The gif figure below shows LED changes with the brightness of the firefly.

Include lab questions, screenshots, analysis, etc. (Remember, this is public, so don't put anything here you don't want to share with the world.)
![ezgif com-gif-maker](https://user-images.githubusercontent.com/114196821/192076377-db8b936e-9183-4e12-8b6a-1d76c5bbd428.gif)


`Part 4.4:` In this part, we designed a game. Computer generates a matrix with all 0 except one 1. As cursor move up, down, left or right in the matrix according to gesture tested by APDS-9960, users can use gesture to move cursor to approach 1. After approaching 1, users move finger twice around APDS-9960, the keyboard will delete 1 and type 0. At the end of the game, all elements in matrix are 0.

![4 4 gif](https://user-images.githubusercontent.com/114196821/192076289-c3b3bcab-0912-4a18-842c-9e16174ceb31.gif)

`The embedded system of part 4.4 and how components interact:` To realize the interaction between components, the most important part is I2C protocol shows in figure 1-1. I2C protocol uses 2 wires called SCL and SDA to transmit signals between master component (RP2040) and slave component (APDS9960). SCL is serial clock pin and SDA is serial data pin. When the SCL is high potential, SDA will jump from high potential to low potential, that is, the slave will enter to the waiting state to receive the address bit (as shown in figure 1-2). Figure 1-3 clarifies the signal transmission: Part 1 is starting command. If the command of part 1 is issued, the slave’s address in part 2 will be read or written which is controlled by part 3. After the master finishes addressing, it will wait for the slave response ACK signal (part 4). Part 5 is the register address inside the sensor. In 4.4 design, the gesture information is stored in this register. In summary, I2C protocol is a widely used. If we need to connect multiple master slave devices, it will make the operation simple and efficient.

![Diagram of Embedded System](https://user-images.githubusercontent.com/114196821/192072496-b77cf929-3127-44ef-bafc-c4550b65efbe.jpg)