Shop OBEX P1 Docs P2 Docs Learn Events
Out of pins! — Parallax Forums

Out of pins!

SabaiSabai Posts: 27
edited 2009-10-06 18:17 in BASIC Stamp
I am kind of new to basic stamp and I am working my way with the first application. My problem is the amount of pins on Basic stamp 2.

My application will use this.

Lcd parallel need 7 pins
ADC0831 need 3 pins (humidity sensor)
DS1620 need 3 pins (temp sensor)
4 buttons 4 pins
1 pulse in (From wind sensor)
2 pins for output

20 pins!

This is what I need and as you can see I need 20 pins. How can this be done, or can it not be done.

Regards

Bert

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-02 18:31
    It is often possible to have several devices share pins. Most parallel LCDs have several control lines and a 4-bit data bus. If the LCD is not enabled, the 4-bit data bus isn't used. Similarly, the ADC0831 and the DS1620 have a chip select line, a clock line, and a shared data in/out line. The clock line and the data line can be shared.

    For the DS1620, holding the /RST line low disables the device. For the ADC0831, holding the /CS line high disables the device. For most parallel LCDs, holding the E (enable) line low disables the device.

    You can use a 74HC165 serial shift register to handle up to 8 buttons. It also has a clock and data line that can be shared. It would require 2 additional pins, one for /CE (chip enable) and the other a clock to sample the button state.

    The LCD would need the 7 pins with 4 pins available to be shared
    The ADC0831 would need one additional pin
    The DS1620 would need one additional pin
    The 74HC165 would need two additional pins
    The wind sensor would need one pin
    The unspecified outputs would need 2 pins
    That's a total of 14

    Look for the StampWorks Manual on Parallax's website and download it. There's a chapter on the use of a 74HC165.

    A much simpler alternative would be to switch to a serial LCD which would only require one I/O pin instead of 7

    Post Edited (Mike Green) : 10/2/2009 6:37:07 PM GMT
  • SabaiSabai Posts: 27
    edited 2009-10-02 18:46
    Thanks Mike for your fats reply.

    I do agree with you that a serial LCD is the easiest way to do this.

    But can you just explain for me how to share pins? For example I got this
    '
    [noparse][[/noparse] I/O Definitions ]

    E PIN 1 ' Enable pin
    RW PIN 2 ' Read/Write
    RS CON 3 ' Register Select
    LcdDirs VAR DIRB ' bus DDR
    LcdBusOut VAR OUTB ' 4-bit LCD data bus
    LcdBusIn VAR INB
    BtnOk PIN 13
    BtnCancel PIN 14

    How do I write this if I share pins?

    B
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-02 19:10
    The "B" pins are 4-7. If you look at the LCD code, you'll see that it always sets E to high, does something, then sets E to low. When E is low, the LCD is not using pins 4-7, so they can be used for some other purpose. Their direction register bits would have to be changed (and maybe changed back when the LCD is used again). The ADC0831 has a /CS, CLK, and DO pins. You'd assign /CS to its own pin and assign CLK to pin 4 and DO to pin 5. Maybe have:

    ADCCS PIN 8
    ADCCLK PIN 4
    ADCDO PIN 5

    You'd do a "HIGH ADCCS" during your program initialization to turn off the ADC0831 and start your "read a value" routine with

    LOW ADCCLK
    INPUT ADCDO
    ... normal read from ADC0831 code ...

    The LCD at this point is disabled (although it's still displaying what was last sent to it) and not using I/O pins 4-7. The next time the LCD is enabled, the data pins' direction (4-7) would have to be reinitialized. The existing sample routines might do that anyway.
  • SabaiSabai Posts: 27
    edited 2009-10-03 17:20
    After looking around did I came up with this. Will this work?

    Pin 2 is for the lcd RW since I am only going to write can I keep this low so that will save one pin on the lcd.

    0 Pulse
    1 e LCD
    2 Clock Shift
    3 rs LCD
    4 bus LCD
    5 bus LCD
    6 bus LCD
    7 DO DS & ADC
    8 Clock DS & ADC
    9 RST DS
    10 CS ADC
    11 Do Shift
    12 Load Shift
    13 Out
    14 Out
  • darkwingdarkwing Posts: 3
    edited 2009-10-06 02:30
    wtf i didn't even see this.[noparse]:([/noparse]
  • SabaiSabai Posts: 27
    edited 2009-10-06 16:06
    I have connected it as my last post and it works great, just FYI

    B
  • hover1hover1 Posts: 1,929
    edited 2009-10-06 18:17
    That's great!
    Sabai said...
    I have connected it as my last post and it works great, just FYI

    B
Sign In or Register to comment.