Shop OBEX P1 Docs P2 Docs Learn Events
Spin Code for Flexiforce Sensor — Parallax Forums

Spin Code for Flexiforce Sensor

NWCCTVNWCCTV Posts: 3,629
edited 2014-11-15 18:45 in Accessories
Does anyone know if there is Spin or SimpleIDE C code for the Parallax Flexiforce Sensor?

Comments

  • JonnyMacJonnyMac Posts: 9,163
    edited 2014-11-15 10:03
    This should do the trick -- I use this for reading a similar RC circuit in a commercial product. You will probably want to filter the result.
    pub read_pot(p)
    
    '' Reads RC circuit on pin p
    
      ctra := (%01000 << 26) | p                                    ' ctra in pos detect mode 
      frqa := 1
    
      outa[p] := 1                                                  ' charge cap
      dira[p] := 1
      waitcnt(cnt + (clkfreq / 500))                                ' wait 2ms
    
      phsa := 0                                                     ' clear counter
      dira[p] := 0                                                  ' allow discharge
      repeat
      while (ina[p])
      ctra := 0                                                     ' disable ctra
      
      return phsa
    
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-11-15 18:45
    My version specifically tested with the Flexiforce. It is essentially the same as Jon's in function but uses the RCTime liberry.
    OBJ
    
    
      pst        : "FullDuplexSerial"  
      rc         : "RCTime"
    
    
    CON
       
      _clkmode = xtal1 + pll16x 
      _xinfreq = 5_000_000
             
    PUB Go | Sense 
    
    
      pst.start(31, 30, 0, 115200)
    
    
      repeat
        rc.rctime(0, 1, @Sense)           ' Flexiforce to pin 0, read rc
        pst.Str(String("Value: "))
        pst.dec(Sense / 100)              ' Display rc time decay in Sense var
        pst.tx(13)
        waitcnt(clkfreq / 2 + cnt)        ' 1/2 second delay
    

    Do you have a Propeller board with an ADC input? If so, you can use the Flexiforce as you would any variable resistor for ADC. For PropC, you could use any of the examples Andy has done that use the ADC inputs of the PAB or PropBOE. Go through the Learn examples -- the latest are on learn.parallax.com.
Sign In or Register to comment.