Shop OBEX P1 Docs P2 Docs Learn Events
2pe MOBO with tsl1401 line scan cammera — Parallax Forums

2pe MOBO with tsl1401 line scan cammera

Hello,

I am new to the Basic stamp so any help is appreciated. I have a 2pe MOBO and a TSL1401 line scan camera. I would like to capture the grayscale data on the PC's serial port. I have the "tsl1401_template.bpe" program running with this code running in program section.

' Your program code goes here.

pixno VAR Byte
char VAR Byte(16)
DO
GOSUB Ready
OWOUT owio, 0, [ACQGRAY]
GOSUB Ready
FOR pixno = 0 TO 7
OWIN owio, 8, [STR char\16]
SEROUT 16, 6, [STR char\16]
NEXT
LOOP
END

When I go to the terminal program the data looks unusable. I have the baud set to 38400. What else do I need to do ?

Thanks
Dan H.

Comments

  • Try this:
    ' =========================================================================
    '
    '   File...... tsl1401_dump_gray.bpe
    '   Purpose... Dump pixel values from the TSL1401-DB using the MoBoStamp-pe.
    '   Author.... Phil Pilgrim
    '   E-mail.... propeller@phipi.com
    '   Started... 22 Dec 2010
    '   Updated...
    '
    '   {$STAMP BS2pe}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    
    
    ' -----[ Program Description ]---------------------------------------------
    
    ' This program dumps analog pixel values from the TSL1401-DB via the
    ' TSL1401.hex firmware for the MoBo's AVR coprocessor.
    
    ' -----[ I/O Definitions ]-------------------------------------------------
    
    owio            PIN     6     'Pin for OWIN and OWOUT to AVR coprocessor.
    
    ' -----[ Constants ]-------------------------------------------------------
    
    ' Commands
    
    SETLED          CON     $EB   'Set LED strobe and brightness/time from next byte.
    
      'Flag to OR to brightness/time (0 - 127) value.
    
      TIME          CON     $80   'Set strobe: value (0 - 127) is 0 - 3.4mS at 100% on.
      INTEN         CON     $00   'Set intensity: value (0 - 127) is 0 - 49.6% on.
    
    SETBIN          CON     $EC   'Set threshold, hysteresis, and filter (3 bytes).
    
      'Filter flags.
    
      FLOAT         CON     $80   'Threshold is floating per filter value (0 - 7).
      FIXED         CON     $00   'Threshold is fixed.
      WINDOW        CON     $40   'Threshold is a window (outside of hysteresis band).
      LEVEL         CON     $00   'Threshold is a level with hysteresis.
    
    SETEXP          CON     $EE   'Set exposure to byte (1 - 255) following: 0.27 - 68mS.
    
    ACQGRAY         CON     $A0   'Acquire and dump a grayscale image.
    ACQBIN          CON     $A4   'Acquire a binary image.
    ACQAND          CON     $A1   'Acquire binary image ANDed w/ previous.
    ACQOR           CON     $A2   'Acquire binary image ORed w/ previous.
    ACQXOR          CON     $A3   'Acquire binary image XORed w/ previous.
    ACQANDNOT       CON     $A5   'Acquire binary image ANDed w/ NOT prev.
    ACQORNOT        CON     $A6   'Acquire binary image ORed w/ NOT prev.
    ACQXORNOT       CON     $A7   'Acquire binary image XORed w/ NOT prev.
    
    ACQDIFF         CON     $A3   'Idiom for ACQXOR.
    ACQSAME         CON     $A7   'Idiom for ACQXORNOT.
    
      XTRIG         CON     $08   'External trigger flag, ORed to ACQ commands.
    
    CNTNEW          CON     $C8   'Count pixels/edges between new bounds.
    CNTNXT          CON     $C0   'Count pixels/edges between current bounds.
    FNDNEW          CON     $F8   'Find first pixel/edge between new bounds.
    FNDNXT          CON     $F0   'Find first pixel/edge between current bounds.
    
      'Modifiers, ORed to CNTNEW, CNTNXT, FNDNEW, and FNDNXT.
    
      NXT           CON     $00   'Continue from where last CNT or FND left off.
      BKWD          CON     $04   'Search backward.
      FWD           CON     $00   'Search forward.
      DRKPIX        CON     $00   'Target is a dark pixel.
      BRTPIX        CON     $02   'Target is a bright pixel.
      DRKEDG        CON     $03   'Target is a bright-to-dark edge.
      BRTEDG        CON     $01   'Target is a dark-to-bright edge.
    
    DUMPADR         CON     $DA   'Dump data, beginning at addr, and until reset.
    
      'Address constants for single byte arg following DUMPADR.
    
      PIXELS        CON     $00   'Beginning of binary pixel buffer (32 bytes).
      RESULTS       CON     $20   'Beginning of results buffer.
      MINPIX        CON     $20   'Value of darkest pixel (0 - 255).
      MINLOC        CON     $21   'Location of darkest pixel (0 - 127).
      MAXPIX        CON     $22   'Value of brightest pixel (0 - 255).
      MAXLOC        CON     $23   'Location of brightest pixel (0 - 127).
      AVGPIX        CON     $24   'Average pixel value (0 - 255).
    
    DUMPID          CON     $DD   'Dump the firmware ID (returns 3 bytes).
    
    DUMPFLAGS       CON     $DF   'Dump error flags (returns 1 byte).
    
      'Bit positions in returned byte.
    
      BADCMD        CON     $80   'Unrecognized command.
      CANTBUF       CON     $40   'Attempt to buffer unbufferable command.
      CMDOVF        CON     $20   'Command buffer overflow.
      DATOVF        CON     $10   'Result data buffer overflow.
    
    ' -----[ Variables ]-------------------------------------------------------
    
    flags           VAR     Byte
    busy            VAR     Bit
    
    ' -----[ Initialization ]--------------------------------------------------
    
    PAUSE 10                      'Wait for AVR to finish reset.
    
    ' -----[ Program Code ]----------------------------------------------------
    
    EXPTIME        CON       60
    i              VAR       Byte
    j              VAR       Byte
    char           VAR       Byte(16)
    
    DO
      OWOUT owio, 1, [SETEXP, EXPTIME, ACQGRAY]
      GOSUB Ready
      FOR i = 0 TO 7
        OWIN owio, 8, [STR char\16]
        FOR j = 0 TO 15
          PUT i << 4 + j, char(j)
        NEXT
      NEXT
      FOR i = 0 TO 127
        GET i, char
        IF (i = 127) THEN
          DEBUG DEC char(15), 13, 13
        ELSE
          DEBUG DEC char, ","
        ENDIF
      NEXT
    LOOP
    END
    
    ' -----[ Subroutines ]-----------------------------------------------------
    
    ' -----[ Ready ]-----------------------------------------------------------
    ' Wait for the driver to become not busy.
    
    Ready:
      DO
        OWIN owio, 4, [busy]     'Read busy bit.
      LOOP WHILE busy            'Keep checking until it goes low.
      RETURN
    
    ' -----[ GetError ]--------------------------------------------------------
    ' Read the error flags from the driver.
    
    GetError:
      OWOUT owio, 0, [DUMPFLAGS]   'Read the error flags.
      OWIN owio, 0, [flags]
      IF (flags = $FF) THEN        'If $FF, driver is waiting for a reset.
        OWOUT owio, 1, [DUMPFLAGS] 'So reset and try again.
        OWIN owio, 0, [flags]
      ENDIF
      RETURN
    

    -Phil
  • Wow, Thanks PhiPi for the quick response! This code works great. So here is another question. It has to do with post processing data at the PC or doing calculations directly on the stamp. I want to get a weighted average to find the center of the waveform.

    Sum(pixel location * pixel intensity)/sum(pixel intensity)

    I can do this easily on the PC after the data is parsed and placed in arrays, but I see you have lots of functions built in to the firmware to work with the binary data. Is this calculation easy to do with your builtin functions and do you think it would be faster than doing it on the PC.

    Thanks again for your fast response!

    Dan H.
  • The centroid computation is not supported in the AVR firmware. And it would be a little tricky to do in PBASIC, since your Sum(pixel location * pixel intensity) won't fit in a word variable. So I think your best option is still to do the computation in the host computer.

    -Phil
Sign In or Register to comment.