From 4320c0ec357462632754213864b2d23fab26e455 Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 22:02:30 -0400
Subject: [PATCH 01/13] Update README.md
---
README.md | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index e61ff2f..18c8962 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,33 @@
University of Pennsylvania, ESE 5190: Intro to Embedded Systems, Lab 1
- (TODO) YOUR NAME HERE
+ Dvisha Kishore Bakarania
(TODO) LinkedIn, personal website, twitter, etc.
- Tested on: (TODO) MacBook Pro (14-inch, 2021), macOS Monterey 12.5.1
+ Tested on:
+
+**Adafruit QT Py RP2040** and **Adafruit APDS9960 Proximity, Light, RGB, and Gesture Sensor** when come together, can help newbies create their own cool embedded system projects. Let's start! This project uses the sensor data (color, proximity, brightness) to implement a "firefly" and a custom real-time visualizer. All you will need is an Adafruit dev board with RP2040 and a sensor.
+
+**Requirements:**
+
+Adafruit QT Py RP2040
+
+
+
+Now, let's implement a **firefly**!
+
+So, the gist here is: the Neopixel led on the QT Py board should blink in synchronization with an actual firefly video. For this, we have used the brightness measurement feature of the sensor. Using the APDS9960, the brightness of the flashing firefly in the video is measured and this reading is used to control the pixels of the neopixel led by scaling the measured sensor output data to adjust the brightness/blinking of the neopixel so that it behaves just like the firefly in the video.
+
+Below is the snippet of the code:
+
+
+
+
+
+
+
+
+
+Up-next is the implementation of a **real-time visualizer** using keyboard emulator to get real time update of the detected sensor data. This can be done using HID keyboard library. The intention here is to get a real time update of any change in brightness level as sensed by the APDS9600.
+
+We will be using two keys: 'O' and 'Backspace' to indicate any change at the input to the sensor. As and when there is an increase in the brightness level at the input to the sensor, any text editor in your laptop should start typing 'O's. If the brightness at the sensor input decreases then the 'Backspace' key should come into action and start erasing the 'O's so that the user is updated of the change(increase/decrease) at the sensor input. This can be done by adjusting the threshold so that an increase in brightness leads to typing 'O' and decrease leads to the erasing of 'O's using Backspace.
-(TODO: Your README)
-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.)
From 0242ea836420b21e8dc531dab35f9597031e4db9 Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 22:25:21 -0400
Subject: [PATCH 02/13] Update README.md
---
README.md | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/README.md b/README.md
index 18c8962..6b252c5 100644
--- a/README.md
+++ b/README.md
@@ -30,4 +30,11 @@ Up-next is the implementation of a **real-time visualizer** using keyboard emula
We will be using two keys: 'O' and 'Backspace' to indicate any change at the input to the sensor. As and when there is an increase in the brightness level at the input to the sensor, any text editor in your laptop should start typing 'O's. If the brightness at the sensor input decreases then the 'Backspace' key should come into action and start erasing the 'O's so that the user is updated of the change(increase/decrease) at the sensor input. This can be done by adjusting the threshold so that an increase in brightness leads to typing 'O' and decrease leads to the erasing of 'O's using Backspace.
+
+
+Also, one important point to note here is that you might probably be using a keyboard to program your RP2040, so if the RP2040 is also sending keystrokes to the
+laptop this can make it quite annoying to reprogram. So, there needs to be a way to stop it from endlessly writing the letter'O' and that is to use an 'escape hatch'. The intention here is to make the system braek out of the main loop on sensing a partivular color. We will be using 'blue' color. So, if I need to stop the program from endlessly writing, I should point my sensor to a 'blue' color and it will break from the main loop as illustrated through the gif below:
+
+
+
From d90a1a26f1719124315b10e67fdbcafa3e667dc8 Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 22:27:23 -0400
Subject: [PATCH 03/13] Update README.md
---
README.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/README.md b/README.md
index 6b252c5..d97ecf6 100644
--- a/README.md
+++ b/README.md
@@ -37,4 +37,7 @@ laptop this can make it quite annoying to reprogram. So, there needs to be a way
+
+
+
From 44176e80b216d40ea9024ba6fdff0c01247a407c Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 22:29:13 -0400
Subject: [PATCH 04/13] Update README.md
---
README.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index d97ecf6..d71f88c 100644
--- a/README.md
+++ b/README.md
@@ -33,11 +33,13 @@ We will be using two keys: 'O' and 'Backspace' to indicate any change at the inp
Also, one important point to note here is that you might probably be using a keyboard to program your RP2040, so if the RP2040 is also sending keystrokes to the
-laptop this can make it quite annoying to reprogram. So, there needs to be a way to stop it from endlessly writing the letter'O' and that is to use an 'escape hatch'. The intention here is to make the system braek out of the main loop on sensing a partivular color. We will be using 'blue' color. So, if I need to stop the program from endlessly writing, I should point my sensor to a 'blue' color and it will break from the main loop as illustrated through the gif below:
+laptop this can make it quite annoying to reprogram. So, there needs to be a way to stop it from endlessly writing the letter'O' or erasing, and that is to use an 'escape hatch'. The intention here is to make the system braek out of the main loop on sensing a partivular color. We will be using 'blue' color. So, if I need to stop the program from endlessly writing/erasing, I should point my sensor to 'blue' color and it will break from the main loop as illustrated through the gif below:

