Giter Club home page Giter Club logo

esp8266_mcp23017_example's Introduction

esp8266_mcp23017_example

I²C Port expander driver example for esp8266. It connects to the mcp2307 with two GPIO pins of your own choice.

The API is very arduino:like, here is the mandatory blinky example:

#include "mcp23017/mcp23017.h"
....
// setup
MCP23017_Self mcpSelf;  // in lieu of C++ member data we have structs :)
uint8_t deviceAddr=0;
uint8_t aMcpPin = 2; // the pin on the mcp23017 we want to write to
i2c_master_gpio_init(); // uses the pins defined by I2C_MASTER_SDA_GPIO & I2C_MASTER_SCL_GPIO
i2c_master_init();  
mcp23017_init(&mcpSelf);
mcp23017_pinMode(&mcpSelf, deviceAddr, aMcpPin, MCP23017_OUTPUT);

....

// loop
mcp23017_digitalWrite(&mcpSelf, deviceAddr, aMcpPin, 0);
delay
mcp23017_digitalWrite(&mcpSelf, deviceAddr, aMcpPin, 1);
delay

You can access the bits one by one like above, by whole bytes or all the bits at once (uint16_t).

The I²C driver is an extended version of the IoT demo i2c_master driver.

While the rest of the MCP23017 driver is a heavily modified port of Adafruit-MCP23017-Arduino-Library.

Todo

  • interrupt support. I don't need this so it won't happend unless someone requests it.

Basic test

I've added a very basic, basic test into the demo. To use this test you should connect each output pin of the mcp23017 to corresponding pin on the 'other side' via a 10+K resistor.

left side pin via right side pin
(bit8) GPBO 10KOhm GPA7 (bit7)
(bit9) GPB1 10KOhm GPA6 (bit6)
(bit10) GPB2 10KOhm GPA5 (bit5)
(bit11) GPB3 10KOhm GPA4 (bit4)
(bit12) GPB4 10KOhm GPA3 (bit3)
(bit13) GPB5 10KOhm GPA2 (bit2)
(bit14) GPB6 10KOhm GPA1 (bit1)
(bit15) GPB7 10KOhm GPA0 (bit0)

Hopefully you should see the text all tests passed in the console.

License

GNU GENERAL PUBLIC LICENSE Version 3

The makefile is copied from esp_mqtt.

###Building and installing:

First you need to install the sdk and the easy way of doing that is to use esp_open_sdk.

You can put that anywhere you like (/opt/local/esp-open-sdk, /esptools etc etc)

Then you could create a small setenv.sh file, containing the location of your newly compiled sdk and other platform specific info;

export SDK_BASE=/opt/local/esp-open-sdk/sdk
export PATH=${SDK_BASE}/../xtensa-lx106-elf/bin:${PATH}
export ESPPORT=/dev/ttyO0  

(or setup your IDE to do the same)

To make a clean build, flash and connect to the esp console you just do this in a shell:

source setenv.sh # This is only needed once per session
make clean && make test

You won't be needing esptool, the makefile only uses esptool.py (provided by esp_open_sdk)

I have tested this with sdk v0.9.5 and v0.9.4 (linux & mac)

esp8266_mcp23017_example's People

Contributors

eadf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.