Shop OBEX P1 Docs P2 Docs Learn Events
Gesture Sensor Help — Parallax Forums

Gesture Sensor Help

NWCCTVNWCCTV Posts: 3,629
edited 2014-06-30 21:04 in General Discussion
In the attached code everything works fine but I have a bit of an issue. At the end of the code I input an IF statement to flash an LED on Pin 13 when sampleCount > 100. The problem is that sampleCount seems to increment automatically. So, I need to figure out what command to use for the ALS VIS, ALS IR, PS1, PS2 and PS3 values since they see the ones to increase and decrease as my hand moves in front of the device. Thanks.
{{
File:    Si1143_Sensor_Demo.spin
Version: 1.0
Date:    March 14, 2012

Author:  Kevin McCullough
Company: Gecko Engineering
         "Turning good ideas into great products." 
Phone:   541.660.2314
Email:   [EMAIL="Kevin@GeckoEngineering.com"]Kevin@GeckoEngineering.com[/EMAIL]
Web:     [URL="http://www.GeckoEngineering.com"]www.GeckoEngineering.com[/URL]
Revision History:
v1.0 - 3/14/2012
  Initial release.         
Description:
This object demonstrates the use of the Si1143.spin driver for the "Si1143 Proximity
Sensor" (Parallax PN: 28046).  In this simple demo, the application runs in a loop
and manually polls the driver for new measurements, then prints the values out to
the serial terminal.
Connection Diagram:
                                   
               VIN = 3.3V                  
    ┌──────┐   ┬   ┬   ┬      ┬ ┌────────────────┐
    │      │   │   │   │      │ │•   [‣]        •│        
    │      │   R  R  R   ┌─┼─┤GND             │
    │      │   │   │   │     └─┤VIN   ┌─────────┘                        
    │    P2├───┻───┼───┼────────┤INT   │
    │    P1├───────┻───┼────────┤SCL   │        
    │    P0├───────────┻────────┤SDA   │
    │      │                    │•     │
    └──────┘                    └──────┘
    Propeller MCU               Si1143 Proximity
    (P8X32A)                     Sensor (28046)
                                  
    R = 4.7kΩ
                
}}
CON
  _clkmode = xtal1 + pll16x
  _clkfreq = 80_000_000
  'Pins used to connect to the "Si1143 Proximity Sensor" module
  SDA_PIN = 0
  SCL_PIN = 1
  INT_PIN = 2
  CURSOR_X = 10     'This value sets the left alignment for printing all the values
  
OBJ
  sensor    : "Si1143"
  debug     : "FullDuplexSerial"
  pin       : "Input Output Pins" 
  time      : "Timing"
VAR
  long  samples[5]
  long  sampleCount
PUB RunDemo | index
  'Start the serial terminal to display debug text
  debug.Start(31, 30, 0, 115200)
  
  'Start the Si1143 device driver
  sensor.Start(SDA_PIN, SCL_PIN, INT_PIN)
  'Store the baseline average offset values (accomodates for optical leakage
  'between the LEDs and the sensor).
  sensor.PsBaselineSet          'NOTE: THIS LINE CAN BE COMMENTED OUT TO GET
                                'THE RAW VALUES FOR PS1, PS2, & PS3
  'Print startup text to the terminal
  debug.tx(0)                   
  debug.str(string("=================="))
  debug.tx(13)
  debug.str(string("Si1143 Sensor Demo"))
  debug.tx(13)
  debug.str(string("=================="))
  debug.tx(13)
  debug.str(string("Sample# = "))
  debug.tx(13)
  debug.str(string("ALS VIS = "))
  debug.tx(13)
  debug.str(string("ALS IR  = "))
  debug.tx(13)
  debug.str(string("PS1:    = "))
  debug.tx(13)
  debug.str(string("PS2:    = "))
  debug.tx(13)
  debug.str(string("PS3:    = "))
    
  'Stay in this loop and take measurements forever 
  repeat 
    'Get a new set of samples
    sampleCount := sensor.SampleOnce(@samples)
    'Display the sample count value
    debug.tx(2)                 'Position cursor (x,y)
    debug.tx(CURSOR_X)          'X
    debug.tx(3)                 'Y
    debug.dec(sampleCount)      'Display value
    debug.str(string("        "))
    
    'Display all the sample values returned in the array
    repeat index from 0 to 4   
      debug.tx(2)                 'Position cursor (x,y)
      debug.tx(CURSOR_X)          'X
      debug.tx(index + 4)         'Y
      debug.dec(samples[index])   'Display value
      debug.str(string("        "))
      if sampleCount > 100
        pin.High(13)
        time.Pause(200)
        pin.Low(13)
        time.Pause(200)
  

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-06-29 16:39
    Add the following to the CON section so you can have name associated with an index number.
    #0, ALS_VIS, ALS_IR, PS1, PS2, PS3
    

    This is a shortcut to this (don't enter the code below into the program):
      ALS_VIS = 0
      ALS_IR = 1
      'ect.
    

    Now that you have name for the index numbers you can use:
    if samples[ALS_VIS] > 100 ' or use other index name for the other values
            pin.High(13)
            time.Pause(200)
            pin.Low(13)
            time.Pause(200)
    
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-06-29 17:08
    I thank you sir. Will give it a go.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-06-29 17:14
    Perfect. That now works as expected. It seems as though P1, P2 and P3 are the functions to use since the other 3 are constantly incrementing up. No big deal as this is exactly what I was looking to do. Thanks Duane, you came through as always.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-06-29 20:12
    So, I want to create a box/container of some sort to place the sensor in. After reading the pdf file on it I believe that I can enclose the entire device with the exception of having to leave the LED;s uncovered. Is this a correct assumption? http://www.parallax.com/sites/default/files/downloads/28046-Si1143-Gesture-Sensor-v1.2.pdf
  • PublisonPublison Posts: 12,366
    edited 2014-06-30 03:18
    NWCCTV wrote: »
    So, I want to create a box/container of some sort to place the sensor in. After reading the pdf file on it I believe that I can enclose the entire device with the exception of having to leave the LED;s uncovered. Is this a correct assumption? http://www.parallax.com/sites/default/files/downloads/28046-Si1143-Gesture-Sensor-v1.2.pdf

    You would also need the detector chip, (Si1143), uncovered. It's the chip above LED1 with the transparent window.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-06-30 13:32
    You would also need the detector chip
    Got it. So can any of them be covered with clear acrylic or must they be left uncovered! I need to do a bit of experimenting to see how thick of an enclosure I can use without interfering with the functionality of the sensor.
  • PublisonPublison Posts: 12,366
    edited 2014-06-30 14:02
    Come on Andy. Doesn't anyone read the product descriptions anymore? :)

    http://www.parallax.com/sites/default/files/downloads/28046-Si1143-Gesture-Sensor-v1.2.pdf
    Furthermore, the sensor may be used behind glass or in a windowed project enclosure to avoid contact with harsh environments or hazardous chemicals.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-06-30 14:10
    I missed that part!!! I did read, which is why I asked the first question!!!!!
  • PublisonPublison Posts: 12,366
    edited 2014-06-30 15:52
    NWCCTV wrote: »
    I missed that part!!! I did read, which is why I asked the first question!!!!!

    Just kidding. :)
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-06-30 21:04
    Yea, I know. That is why I use exclamations!!!! I usually forget about the smiley face
Sign In or Register to comment.