+Code snippet for implementing this:
+
From 85dbe91d009fa2eb828dc7a3b938b6d30d75d610 Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 22:45:06 -0400
Subject: [PATCH 05/13] Update README.md
---
README.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/README.md b/README.md
index d71f88c..58074eb 100644
--- a/README.md
+++ b/README.md
@@ -41,5 +41,8 @@ laptop this can make it quite annoying to reprogram. So, there needs to be a way
Code snippet for implementing this:
+
+
+
From 7d49fce3bcd7bafa0d96acdbfcbc6dd4a099441c Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 22:47:41 -0400
Subject: [PATCH 06/13] Update README.md
---
README.md | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 58074eb..544f0e6 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,7 @@ Below is the snippet of the code:
+

@@ -38,7 +39,9 @@ laptop this can make it quite annoying to reprogram. So, there needs to be a way

-
+
+
+
Code snippet for implementing this:
From d0ab2017a87661d998aef075b8a063f77134ef47 Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 22:52:45 -0400
Subject: [PATCH 07/13] Update README.md
---
README.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 544f0e6..068e6fc 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
University of Pennsylvania, ESE 5190: Intro to Embedded Systems, Lab 1
-
- Dvisha Kishore Bakarania
- (TODO) LinkedIn, personal website, twitter, etc.
- Tested on:
+
+ Dvisha Kishore Bakarania
+ LinkedIn: https://www.linkedin.com/in/dvisha-bakarania-9370b2146?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_contact_details%3BNtJBfZpDTEKluhukjP7uqg%3D%3D
+ Tested on: Windows 11 Home Version 21H2
**Adafruit QT Py RP2040** and **Adafruit APDS9960 Proximity, Light, RGB, and Gesture Sensor** when come together, can help newbies create their own cool embedded system projects. Let's start! This project uses the sensor data (color, proximity, brightness) to implement a "firefly" and a custom real-time visualizer. All you will need is an Adafruit dev board with RP2040 and a sensor.
From b65a1637698e67f1b7fd6842b1c4b3627b958bdd Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 22:56:56 -0400
Subject: [PATCH 08/13] Update README.md
---
README.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 068e6fc..9b0835c 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,9 @@
University of Pennsylvania, ESE 5190: Intro to Embedded Systems, Lab 1
Dvisha Kishore Bakarania
- LinkedIn: https://www.linkedin.com/in/dvisha-bakarania-9370b2146?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_contact_details%3BNtJBfZpDTEKluhukjP7uqg%3D%3D
+
+ LinkedIn: [Dvisha Bakarania](https://www.linkedin.com/in/dvisha-bakarania-9370b2146?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_contact_details%3BNtJBfZpDTEKluhukjP7uqg%3D%3D)
+
Tested on: Windows 11 Home Version 21H2
**Adafruit QT Py RP2040** and **Adafruit APDS9960 Proximity, Light, RGB, and Gesture Sensor** when come together, can help newbies create their own cool embedded system projects. Let's start! This project uses the sensor data (color, proximity, brightness) to implement a "firefly" and a custom real-time visualizer. All you will need is an Adafruit dev board with RP2040 and a sensor.
From 0fab0c48a4c432562012f3c413cd339e4dae345c Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 23:02:06 -0400
Subject: [PATCH 09/13] Add files via upload
---
Firefly.py | 34 +++++++++++++++++++++++++++++
Real_Time_Visualizer.py | 48 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+)
create mode 100644 Firefly.py
create mode 100644 Real_Time_Visualizer.py
diff --git a/Firefly.py b/Firefly.py
new file mode 100644
index 0000000..29aa88a
--- /dev/null
+++ b/Firefly.py
@@ -0,0 +1,34 @@
+import time
+import board
+import busio
+from adafruit_apds9960.apds9960 import APDS9960
+import neopixel
+
+pixels = neopixel.NeoPixel(board.NEOPIXEL, 1)
+
+i2c = board.I2C()
+apds = APDS9960(i2c)
+apds.enable_color = True
+
+print("apds_time: ", apds.color_integration_time)
+apds.color_integration_time = 64
+
+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)
+ print("apds_time_updated: ", apds.color_integration_time)
+
+ # scale the measured 'c' to adjust the neopixel output
+ pixels.fill((c / 6, c / 6, 0))
+
+ time.sleep(0.5)
+
+
diff --git a/Real_Time_Visualizer.py b/Real_Time_Visualizer.py
new file mode 100644
index 0000000..e554804
--- /dev/null
+++ b/Real_Time_Visualizer.py
@@ -0,0 +1,48 @@
+import time
+import board
+import busio
+from adafruit_apds9960.apds9960 import APDS9960
+import digitalio
+import usb_hid
+from adafruit_hid.keyboard import Keyboard
+from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
+from adafruit_hid.keycode import Keycode
+
+i2c = board.I2C()
+apds = APDS9960(i2c)
+apds.enable_color = True
+
+keys_pressed = [Keycode.O, Keycode.BACKSPACE]
+control_key = Keycode.SHIFT
+time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
+keyboard = Keyboard(usb_hid.devices)
+keyboard_layout = KeyboardLayoutUS(keyboard)
+
+while True:
+ while not apds.color_data_ready:
+ time.sleep(0.005)
+ r, g, b, c = apds.color_data
+ print("red: ", r)
+ print("green: ", g)
+ print("blue: ", b)
+ print("clear: ", c)
+
+ if b>50:
+ if c>1400:
+ j=0
+ key = keys_pressed[j]
+ if isinstance(key, str):
+ keyboard_layout.write(key)
+ else:
+ keyboard.press(control_key, key)
+ keyboard.release_all()
+ else:
+ j=1
+ key = keys_pressed[j]
+ if isinstance(key, str):
+ keyboard_layout.write(key)
+ else:
+ keyboard.press(control_key, key)
+ keyboard.release_all()
+
+
From 3a8a65675cf863e95c0b865e0bfb4c73537ea037 Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 23:05:31 -0400
Subject: [PATCH 10/13] Update README.md
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 9b0835c..1a9dd43 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,7 @@ Below is the snippet of the code:
+Code can also be found at: [Firefly](https://www.linkedin.com/in/dvisha-bakarania-9370b2146?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_contact_details%3BNtJBfZpDTEKluhukjP7uqg%3D%3D)
Up-next is the implementation of a **real-time visualizer** using keyboard emulator to get real time update of the detected sensor data. This can be done using HID keyboard library. The intention here is to get a real time update of any change in brightness level as sensed by the APDS9600.
We will be using two keys: 'O' and 'Backspace' to indicate any change at the input to the sensor. As and when there is an increase in the brightness level at the input to the sensor, any text editor in your laptop should start typing 'O's. If the brightness at the sensor input decreases then the 'Backspace' key should come into action and start erasing the 'O's so that the user is updated of the change(increase/decrease) at the sensor input. This can be done by adjusting the threshold so that an increase in brightness leads to typing 'O' and decrease leads to the erasing of 'O's using Backspace.
From c1ee2a235d8a2e01a7725ff37c65071b9b8b2d7a Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 23:07:16 -0400
Subject: [PATCH 11/13] Update README.md
---
README.md | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 1a9dd43..3811bfa 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,10 @@ Below is the snippet of the code:
-Code can also be found at: [Firefly](https://www.linkedin.com/in/dvisha-bakarania-9370b2146?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_contact_details%3BNtJBfZpDTEKluhukjP7uqg%3D%3D)
+Code can also be found at: [Firefly](https://github.com/dvishab/ese5190-2022-lab1-firefly/blob/3a8a65675cf863e95c0b865e0bfb4c73537ea037/Firefly.py)
+
+
+
Up-next is the implementation of a **real-time visualizer** using keyboard emulator to get real time update of the detected sensor data. This can be done using HID keyboard library. The intention here is to get a real time update of any change in brightness level as sensed by the APDS9600.
We will be using two keys: 'O' and 'Backspace' to indicate any change at the input to the sensor. As and when there is an increase in the brightness level at the input to the sensor, any text editor in your laptop should start typing 'O's. If the brightness at the sensor input decreases then the 'Backspace' key should come into action and start erasing the 'O's so that the user is updated of the change(increase/decrease) at the sensor input. This can be done by adjusting the threshold so that an increase in brightness leads to typing 'O' and decrease leads to the erasing of 'O's using Backspace.
From edebdd48023292856e57aa045768cb7b9081913c Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 23:08:32 -0400
Subject: [PATCH 12/13] Update README.md
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 3811bfa..32d9547 100644
--- a/README.md
+++ b/README.md
@@ -52,6 +52,7 @@ Code snippet for implementing this:
+Code can also be found at: [Real Time Visualizer](https://github.com/dvishab/ese5190-2022-lab1-firefly/blob/c1ee2a235d8a2e01a7725ff37c65071b9b8b2d7a/Real_Time_Visualizer.py)
From 895a72c6fb30240ec3c3c650936806f71950e527 Mon Sep 17 00:00:00 2001
From: dvishab <114099174+dvishab@users.noreply.github.com>
Date: Fri, 23 Sep 2022 23:12:31 -0400
Subject: [PATCH 13/13] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 32d9547..8f7f48e 100644
--- a/README.md
+++ b/README.md
@@ -40,7 +40,7 @@ We will be using two keys: 'O' and 'Backspace' to indicate any change at the inp
Also, one important point to note here is that you might probably be using a keyboard to program your RP2040, so if the RP2040 is also sending keystrokes to the
-laptop this can make it quite annoying to reprogram. So, there needs to be a way to stop it from endlessly writing the letter'O' or erasing, and that is to use an 'escape hatch'. The intention here is to make the system braek out of the main loop on sensing a partivular color. We will be using 'blue' color. So, if I need to stop the program from endlessly writing/erasing, I should point my sensor to 'blue' color and it will break from the main loop as illustrated through the gif below:
+laptop this can make it quite annoying to reprogram. So, there needs to be a way to stop it from endlessly writing the letter'O' or erasing, and that is to use an 'escape hatch'. The intention here is to make the system braek out of the main loop on sensing a partivular color. We will be using **'blue'** color. So, if I need to stop the program from endlessly writing/erasing, I should point my sensor to 'blue' color and it will break from the main loop as illustrated through the gif below: