​ ​ ​ ​ Help please with 20M2 inputs
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 24

Thread: Help please with 20M2 inputs

  1. #1

    Default Help please with 20M2 inputs

    Hi. I'd be very grateful for a bit of guidance. I have a 20M2 board - 7 outputs & 7 inputs. The outputs work fine but I'm having trouble with the inputs and I think I must be making a fundamental error in either my programming or in the way I have configured the inputs.

    1. In reading the inputs, (for example input 7) I am using the syntax 'if pinC.7 = 1 then high <6>. I think this should make output 6 'high' when input 7 is 'on'. This doesn't work What am I doing wrong?
    2. If I want to get input 7 to remain in a loop until the input os 'on', what syntax do I use?
    3. Have I connected the inputs correctly? I have assumed each input is a pair of wires from the PicAxe board and that when a connection is made between these two wires, the input is 'on' (pinC.7 = 1). When the connection is broken, the input is 'off' (pinC.7 =0).

    Thanks.


    using editor 6.0.9.3 on Windows XP

  2. #2
    Senior Member
    Join Date
    Feb 2010
    Location
    Don't Mess With My Texas!
    Posts
    2,296

    Default

    1. In reading the inputs, (for example input 7) I am using the syntax 'if pinC.7 = 1 then high <6>. I think this should make output 6 'high' when input 7 is 'on'. This doesn't work What am I doing wrong?
    Code:
    if pinC.7 = 1 then
       high B.6
    endif
    or

    Code:
    if pinC.7 = 1 then : high B.6 : endif
    - Tex
    __________________________________________________ _______________________
    "Truth lies dormant in our future history." ― Tex Clodhopper LXV
    “Confidence is ignorance. If you're feeling cocky, it's because there's something you don't know.” ― Eoin Colfer, Artemis Fowl

  3. #3
    Senior Member
    Join Date
    Feb 2010
    Location
    Don't Mess With My Texas!
    Posts
    2,296

    Default

    2. If I want to get input 7 to remain in a loop until the input os 'on', what syntax do I use?
    Code:
    do : loop until C.7 = 1 ; assuming the pin is tied LOW until activated
    Add this if C.7 is driven by a switch with a finger pressing on it. This will wait in the loop until they lift the finger.

    Code:
    do : loop until C.7 = 0
    - Tex
    __________________________________________________ _______________________
    "Truth lies dormant in our future history." ― Tex Clodhopper LXV
    “Confidence is ignorance. If you're feeling cocky, it's because there's something you don't know.” ― Eoin Colfer, Artemis Fowl

  4. #4
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    23,878

    Default

    Welcome to the PICAXE forum.

    1) What you have should work but you perhaps have the syntax wrong. For a one line IF-THEN what follows must be a label. To have the HIGH 6 - which should ideally be B.6 - you would use a multi-line statement -

    Code:
    If pinC.7 = 1 Then
      High B.6
    End If
    Though that can be reduced to one line if you use colons to separate each line -

    Code:
    If pinC.7 = 1 Then : High B.6 : End If
    2) The best way of waiting until an input goes high is the DO-LOOP -

    Code:
    Do
    Loop Until pinC.7 = 1
    Again that can be compacted onto one line by placing a colon between the DO and the LOOP. The UNTIL Can be replaced by a WHILE if that makes more sense.

    3) It depends on which board you are using and how you have wired the button.

    If the input has a pull-down resistor, the button should be between the input and +V and the input pin will read 1 when the button is pushed, 0 when it isn't.

    If the input has a pull-up resistor, the button should be between the input and 0V and the input pin will read 0 when the button is pushed, 1 when it isn't.

  5. #5
    Senior Member
    Join Date
    Feb 2010
    Location
    Don't Mess With My Texas!
    Posts
    2,296

    Default

    3. Have I connected the inputs correctly? I have assumed each input is a pair of wires from the PicAxe board and that when a connection is made between these two wires, the input is 'on' (pinC.7 = 1). When the connection is broken, the input is 'off' (pinC.7 =0).
    If one of wires of the pair is tied to VCC (the power connection or HIGH level) and the other is tied to the pin which is connected to GND or LOW level with a 1K to 10K resistor, then yes you are correct.

    There are several ways to do this by rearranging the electrical part and the programming logic.
    - Tex
    __________________________________________________ _______________________
    "Truth lies dormant in our future history." ― Tex Clodhopper LXV
    “Confidence is ignorance. If you're feeling cocky, it's because there's something you don't know.” ― Eoin Colfer, Artemis Fowl

  6. #6

    Default Thanks :)

    Thanks for the welcome and the help.

    I have resorted to running test programs to see what works.

    test:
    If pinC.7 <> 1 then test; pin7 is a push to make switch
    high 6; switches on a lamp
    pause 1000; waits a second
    low 6; switches off lamp
    end

    this didn't work - the program ignores the 'if pinC' line and goes immediately to the next line. I'm still uncertain as to whether I'm electrically connecting the inputs correctly.

    my next move is to try your suggestion...

    test:
    If pinC.7 = 1 Then
    High B.6
    pause 1000
    Low B.6
    End If


    Hopefully, this will make the difference. This will show if the input is working.

    Then

    test:
    Do
    Loop Until pinC.7 = 1
    High B.6
    pause 1000
    Low B.6
    End If


    Does this look right? What's the 'endif' command all about?

    Board photo2.jpg

    Thanks again.


    Quote Originally Posted by hippy View Post
    Welcome to the PICAXE forum.



    1) What you have should work but you perhaps have the syntax wrong. For a one line IF-THEN what follows must be a label. To have the HIGH 6 - which should ideally be B.6 - you would use a multi-line statement -

    Code:
    If pinC.7 = 1 Then
      High B.6
    End If
    Though that can be reduced to one line if you use colons to separate each line -

    Code:
    If pinC.7 = 1 Then : High B.6 : End If
    2) The best way of waiting until an input goes high is the DO-LOOP -

    Code:
    Do
    Loop Until pinC.7 = 1
    Again that can be compacted onto one line by placing a colon between the DO and the LOOP. The UNTIL Can be replaced by a WHILE if that makes more sense.

    3) It depends on which board you are using and how you have wired the button.

    If the input has a pull-down resistor, the button should be between the input and +V and the input pin will read 1 when the button is pushed, 0 when it isn't.

    If the input has a pull-up resistor, the button should be between the input and 0V and the input pin will read 0 when the button is pushed, 1 when it isn't.

  7. #7

    Default

    Hi. Thanks for your replies. My understanding is developing but the learning curve is steep.
    Board photo2.jpg
    I think this is the board I am using. The inputs are pairs numbered from 0 to 7. I had assumed that the each pair for each input was connected as you have said. However, I have not placed a resistor in any of the input circuits. Does this mean my switch across these two input wires has produced a 'short' and therefore damaged the pic? When I last did this sort of stuff, I used a proprietary 'buffer box' connected directly to a computer. The programming was very similar but I guess the buffer box provided circuit protection.



    Quote Originally Posted by Texasclodhopper View Post
    If one of wires of the pair is tied to VCC (the power connection or HIGH level) and the other is tied to the pin which is connected to GND or LOW level with a 1K to 10K resistor, then yes you are correct.

    There are several ways to do this by rearranging the electrical part and the programming logic.

  8. #8

    Default

    Hi again. Trying desperately to get this straight in my head. Can I use this as follows...

    Code:
    test:
    do : loop until C.7 = 1
    high B.6; turn on lamp
    pause 1000
    low B.6
    end
    Will this wait indefinitely until there is a connection across the two wires of input 7 before turning the lamp on and off?
    Should I place a 10k resistor in the input circuit?

    Thanks again?

    Quote Originally Posted by Texasclodhopper View Post
    Code:
    do : loop until C.7 = 1 ; assuming the pin is tied LOW until activated
    Add this if C.7 is driven by a switch with a finger pressing on it. This will wait in the loop until they lift the finger.

    Code:
    do : loop until C.7 = 0

  9. #9
    Senior Member
    Join Date
    Dec 2012
    Location
    Midlands UK
    Posts
    261

    Default

    Hi oldbloke,
    Are you using the simulator in PE6? No soldering required. Its quick & easy.

    Regards bear..

  10. #10
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    23,878

    Default

    The board you have seems to be an AXE118. If so then the pins on the left are input pins with V+ next to them. Shorting the two together should take the input high. The pull-down resistors are in the 'thin black strip' component on the left; that's a Single In-Line resistor package (SIL).

    Perhaps try this code ...

    Code:
    #Picaxe 20M2
    #Terminal 4800
    Do
      If pinC.7 = 0 Then
        SerTxd( "Pin C.7 is low (0)", CR, LF )
        Do : Loop While PinC.7 = 0
      Else
        SerTxd( "Pin C.7 is high (1)", CR, LF )
        Do : Loop While PinC.7 = 1
      End If
    Loop

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •