|
1 | 1 | .. _eye-bioamp-arduino-firmware:
|
2 | 2 |
|
3 | 3 | Eye (EOG) BioAmp Arduino Firmware
|
4 |
| -##################################### |
| 4 | +##################################### |
| 5 | + |
| 6 | +What is Electrooculography (EOG)? |
| 7 | +================================== |
| 8 | + |
| 9 | +Electrooculography (EOG) `[1] <https://eyewiki.org/Electrooculogram>`_ is a technique for measuring the corneo-retinal standing potential that exists between the front and the back of the human eye. The resulting signal is called the electrooculogram. |
| 10 | +Primary applications are in ophthalmological diagnosis and in recording eye movements. To measure eye movement, pairs of electrodes are typically placed either above and below the eye or to the left and right of the eye. |
| 11 | +If the eye moves from center position toward one of the two electrodes, |
| 12 | +this electrode "sees" the positive side of the retina and the opposite electrode "sees" |
| 13 | +the negative side of the retina. Consequently, a potential difference occurs between the electrodes. |
| 14 | +Assuming that the resting potential is constant, the recorded potential is a measure of the eye's position. |
| 15 | + |
| 16 | + |
| 17 | +To know more about EOG `visit here <https://en.wikipedia.org/wiki/Electrooculography>`_. |
| 18 | + |
| 19 | +**Who is this for?** |
| 20 | + |
| 21 | +Anyone who's using the BioAmp Hardware for the very first time — whether you're a student, hobbyist, educator, or just curious. No experience needed! |
| 22 | + |
| 23 | +👉 To learn about our BioAmp Hardware checkout :ref:`the hardware page <upsidedownlabs_hardware_home>`. |
| 24 | + |
| 25 | +Step-by-Step Setup Guide |
| 26 | +=========================== |
| 27 | + |
| 28 | +With the hardware in your hands, you're just a few steps away from unlocking its full potential — let's get the software set up! |
| 29 | + |
| 30 | +**Step 1: Downloading GitHub Repository for Hardware** |
| 31 | + |
| 32 | +- This is the code your Arduino needs to read Eye (EOG) signals. |
| 33 | +- You have two easy ways to get the code that will help you read your EOG signals: |
| 34 | + |
| 35 | +.. dropdown:: Simply Download (recommended for beginners) |
| 36 | + :open: |
| 37 | + |
| 38 | + - Go to the GitHub page: `Eye BioAmp Arduino Firmware <https://github.com/upsidedownlabs/Eye-BioAmp-Arduino-Firmware>`_ |
| 39 | + - Click the green “**Code**” button > Download ZIP |
| 40 | + - Unzip the folder and save it somewhere easy to find. |
| 41 | + |
| 42 | +.. dropdown:: Clone using Git (for tech-savvy users) |
| 43 | + |
| 44 | + - Install Git for your OS: https://git-scm.com/ |
| 45 | + - Clone this GitHub repository using |
| 46 | + |
| 47 | + .. code-block:: bash |
| 48 | + |
| 49 | + git clone https://github.com/upsidedownlabs/Eye-BioAmp-Arduino-Firmware |
| 50 | +
|
| 51 | +**Step 2: Application Required** |
| 52 | + |
| 53 | +Before you start using the kit, please download or open the following: |
| 54 | + |
| 55 | +1. **Arduino IDE** |
| 56 | + |
| 57 | + - We need Arduino IDE to upload code to your Arduino board |
| 58 | + - Link to download IDE for your OS: https://www.arduino.cc/en/software |
| 59 | + |
| 60 | +2. **Chords Website** |
| 61 | + |
| 62 | + - We will use Chords Website to visualize the Eye Signals! |
| 63 | + - Open this website: `Chords Web <https://chords.upsidedownlabs.tech>`_ |
| 64 | + |
| 65 | +.. _Connect Your Hardware: |
| 66 | + |
| 67 | +**Step 3: Connect Your Hardware** |
| 68 | + |
| 69 | +1. Plug the Hardware into your Arduino UNO using jumper wires. |
| 70 | +2. Follow the exact wiring diagram from the :ref:`hardware documentation <upsidedownlabs_hardware_home>` of the hardware you are using. |
| 71 | +3. Hardwares that are compatible with Eye BioAmp Firmware: |
| 72 | + |
| 73 | + - :ref:`Bioamp EXG Pill <bioamp-exg-pill>` |
| 74 | + |
| 75 | +It’s just like putting together a puzzle! |
| 76 | + |
| 77 | +**Step 4: Prepare the Electrodes** |
| 78 | + |
| 79 | +- **Using Gel Electrodes:** |
| 80 | + |
| 81 | +1. **Prepare your skin** |
| 82 | + |
| 83 | + - Choose the area where you'll place the electrodes. |
| 84 | + - Clean the skin using **an alcohol swab** or **Nuprep Gel** to remove oils and dead cells — this improves signal clarity. |
| 85 | + |
| 86 | + .. note:: |
| 87 | + |
| 88 | + Need help with skin prep? Check out the full guide here: :ref:`Skin Preparation Guide <skin-preparation>` |
| 89 | + |
| 90 | +2. For **Vertical EOG**, attach the wires to the electrodes, then attach the electrodes to skin (refer diagram below): |
| 91 | + |
| 92 | + - ``IN+`` (positive): Place just below the eye (under the pupil). |
| 93 | + - ``IN–`` (negative): Place just above the eyebrow (in line with the pupil). |
| 94 | + - ``REF`` (reference): Attach on the bony area near the cheek or behind the ear (as in the diagram). |
| 95 | + |
| 96 | +3. For **Horizontal EOG**, attach the wires to the electrodes, then attach the electrodes to skin (refer diagram below): |
| 97 | + |
| 98 | + |
| 99 | + - ``IN+`` (positive): Place on the right temple, just outside the right eyebrow. |
| 100 | + - ``IN–`` (negative): Place on the left temple, just outside the left eyebrow. |
| 101 | + - ``REF`` (reference): Attach on the bony area near the cheek or behind the ear (as in the diagram). |
| 102 | + |
| 103 | +.. figure:: ../../../guides/usage-guides/skin-preparation/media/skin-prep-eog.png |
| 104 | + |
| 105 | + :align: center |
| 106 | + :alt: EOG Placement |
| 107 | + |
| 108 | + EOG Placement |
| 109 | + |
| 110 | +.. _How to upload the Code to Arduino: |
| 111 | + |
| 112 | +**Step 5: How to upload the Code to Arduino** |
| 113 | + |
| 114 | +1. Open the folder you downloaded: **Eye-BioAmp-Arduino-Firmware** |
| 115 | +2. Inside that, you’ll find several subfolders. |
| 116 | +3. Pick the folder for the experiment you want to try. (For beginners: start with the first one and move step-by-step through the others for a better learning experience ) |
| 117 | +4. Inside that folder, open the **.ino** file using **Arduino IDE** |
| 118 | + |
| 119 | +- For example: |
| 120 | + |
| 121 | + - To try raw signal: open ``01_FixedSampling.ino`` |
| 122 | + - To try filtered signal: open ``02_EOGFilter.ino`` |
| 123 | + |
| 124 | +.. note:: |
| 125 | + You'll find all the experiments listed below, each with :ref:`step-by-step instructions<experiments step by step>`. Just scroll to the one you're working on to get started with the right setup. |
| 126 | + |
| 127 | +5. Connect Your Arduino |
| 128 | + |
| 129 | + - Plug your Arduino board into your computer’s USB port using the USB cable. |
| 130 | + - Wait for the operating system to install any required USB drivers. |
| 131 | + |
| 132 | +6. In Arduino IDE: |
| 133 | + |
| 134 | + - Go to **Tools > Board > Arduino UNO** choose the model of your board (e.g., “Arduino Uno” or “Arduino Nano” if you wired to a Nano) |
| 135 | + - Go to **Tools > Port > [select the correct COM port]** |
| 136 | + |
| 137 | +7. Verify (Compile) the Sketch |
| 138 | + |
| 139 | + - Click the **“✔️ Verify”** button (or press ``Ctrl + R``). |
| 140 | + - Wait for **“Done compiling.”** If errors appear, double-check you opened the correct .ino file. |
| 141 | + |
| 142 | +8. Click the **✓** Upload (or press ``Ctrl + U``) button to send the code to your Arduino. |
| 143 | + |
| 144 | + - The IDE will compile again and then send the code to your board. |
| 145 | + - The onboard LED labeled **“L”** may blink during upload. When you see **“Done uploading”**, the new firmware is running. |
| 146 | + |
| 147 | + |
| 148 | +9. Open Serial Monitor and Serial Plotter (Optional) |
| 149 | + |
| 150 | + - For serial monitor and plotter, we recommend using `Chords Web <https://chords.upsidedownlabs.tech>`_. However, if you're learning to develop, you might also find these options useful. |
| 151 | + |
| 152 | + - For Serial Monitor: In the IDE, click **Tools → Serial Monitor** (or press ``Ctrl + Shift + M``). |
| 153 | + - Ensure the baud rate at the bottom right of the Serial Monitor is set to ``115200`` (or whatever the sketch’s Serial.begin(115200); line specifies). |
| 154 | + - You should start seeing lines of numbers. Those are your readings. |
| 155 | + |
| 156 | + |
| 157 | + - For Serial Plotter: In the IDE, click **Tools → Serial Plotter**. |
| 158 | + - You should start seeing plotting of graph and visualize the waves. |
| 159 | + |
| 160 | +.. important:: |
| 161 | + |
| 162 | + - Remember to close the **Serial Monitor & Serial Plotter** in **Arduino IDE** before starting the Chords Visualizer. |
| 163 | + |
| 164 | +.. _Visualize Your Eye Signals!: |
| 165 | + |
| 166 | +**Step 6: Visualize Your Eye Signals!** |
| 167 | + |
| 168 | +1. Open this website: `Chords Web <https://chords.upsidedownlabs.tech>`_ |
| 169 | +2. Click: Visualize Now → then choose Serial Wizard. |
| 170 | +3. Select the correct COM port (same one from Arduino IDE). |
| 171 | +4. Click Connect. |
| 172 | + |
| 173 | +.. important:: |
| 174 | + |
| 175 | + - Always **disconnect your laptop charger** while testing. Why? Charging can introduce 50 Hz noise that affects the signal. |
| 176 | + |
| 177 | + |
| 178 | +🎉 Now blink your eyes or look side to side — you’ll see real-time EOG waves on the screen! |
| 179 | + |
| 180 | +.. _experiments step by step: |
| 181 | + |
| 182 | +Let's explore all the experiments step by step |
| 183 | +=============================================== |
| 184 | +.. Experiment 1 |
| 185 | +
|
| 186 | +.. dropdown:: 1. Fixed Sampling |
| 187 | + :open: |
| 188 | + |
| 189 | + **1. Program Purpose & Overview** |
| 190 | + |
| 191 | + The **Fixed Sampling** program reads the raw electrical signal from the eyes (Electrooculography or EOG) |
| 192 | + using an analog pin and prints it to the Serial Monitor. It's useful for understanding |
| 193 | + what the unfiltered eye signal looks like. Think of it like looking at the "raw ingredients" before cooking. |
| 194 | + |
| 195 | + **2. How It Works** |
| 196 | + |
| 197 | + - ``analogRead(A0)`` reads voltage from the Eye BioAmp sensor. |
| 198 | + - ``Serial.println()`` prints those values to the computer. |
| 199 | + - A timer ensures values are read at a steady rate (e.g., 500 times per second or 500 Hz). |
| 200 | + |
| 201 | + You can see how blinking or moving eyes changes the waveform. |
| 202 | + |
| 203 | + **3. Perform the Hardware** |
| 204 | + |
| 205 | + - Refer to wiring as per instructions given in :ref:`Connect Your Hardware<Connect Your Hardware>` |
| 206 | + |
| 207 | + **4. Firmware Upload** |
| 208 | + |
| 209 | + - For this project, navigate to the repository folder (Eye-BioAmp-Arduino-Firmware/1_FixedSampling) and select ``1_FixedSampling.ino``. |
| 210 | + - To upload firmware, refer to :ref:`How to upload the Code to Arduino<How to upload the Code to Arduino>` |
| 211 | + |
| 212 | + **5. Visualize your signal** |
| 213 | + |
| 214 | + - Follow the steps given in :ref:`Visualize Your Eye Signals!<Visualize Your Eye Signals!>` |
| 215 | + |
| 216 | + **6. Running & Observing Results** |
| 217 | + |
| 218 | + - A stream of numbers. |
| 219 | + - Looking up/down → sudden voltage change. |
| 220 | + - Blinks → sharp spikes. |
| 221 | + |
| 222 | + Checkout Demo Visualization on **YouTube**: |
| 223 | + |
| 224 | + .. youtube:: Txo7DjUr5Tk |
| 225 | + |
| 226 | + .. note:: |
| 227 | + To learn more about this project, visit our Instructables page: `Visualizing Electrical Impulses of Eyes (EOG) Using BioAmp EXG Pill <https://www.instructables.com/Visualizing-Electrical-Impulses-of-Eyes-EOG-Using-/>`_ |
| 228 | + .. Experiment 2 |
| 229 | +
|
| 230 | +.. dropdown:: 2. EOG Filter |
| 231 | + |
| 232 | + **1. Program Purpose & Overview** |
| 233 | + |
| 234 | + The **EOG Filter** program cleans the raw signal by removing slow drift (DC offset) and high-frequency noise. |
| 235 | + It gives a more accurate view of intentional eye movements. |
| 236 | + |
| 237 | + **2. How It Works** |
| 238 | + |
| 239 | + - Uses a bandpass IIR filter (0.5 Hz to 19.5 Hz). |
| 240 | + - Stores several recent samples in an array (circular buffer). |
| 241 | + - For each new reading, calculates a weighted average using filter coefficients. |
| 242 | + - Prints filtered values to Serial Monitor. |
| 243 | + - To learn more about filters and how to generate new filters, visit: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.butter.html |
| 244 | + |
| 245 | + **3. Perform the Hardware** |
| 246 | + |
| 247 | + - Refer to wiring as per instructions given in :ref:`Connect Your Hardware<Connect Your Hardware>` |
| 248 | + |
| 249 | + **4. Firmware Upload** |
| 250 | + |
| 251 | + - For this project, go to the repository folder (Eye-BioAmp-Arduino-Firmware/2_EOGFilter) and select ``2_EOGFilter.ino``. |
| 252 | + - To upload firmware, refer to :ref:`How to upload the Code to Arduino<How to upload the Code to Arduino>` |
| 253 | + |
| 254 | + **5. Visualize your signal** |
| 255 | + |
| 256 | + - Follow the steps given in :ref:`Visualize Your Eye Signals!<Visualize Your Eye Signals!>` |
| 257 | + |
| 258 | + **6. Running & Observing Results** |
| 259 | + |
| 260 | + - A smoother, more stable signal. |
| 261 | + - Eye blinks and movement are easier to detect visually. |
| 262 | +.. Experiment 3 |
| 263 | +
|
| 264 | +.. dropdown:: 3. Drowsiness Detection |
| 265 | + |
| 266 | + The **Drowsiness Detection** sketch helps detect drowsiness or sleepiness by measuring blink intervals. |
| 267 | + If someone doesn’t blink for a long time or their eye remains closed, the system can |
| 268 | + raise an alert (e.g., buzz). |
| 269 | + |
| 270 | + - It continuously reads EOG signal. |
| 271 | + - Calculates the signal envelope (peak activity). |
| 272 | + - If envelope is above a blink threshold, it counts as a blink. |
| 273 | + - Measures time between blinks. |
| 274 | + - If time exceeds a set limit → triggers buzzer. |
| 275 | + |
| 276 | + For a detailed walkthrough, follow along with the **YouTube** tutorial for this project: |
| 277 | + |
| 278 | + .. youtube:: h4F41mp4mWk |
| 279 | + |
| 280 | + .. note:: |
| 281 | + To learn more about this project, visit our Instructables page: `Drowsiness Detector by Detecting EOG Signals Using BioAmp EXG Pill <https://www.instructables.com/Drowsiness-Detector-by-Detecting-EOG-Signals-Using/>`_ |
| 282 | +.. Experiment 4 |
| 283 | +
|
| 284 | +.. dropdown:: 4. EOG Photo Capture BLE |
| 285 | + |
| 286 | + To be documented. |
| 287 | + |
| 288 | +.. dropdown:: 5. Eye Blink Detection |
| 289 | + |
| 290 | + The **Eye Blink Detection** program detects individual eye blinks in real-time and activates an output, like a buzzer or LED. Great for making |
| 291 | + blink-based interfaces! |
| 292 | + |
| 293 | + Continuously samples the filtered EOG waveform and applies a dynamic threshold + hysteresis to catch |
| 294 | + the rapid voltage swings caused by an eyelid closing. Whenever the signal crosses the blink threshold, |
| 295 | + the firmware immediately flags a “blink event” and drives a configurable digital output (LED, buzzer, relay |
| 296 | + or serial message). |
| 297 | + |
| 298 | + Because it operates in real‑time on the microcontroller, you get sub‑50 ms latency from |
| 299 | + physical blink to output trigger—perfect for responsive, blink‑based user interfaces or assistive‑tech |
| 300 | + prototypes. |
| 301 | + |
| 302 | + For a detailed walkthrough, follow along with the **YouTube** tutorial for this project: |
| 303 | + |
| 304 | + .. youtube:: PfEJVa3gv6E |
| 305 | + |
| 306 | + .. note:: |
| 307 | + To learn more about this project, visit our Instructables page: `Eye Blink Detection by Recording EOG Using BioAmp EXG Pill <https://www.instructables.com/Eye-Blink-Detection-by-Recording-EOG-Using-BioAmp-/>`_ |
| 308 | + |
| 309 | +.. dropdown:: 6. EOG DinoGame |
| 310 | + |
| 311 | + The **EOG DinoGame** program controls Chrome Dino Game with your eye blinks! |
| 312 | + |
| 313 | + Transforms your blinks into game inputs for Chrome’s offline “Dino Run.” |
| 314 | + The Arduino runs the same blink‑detection algorithm as above, but instead of an onboard |
| 315 | + LED it sends a simple code over USB serial for each blink. |
| 316 | + |
| 317 | + A companion script on your PC listens on the COM port and synthesizes a space‑bar keypress |
| 318 | + whenever a blink event arrives—letting you jump over cacti and dodge pterodactyls using only your eyes. |
| 319 | + It’s a fun demo of how EOG can drive full applications with no hands at all. |
| 320 | + |
| 321 | + Uses serial communication or USB HID to simulate a jump action when you blink. |
| 322 | + |
| 323 | + .. note:: |
| 324 | + |
| 325 | + To learn about this project, visit our Instructables page for detailed guide: `Control Dino Game Using Eye Blinks (EOG) <https://www.instructables.com/Control-Dino-Game-Using-Eye-Blinks-EOG/>`_ |
| 326 | + |
| 327 | + Checkout our **YouTube** video, to know how it looks : |
| 328 | + |
| 329 | + .. youtube:: Sw46RTjeLs4 |
| 330 | + |
| 331 | +.. dropdown:: 7. EOG Servo Control |
| 332 | + |
| 333 | + |
| 334 | + The **EOG Servo Control** sketch maps eye blinks to physical motion—e.g., controlling a servo claw with eye input. |
| 335 | + |
| 336 | + Maps individual blinks (or blink patterns) to precise servo motions for mechanical actuation. |
| 337 | + Blink events are detected exactly as in the Eye Blink Detection sketch, but here each blink pulses a |
| 338 | + hobby‑servo control signal (via Arduino’s Servo library) to move to a predefined angle. |
| 339 | + |
| 340 | + You can configure single‑blink/double‑blink sequences to open and close a gripper, nod a toy head, |
| 341 | + or point an indicator—showcasing simple, hands‑free robotics driven entirely by your eye movements. |
| 342 | + |
| 343 | + .. note:: |
| 344 | + To learn about this project, visit our Instructables page for detailed guide: `Control a Servo Claw Using Your Eye Blinks (EOG) <https://www.instructables.com/Control-a-Servo-Claw-Using-Your-Eye-Blinks-EOG/>`_ |
| 345 | + |
| 346 | +.. dropdown:: 8. Vertical Eye Movement Detector |
| 347 | + |
| 348 | + The **Vertical Eye Movement Detector** firmware detects **upward and downward eye movements** using EOG signals captured by the **Eye-BioAmp sensor**. |
| 349 | + It is useful for applications where vertical eye gestures are mapped to specific control functions, such as assistive device interaction or simple user interfaces. |
| 350 | + |
| 351 | + For a detailed walkthrough, follow along with the **YouTube** tutorial for this project: |
| 352 | + |
| 353 | + .. youtube:: Zt7YWTnSAY0 |
| 354 | + |
| 355 | + .. note:: |
| 356 | + |
| 357 | + To learn about this project, visit our Instructables page for detailed guide: `Detecting UP and DOWN Movements of Eyes Using EOG <https://www.instructables.com/Tracking-UP-and-DOWN-Movements-of-Eyes-Using-EOG/>`_ |
| 358 | + |
| 359 | +✅ **And That’s it!, Congrats on making your neuroscience project using BioAmp Hardware.** |
0 commit comments