Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16-bit I/O expander #33

Closed
hans0611 opened this issue Dec 28, 2014 · 4 comments
Closed

16-bit I/O expander #33

hans0611 opened this issue Dec 28, 2014 · 4 comments

Comments

@hans0611
Copy link

I have been using the "old" DCS-BIOS version (experimental branch) with UNO + Ethernet shield W5100 with great success.

In order to expand the numbers of I/O I have been trying to apply a 16-bit I/O expander MCP23017. The origianl idea came from this; http://macetech.com/store/index.php?main_page=product_info&products_id=23

I have tried with a small setup using only one MCP23017 and it works great with "old" DCS-BIOS version. It is very simple to use since instead of digitalWrite you just need to type CS.digitalWrite.
I wonder if it was possible to incorporate the use of 16-bit I/O expanders in the DCS-BIOS as it would greatly increase the numbers of I/O (up to 128 ~ 8 MCP23017)

Great work by the way
ED forum ID: HMA

@jboecker
Copy link
Member

First, you could still do it the "old way" -- the new equivalent to the old onDcsBiosMessage method is called onDcsBiosWrite, and the reference documentation provides example code to insert there that checks whether the address matches and extracts the value to an integer variable for you.

A better way would be to make your own versions of the default classes (Switch2Pos, LED, etc) that are meant to be used with the I/O expander. We can then add these to the next release of the Arduino library.

For example, here's a version of the LED class that uses the MCP23017 (untested):

class MCP23017LED : DcsBios::ExportStreamListener {
    private:
        void onDcsBiosMessage(const char* msg, const char* args);
        char* msg_;
        char pin_;
                Adafruit_MCP23017 &mcp_;
    public:
        MCP23017LED(char* msg, char pin, Adafruit_MCP23017 &mcp);
};


MCP23017LED::MCP23017LED(char* msg, char pin, Adafruit_MCP23017 &mcp) : mcp_(mcp) {
    msg_ = msg;
    pin_ = pin;
    mcp_.pinMode(pin_, OUTPUT);
    mcp_.digitalWrite(pin_, LOW);
}
void MCP23017LED::onDcsBiosMessage(const char* msg, const char* arg) {
    if (strcmp(msg, msg_) == 0) {
        if (arg[0] == '1') {
            mcp_.digitalWrite(pin_, HIGH);
        } else {
            mcp_.digitalWrite(pin_, LOW);
        }
    }
}

@jboecker
Copy link
Member

I still have work to do on the developer guide; the ExportStreamListener and PollingInput classes will be documented there in the future.

@hans0611
Copy link
Author

No rush Jan. Just a kind suggestion that would eventually assist me ;-) Merry Christmas and a happy New Year

@jboecker
Copy link
Member

Closing this, as ExportStreamListener and PollingInput are now documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants