Menu

I2C Bus

Help
Keith
2023-01-11
2023-01-12
  • Keith

    Keith - 2023-01-11

    does anyone know of a device which can sit on the I2C Bus and can be addressed to give me a couple ( or more ) of Output ports?
    i am building a water temperature, pump and Fan controller for my CNC Spindle motor and i have run ou of control ports to control it with my 18F SBC any ideas anyone?

     
  • William Roth

    William Roth - 2023-01-11

    The PCF8574 is probably the most common with hobbyists but there are others just as capable. I think GCB has a library for the PCF8574.

     
    • Anobium

      Anobium - 2023-01-11

      Or the MCP23008 or MCP23017.

       
  • Keith

    Keith - 2023-01-11

    Just the Job .... Two Wire Clock and Data wit 8 ports I/O. Is the MCP23008 supported in GCB?

    I have had a quick peek at the I2C PCF8574 Serial expander demo and the code is again way above my pay grade I think I'm going to need some help with the coding for this - in fact I KNOW I'm going to need some help.

     
  • Anobium

    Anobium - 2023-01-12

    MCP23008 ... it can be made to support you device.

     
  • Anobium

    Anobium - 2023-01-12

    I just realised. There is no demo for the MCP23008.

    Here is the code.

    // Include the library
    #include <MCP23008.h>
    
    // Define the address of the MCP, you can many devices
    #DEFINE MCP23008_DEVICE 0X48
    
    /*
    
    There is two functions
    mcp23008_sendbyte( in mcp23008_device, in mcp23008_instr , in mcp23008_data )
    mcp23008_readbyte( in mcp23008_device, in mcp23008_instr , Out mcp23008_data )      
    
    These are the constants defined.
    
    MCP23008_IODIR              0X00  ' DEFAULT IS INPUT  0= OUT 1= IN
    MCP23008_IPOL               0X01  ' INPUT POLARITY 0= NORMAL, 1= INVERTED
    MCP23008_GPINTEN            0X02  ' ALLOW INTERRUPT ON CHANGE
    MCP23008_DEFVAL             0X03 ' DEFAULT VALUE BEFORE INTERRUPT [FOR EASY COMPARE]
    MCP23008_INTCON             0X04 ' I/O EXPANDER CONFIGURATION .2 1= OPEN DRAIN [WIRE TOGETHER INTERRUPTS]
    MCP23008_IOCON              0X05
    MCP23008_GPPU               0X06 ' WEAK PULL UP RESISTORS [~100KOHHM] VERY HANDY
    MCP23008_ITF                0X07 ' WHO DONE IT, THE INTERRUPT
    MCP23008_INTCAP             0X08 ' SAVES THE EVENT THAT CAUSED THE INTERRUPT
    MCP23008_GPIO               0X09 ' THE IO PORT
    MCP23008_OLAT               0X0A ' THE LATCH OF THE IO PORT SEE DOC
    
    */
    
          ' setup MCP23008
    mcp23008_sendbyte(MCP23008_DEVICE, MCP23008_IODIR  , 0x00)' turn all pins output
    
    ' set ports status on MCP23008
    portsetvalue0 = 0
              mcp23008_sendbyte(MCP23008_DEVICE_1, MCP23008_GPIO, portsetvalue0 )' turn all pins off
    
    ' set ports status on MCP23008
    portsetvalue1 = 255
              mcp23008_sendbyte(MCP23008_DEVICE_1, MCP23008_GPIO, portsetvalue1 )' turn all pins on to state
    
    ' read ports status on MCP23008
    ug_data = 0 // Set to zero to ensure you get a result.  ug_data will be the 8bits of the MCP devices either 0 or 1 all 8 bits.
    
          mcp23008_readbyte(MCP23008_DEVICE_1, MCP23008_GPIO, ug_data )' read state
    

    Hope this helps. It is really easy to use... but, it is currently only software I2C. If this needs to change the hardware I2C then let us know.

    Enjoy

     
  • stan cartwright

    stan cartwright - 2023-01-12

    I used 2 pca9685 boards to drive 18 rc servos using gcb.
    Don't know if relevant.

     
    • Anobium

      Anobium - 2023-01-12

      Very relevent. :-)

      Got any code to share?

       
      • stan cartwright

        stan cartwright - 2023-01-12

        Searching. It's supported by gcb, i2c arduino nano so it's something you probably wrote.
        All servos worked but the leg motion and a psu.. it got put on the shelf.
        I found this.

         

        Last edit: stan cartwright 2023-01-12

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.