How stable would this be as a no hardware distance sensor?
Jorge P
Posts: 385
I was writing and testing some code for a project I have in Customer Projects, when I noticed that each time I placed my hand within 1.5 to 2 inches it would be detected by a hanging wire connected to a propeller pin. I have I2C code running on the pin next to it so I am curious if it is creating capacitance...
Here is the code I was working on
I have never noticed this with the Propeller before.
Can an anomaly like this be relied upon to work all the time?
Here is a video showing it:
Here is the code I was working on
{{ HC-SR04 Trigger Driver 8x HC-SR04 are used All Trig pins are connected to the MCP23017 on seperate lines All echo pins are tied together and connected to the Propeller Only one HC-SR04 is read at a time clockwise from Left of the robot device License: MIT Copyright (c) 2011-2018 Jorge Joaquin Pareja Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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 }} CON _clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz _xinfreq = 5_000_000 ' Connect up to 16 trigger pins to the MCP23017 ' Connect all echo pins together and connect them to a free Propeller pin and define that pin as ECHO below SDA = 0 ' Prop pin 0 SCL = 1 ' Prop pin 1 ECHO = 2 'Hardware addressable pins 15, 16, and 17 '||| MCPADDR = %0100_000 ' leave off the R/W bit, Address is shifted right to put the bit in by the driver INPUT_BIT = %1 OUTPUT_BIT = %0 ALLOUTPUT = %0000_0000 ALLINPUT = %1111_1111 ALLOFF = %0000_0000 TRIG_0 = %0000_0001 ' Left Center GPA0 TRIG_1 = %0000_0010 ' Left Front GPA1 TRIG_2 = %0000_0100 ' Front Center GPA2 TRIG_3 = %0000_1000 ' Right Front GPA3 TRIG_4 = %0001_0000 ' Right Center GPA4 TRIG_5 = %0010_0000 ' Right Rear GPA5 TRIG_6 = %0100_0000 ' Rear Center GPA6 TRIG_7 = %1000_0000 ' Left Rear GPA7 TRIG_8 = %0000_0001 ' spare TRIG_9 = %0000_0010 ' spare TRIG_10 = %0000_0100 ' spare TRIG_11 = %0000_1000 ' spare TRIG_12 = %0001_0000 ' spare TRIG_13 = %0010_0000 ' spare TRIG_14 = %0100_0000 ' spare TRIG_15 = %1000_0000 ' spare ' MCP CONFIG Registers ICON.BANK = 0 IODIRA = $00 IODIRB = $01 IPOLA = $02 IPOLB = $03 GPINTENA = $04 GPINTENB = $05 DEFVALA = $06 DEFVALB = $07 INTCONA = $08 INTCONB = $09 IOCON = $0A GPPUA = $0C GPPUB = $0D INTFA = $0E INTFB = $0F INTCAPA = $10 INTCAPB = $11 GPIOA = $12 GPIOB = $13 OLATA = $14 OLATB = $15 ' from Timing.spin _10us = 1_000_000 / 10 ' Divisor for 10 us _1ms = 1_000_000 / 1_000 ' Divisor for 1 ms _1s = 1_000_000 / 1_000_000 ' Divisor for 1 s DEBUG = 1 VAR LONG clkcycles ' OBJ mcp : "i2cDriver.spin" pst : "Parallax Serial Terminal.spin" ' only use for debugging or it slows us down PUB MAIN | tmp, pass ' init pst pst.Start(115200) mcp.Init(SCL, SDA) MCP_Config pass := 1 tmp := 0 REPEAT USS_Read(tmp) tmp++ IF tmp == 16 tmp := 0 pst.Clear pst.Str(STRING("Pass: ")) pst.Dec(pass) pst.NewLine pass++ PUB MCP_Config ' set all pins to output MCP_Write(IODIRA, ALLOUTPUT) MCP_Write(IODIRB, ALLOUTPUT) MCP_Write(GPIOA, %0000_0000) MCP_Write(GPIOB, %0000_0000) PUB USS_Read(device) | cnt1, cnt2, Microseconds, Distance CASE device 0: MCP_PinGPB(ALLOFF) MCP_PinGPA(TRIG_0) WaitUsec10 MCP_PinGPA(ALLOFF) 1: MCP_PinGPB(ALLOFF) MCP_PinGPA(TRIG_1) WaitUsec10 MCP_PinGPA(ALLOFF) 2: MCP_PinGPB(ALLOFF) MCP_PinGPA(TRIG_2) WaitUsec10 MCP_PinGPA(ALLOFF) 3: MCP_PinGPB(ALLOFF) MCP_PinGPA(TRIG_3) WaitUsec10 MCP_PinGPA(ALLOFF) 4: MCP_PinGPB(ALLOFF) MCP_PinGPA(TRIG_4) WaitUsec10 MCP_PinGPA(ALLOFF) 5: MCP_PinGPB(ALLOFF) MCP_PinGPA(TRIG_5) WaitUsec10 MCP_PinGPA(ALLOFF) 6: MCP_PinGPB(ALLOFF) MCP_PinGPA(TRIG_6) WaitUsec10 MCP_PinGPA(ALLOFF) 7: MCP_PinGPB(ALLOFF) MCP_PinGPA(TRIG_7) WaitUsec10 MCP_PinGPA(ALLOFF) 8: MCP_PinGPA(ALLOFF) MCP_PinGPB(TRIG_8) WaitUsec10 MCP_PinGPB(ALLOFF) 9: MCP_PinGPA(ALLOFF) MCP_PinGPB(TRIG_9) WaitUsec10 MCP_PinGPB(ALLOFF) 10: MCP_PinGPA(ALLOFF) MCP_PinGPB(TRIG_10) WaitUsec10 MCP_PinGPB(ALLOFF) 11: MCP_PinGPA(ALLOFF) MCP_PinGPB(TRIG_11) WaitUsec10 MCP_PinGPB(ALLOFF) 12: MCP_PinGPA(ALLOFF) MCP_PinGPB(TRIG_12) WaitUsec10 MCP_PinGPB(ALLOFF) 13: MCP_PinGPA(ALLOFF) MCP_PinGPB(TRIG_13) WaitUsec10 MCP_PinGPB(ALLOFF) 14: MCP_PinGPA(ALLOFF) MCP_PinGPB(TRIG_14) WaitUsec10 MCP_PinGPB(ALLOFF) 15: MCP_PinGPA(ALLOFF) MCP_PinGPB(TRIG_15) WaitUsec10 MCP_PinGPB(ALLOFF) ' Start reading WAITPNE(0, |< ECHO, 0) cnt1 := CNT WAITPEQ(0, |< ECHO, 0) cnt2 := CNT Microseconds := (||(cnt1 - cnt2) / (CLKFREQ / 1_000_000)) >> 1 if DEBUG == 1 pst.Home pst.ClearEnd pst.Dec(Microseconds) pst.Str(STRING(" us. ")) Distance := Millimeters(Microseconds) IF DEBUG == 1 pst.Dec(Distance) pst.Str(STRING(" mm.")) pause1ms(100) 'From Timing.spin PUB pause1ms(period) '' Pause execution for period (in units of 1 ms). clkcycles := ((CLKFREQ / _1ms * period) - 4296) #> 381 ' Calculate 1 ms time unit WAITCNT(clkcycles + CNT) ' Wait for designated time PUB Millimeters(ms) : Distance ''Measure object distance in millimeters Distance := ms * 10_000 / TO_CM ' Distance In Millimeters PUB WaitUsec10 WAITCNT ((mcp#uSec * 10) + cnt) PUB MCP_PinGPA(data) mcp.WriteByteA8(MCPADDR, GPIOA, data) PUB MCP_PinGPB(data) mcp.WriteByteA8(MCPADDR, GPIOB, data) PUB MCP_Write(reg, data) mcp.WriteByteA8(MCPADDR, reg, data) DAT TO_CM LONG 29_386
I have never noticed this with the Propeller before.
Can an anomaly like this be relied upon to work all the time?
Here is a video showing it:
Comments
Mike R...
I've attached my MCP23017 object in case you'd like to compare code.
The I2C driver is based off your code, modified by Erlend Fj. Your included zip seems newer so I'll give it a try.
No, our circuits are a big wobbly jelly of electric and magnetic fields that allow every part to interact with every other, including parts that we don't think of as being in the circuit, like your hand. In ways that are often difficult to fathom. Ping on one part of that jelly and all the other parts quiver.