updated
parent
a7ea2e2372
commit
6dcd4da327
67
readme.md
67
readme.md
|
@ -49,72 +49,9 @@ Lots of I2C devices make use of these chips. In particular many of [Control Eve
|
||||||
|
|
||||||
`npm run sample`
|
`npm run sample`
|
||||||
|
|
||||||
if all went well the device should have been written to and read back and you can confirm the writes and reads were correct by looking at the console output. A more robust way to see that you've succeeded in talking to the mcp chip is the run the test suite
|
if all went well the device should have been written to and read back and you can confirm the writes and reads were correct by looking at the console output. If you hook up a mcp based relay board you should see the relays being turned on and off.
|
||||||
|
|
||||||
`npm run test`
|
|
||||||
|
|
||||||
## Using the module
|
|
||||||
|
|
||||||
|
|
||||||
and here is the code
|
|
||||||
|
|
||||||
```
|
|
||||||
const Bus = require('@uci/i2c').Bus,
|
|
||||||
MCP = require('../lib/mcp23008-17'),
|
|
||||||
// use this require when using your own code
|
|
||||||
// MCP = require('@uci/mcp')
|
|
||||||
pause = require('@uci/utils').pPause
|
|
||||||
|
|
||||||
let bus = new Bus()
|
|
||||||
|
|
||||||
let ADDR = 0x24
|
|
||||||
let CHIP = 'MCP23017'
|
|
||||||
let MS = 500 // so humans can watch the light otherwise set to zero
|
|
||||||
let PORT = 'A'
|
|
||||||
|
|
||||||
let mcp = new MCP[CHIP](bus, ADDR);
|
|
||||||
|
|
||||||
(async function () {
|
|
||||||
|
|
||||||
await mcp.init()
|
|
||||||
await mcp.allOff(PORT) // start clean
|
|
||||||
console.log('all pins off')
|
|
||||||
await pause(MS)
|
|
||||||
|
|
||||||
let pins = [1, 7, 8]
|
|
||||||
await mcp.on(pins, PORT, 'PLC')
|
|
||||||
let result = await mcp.readPort(PORT, { format: 'PLC' })
|
|
||||||
console.log(`${pins} on = current state: ${result.sort()}`)
|
|
||||||
await pause(MS)
|
|
||||||
|
|
||||||
pins = [2, 1, 6]
|
|
||||||
await mcp.toggle(pins, PORT, 'PLC')
|
|
||||||
result = await mcp.readPort(PORT, { format: 'PLC' })
|
|
||||||
console.log(`${pins} toggle = current state: ${result.sort()}`)
|
|
||||||
await pause(MS)
|
|
||||||
|
|
||||||
pins = [2, 1, 7]
|
|
||||||
await mcp.off(pins, PORT, 'PLC')
|
|
||||||
result = await mcp.readPort(PORT, { format: 'PLC' })
|
|
||||||
console.log(`${pins} off = current state: ${result.sort()}`)
|
|
||||||
await pause(MS)
|
|
||||||
|
|
||||||
console.log('all pins off')
|
|
||||||
await mcp.allOff(PORT) // clear port after each test
|
|
||||||
|
|
||||||
})()
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Use the sample.js code as the basis for your mcp i2c project.
|
||||||
|
|
||||||
* [MCP23017 PDF Doc](http://www.microchip.com/wwwproducts/en/mcp23017)
|
* [MCP23017 PDF Doc](http://www.microchip.com/wwwproducts/en/mcp23017)
|
||||||
* [MCP23008 PDF Doc](http://www.microchip.com/wwwproducts/en/mcp23008)
|
* [MCP23008 PDF Doc](http://www.microchip.com/wwwproducts/en/mcp23008)
|
||||||
|
|
Loading…
Reference in New Issue