-
Notifications
You must be signed in to change notification settings - Fork 1
Home
This project is my latest attempt to create a wearable mask which can alert me when I'm dreaming and encourage lucid dreams. Unfortunately, I've been struggling with insomnia over the last few years, so this project is in an "almost but not quite" state. Recent changes seem to be getting it under control, and I hope to be able to pick up this project again some time soon.
See my album on Imgur.
You may be asking "Why the weird 2-board design? Why all that elastic?" Ironically, over the course of my multiple builds, the hardest part wasn't getting the electronics working; rather, it was getting the mask to stay in place on my face during the night! With a more traditional design, I wouldn't get much good data before the mask slipped up onto my forehead or onto the side of my face. I decided on the size of the "nose board" by finding how big I could make it without bumping it while laying on my side; then I stuffed whatever I could on it and dumped the rest on the second "forehead board." The multiple loops of elastic (with elastic on the ends) do a pretty good job of holding everything in place all night long.
I have no doubts that someone can come up with a better design than this, but at least it works.
To build this project, you'll need the following:
- An AVR programmer (I use the ISP500, but I assume the newer, cheaper ones would work fine)
- An FTDI USB-Serial interface
- The ability to cut, etch, and drill circuit boards (laser printer masks are sufficient)
- The ability to do simple surface-mount soldering (SOICs and 0804s)
- The ability to sew a fabric mask to hold everything in place
- Eagle
- avrdude
These are all the components which go into the mask itself. I've listed Digikey part numbers for almost everything. Some of the parts have been obsoleted, but I assume that replacement parts are functionally identical.
- 1x DIP ATMega328 (ATMEGA328P-AU)
- 1x SOIC 8mbit flash chip (W25Q80BVSSIG-ND)
- 1x 0805 PTC (507-1518-1-ND)
- 2x PTH IR sensors (751-1034-5-ND)
- 1x SMD red led (475-1278-1-ND)
- 2x PTH red LEDs (Radio Shack)
- 1x 0805 10uH inductor
- 2x 0805 100nF capacitors
- 1x 32.768k crystal (possibly 300-8761-ND, not sure)
- 2x 47 Ohm 0805 resistors (RMCF0805JT47R0CT-ND)
- 3x 220 Ohm 0805 resistors (RMCF0805JT220RCT-ND)
- 2x 10k Ohm 0805 resistors (RMCF0805JT10K0CT-ND)
- 2x 24k Ohm 0805 resistors (1276-5561-1-ND)
- 1x SMD battery holder (BA2032SM-ND)
- 1x 2x14 dip holder (optional) (3M5480-ND)
- 2x pushbuttons (450-1140-ND)
- 1x right-angle female connector (S5444-ND)
- wire
- spare protoboard
- .1" pins (I needed 8x, 6x, 3x, 3x, but yours might vary depending on your FTDI adapter and programmer)
- wire
- Etch both circuit boards using the Eagle files (NB: I made these for home etching, so they have large tolerances and don't have the extra layers for professional fabbers to do solder masks and drilling)
- Using the Eagle files as a guide, solder on all the components
- Using the air wires as a guide, connect the two boards together
- Create a communications adapter to map the pins from the AVR programmer and the FTDI adapter onto the pins on the board (this will vary depending on FTDI and programmer; look at the picture to see what I'm talking about)
- Run "make fuses" (this only has to be done once per AVR chip)
- Run "make program" to build and upload the program
- Make a fabric mask (TODO: upload pictures of what I made)
To turn the mask on, insert the battery. Once you're in bed, press a button to turn on recording and REM detection logic. After a delay (TODO what is it?), the "dream alarm" will be enabled and will flash the LEDs (the morse code for "DREAM") when REM sleep is detected. In the morning, download the eye movement data for further analysis (or just clear it).
With the FTDI adapter attached and the battery in, run a standard serial emulator (e.g. minicom). Connect with 230400 / ? / ? / ? with no handshake. The following commands are available:
- SCAN - see how much of the flash memory is in use
- ERASE - erase the flash memory
- VOLT - perform a crude battery test
- MORSE - blink with Morse code
- ADC - turn on the sensors
- ADCVERB - start printing what the sensors "see"
- SUM - print a checksum of the current flash memory (may or may not work?) You can also initiate an XMODEM download to download the flash contents (no command required; just start an XMODEM download).
IR readings are 10-bit numbers. 8 times each second, each sensor is polled and the data is recorded to flash along with other data about what the mask is doing. The data is downloaded as a binary blob. Each 256-byte "packet" has an 8-byte header followed by readings and other data. bytes 0-7: FF EE 0 byte 8,12,etc: <2 high bits from left reading> <left sensor shows dreaming?> <right sensor shows dreaming?> <is the left button pressed?> <is the right button pressed?> <is morse sending?> byte 9, 13, etc: 8 low bits from left reading byte 10, 14, etc: Same as 8, for right byte 11, 15, etc: Same as 9, for right
I use the scripts in the "data" folder to interpret the data. "parse_raw.pl" reads in the binary blob and dumps out a text file containing the data in a format which gnuplot can use, while plot.sh calls gnuplot with the appropriate actions.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.