Shop OBEX P1 Docs P2 Docs Learn Events
I2C Network of p240s? — Parallax Forums

I2C Network of p240s?

Bill ChennaultBill Chennault Posts: 1,198
edited 2006-09-26 19:03 in BASIC Stamp
All--

I am not an electronics genius. I am more of an electronics moron. However, I need single bit sensors and a way to control relays. I need lots of both. Therefore, with its I2C bus and 32 I/O lines, I was wondering if there is a simple way to place multiple (more than two) Stamp p240 devices in an "I2C" network? IF I could do this, then I would have access to a lot of I/O, which I could process on-board via tablet PC and off-load wirelessly for a PC or a network of PCs to consider.

But, is it possible to create an I2C network of Stamp p240s?

Thanks.

--Bill

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-09-25 16:38
    The built-in I2C commands don't work in slave-mode so you can't use the Stamp as an I2C peripheral. Someone did post some Stamp routines that allow it to be an I2C slave, but the timing is very slow and probably won't work unless you want to write your own I2C routines for the tablet PC. Better to use a standard full duplex serial connection.

    You could use a single Stamp with I/O expansion devices. The 74HC595 provides 8 latched output pins with only 3 or 4 I/O pins and the devices can be cascaded to whatever length you want. The 74HC165 provides 8 inputs with only 3 I/O pins and can also be cascaded.

    You can also create a serial network using several Stamps (and the tablet PC). There's information in the Stamp Manual about how to do it (in the section on the SERIN and SEROUT commands).
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-09-25 16:51
    Yup. The BS2 (all flavors) supports an 'open baud mode' which can be used to make a local 'party line' of BS2's. You can also add '485 drivers to make an 'external' party line of master-slave BS2's. And these use the SERIN/SEROUT commands, which do work in 'master-slave' modes.

    You could even do what you're suggesting more cheaply by having a single BS2 be the 'gateway' for your PC, and have it control (using SHIFTOUT/SHIFTIN) multiple 'slave' '595's for outputs, and '164's for inputs.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2006-09-25 18:27
    Mike and Allan--

    At lunch, I had already figured out I had dumbed off. Since I know very little about electronics, I am wondering about the concept of simply using a BS2p40 at the top of a hierarchy of BS2-IC stamps? (Remember, I am a novice to microcontrollers.) Why couldn't I simply tie a BS2p40 output·directly to the input of of BS2-IC? This would theoretically give me control of 32 BS2-IC Stamps via the BS2p40. Therefore (again, theoretically), I would have 32 x 16 = 512 I/O ports.

    Then, I would let the BS2p40 talk to the tablet PC via USB and the whole "Stamp I/O Machine" would like one MSComm port in VB. (I would build the conglomerated Stamp output syntax·either in the BS2p40 or in the tablet PC and parse it back out in the tablet PC. And, I would do the same thing in the tablet PC in the other direction.)

    Tell me where I err in an idea like this.

    Thanks!

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-09-25 18:52
    You could do it this way. You could use a USB to serial adapter on the BS2p40's debug/programming port to talk to the PC. You would have 32 ports available with the BS2p40 as the master and the BS2's as slaves. The connection could be bidirectional with the master sending commands and the slaves responding with an acknowledgement and/or data. I don't think the BS2's could use their debug/programming port for this unless you add some hardware so you could use a single line for both directions (probably a single transistor and a pullup would work - for an open-collector serial bus). It might be simpler to use one of the BS2's I/O pins for the connection to the BS2p40. You'd still have a lot of I/O pins. It is cheaper to use the 74HC595's and 74HC164's, particularly for just switches and relays. You can buy a lot of these for the cost of one BS2 and, with the SHIFTOUT and SHIFTIN commands, they're really easy to use. Another option might be using several Microchip MCP23017 I/O expanders. These provide 16 bits of bidirectional I/O and talk I2C. You can put up to 8 of these on one I2C bus and it has a nice interrupt-on-change feature and configurable pullups on the I/O pins so you could connect switches without any external parts. It looks like the outputs are rated for only 8ma so you'd need a driver for relays. A single FET per relay (plus protective diode across the relay) would work.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2006-09-25 20:07
    Mike--

    I looked up some data sheets on the 74HC164s. If I could even SPELL electronics, this is doubtless the way to go. Alas, I can't. I wonder if someone makes something that I could BUY and HOOK UP? (I do like my cascading Stamp idea, but I can see how inefficient it is. However, it does provide some level of processing power at every level.

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-09-25 20:43
    Don't despair. Parallax has some excellent freely downloadable books on their Stamps in Class page. Check them out. There were also several articles on expanding the Stamp's I/O in Nuts and Volts, also on the website. I suggest you just look through all the issues quickly to see what articles may be useful.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2006-09-26 14:53
    Mike and All--

    I just bought Whats a Microcontroller? Parts Kit and Text (v2-2) and Process Control Parts and Text. This should get me started.

    Back in the old days, we built networks--prior to the invention of the term "LAN"--using Datapoint's ARCNet. (Before THAT, we built them using serial ports and then eventually UPGRADED to parallel ports.) In any case, ARCNet was a token passing protocol. Although it was physically a star, or string of stars, each node had a physical address and each node maintained a table of addresses, sorted numerically. The "token"--just some specific bytes--circulated among all the nodes according to this table, thus, although it was a physical star, ARCNet was a logical ring. Each time a node had the token, that node had access to the network. Thus, unlike ethernet, ARCNet was a deterministic network.

    Well, I was thinking that a BS2p40 could easily use a single output·line to which all other Stamps were connected by a single one of their input lines. Each Stamp would be assigned an identifier. When the "master" (the BS2p40) formed a command for a particular stamp, it would simply preface it with the desired Stamp's identifier and send the whole thing to every stamp at the same time via the single output line dedicated to that purpose. Each Stamp would then check to see if the identifier was its identifier. If it was not, then that Stamp would simply ignore the command. However, if it was, then that Stamp would execute the command.

    Multi-Stamp commands could easily be constructed by the BS2p40 by using the unique identifiers to which multiple Stamps were programmed to·"listen" for. That way, you could execute an entire series of commands at the low-level Stamp that would do a certain fundamental task. (Like cause four leg motors to move.)

    What am I missing or erroneously assuming? (I see no reason to quit learning just because I have bought some stuff!)

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-09-26 15:19
    Yup. And the BS2 has the 'open' baud modes, which let you implement a 'wired OR' buss line exactly as you describe, using SERIN/SEROUT with the token passing scheme you've described.

    The reason people use the '595 and '164 is cost, usually. If each BS2 costs $50, 16 of them is $800. A '595 is around $1.00. So if all you want is 256 outputs (16 x 16) then 32 '595s will get that for you for $32. If a BS2 cost $1.00, then why mess around with the '595?

    Another reason is speed. The SHIFTIN/SHIFTOUT clocking runs at about 56 KBits/Sec. The SERIN/SEROUT runs at 9600 or 19200 baud, AND has syncronization delays while the 'slave' BS2's 'listen' (there's NO serial buffering, they MUST be 'pended' in a SERIN or they'll miss data). There's ways of working with this, but it is an issue.

    Bottom line: The BS2p40 lets you decide how many I/O pins you need, and how much 'local intelligence' you need.· If 'raw I/O', with no intelligence is needed, then a BS2 with some '595s may do it.· If LOTS of 'local intelligence' is needed, then more than two BS2p40's may give you that.

    Were I you, I'd probably prototype a system with a BS2 'master', two BS2p40 'slaves', a subset of the desired I/O, and try it out.· Sounds like you're on your way down that path, actually.

    Post Edited (allanlane5) : 9/26/2006 3:24:21 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2006-09-26 15:53
    Bill,
    I worked for Datapoint's research department when ARCnet was developed. It actually was a successor to a simple open-collector party line bus used for file transfers and printer servers. You could certainly implement a similar master-less token passing system if you want.
    Mike
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2006-09-26 16:32
    Mike--

    You worked for Datapoint! WOW! You are my hero! Datapoint (ARCNet, actually) made my entire career! I bet you have a lot of stories.

    --Bill
    ps I am still waiting for the 20MB/s version!!! [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2006-09-26 16:43
    Allan--

    Re: "The reason people use the '595 and '164 is cost, usually. If each BS2 costs $50, 16 of them is $800. A '595 is around $1.00. So if all you want is 256 outputs (16 x 16) then 32 '595s will get that for you for $32. If a BS2 cost $1.00, then why mess around with the '595?"
    I know you are correct about using the Stamp and some chips to do I/O. I am simply not an electronics-type person, much to my chagrin. (However, if I can find some good hints, I can do a lot of research and maybe gin something up that doesn't smoke very much.)

    The bottom line is that I need only a little intelligence and LOTS of I/O. A BS2p40 and your recommended method is doubtless what I REALLY need. Where can I find a schematic? One that will make it clear how to add bits, as necessary?

    --Bill


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-09-26 17:07
    Get the StampWorks book (download it or buy the paper version) and look at experiments #23 and #24. These show you how to connect and program a Stamp for use with the 74HC595 to drive a bunch of LEDs and the 74HC164 to handle a bunch of switch closures. They include instructions in connecting them in series.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2006-09-26 19:03
    Mike--

    Thank you for your forbearance.

    Successfully downloaded and saved . . . now!

    --Bill





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
Sign In or Register to comment.