Any multiple button tutorials for MCP23017?

I am trying to make 4 buttons work with an MCP23017 and my Teensy board.

I got one button working and went to add a second button and it gives the same serial window display value as button one.

I see plenty of examples out there with one button but not much on multiple buttons.

I’d like to add a pic of my breadboard but I don’t see any attachment links?

Thanks for any help…

@rfresh737 I’ve got a feeling you’re on the wrong forum. This is meant for Particle devices, since this is the Particle community forum. Although a lot of similarities are shared with Arduinos the Particle devices are still quite different. I think you’ll be able to find more support on a forum meant for your specific device, the Teensy in this case.

Googling on “MCP23017 arduino” however, has leas me to this tutorial, so you should be able to find some as well :wink:

1 Like

Thanks…I have seen that tutorial but it doesn’t show how multiple buttons work…I’ll keep looking…thanks again…

But just to not let you go without showing what you could gain by moving over to :particle: Particle and its awesome community :wink:

The sample code looks like this and it in fact does show you a multiple button solution.

This is Arduino code and not Particle

/*
 Example 41.2 - Microchip MCP23017 with Arduino
 http://tronixstuff.com/tutorials > chapter 41
 John Boxall | CC by-sa-nc
 */
// pins 15~17 to GND, I2C bus address is 0x20
#include "Wire.h"
byte inputs=0;
void setup()
{
 Serial.begin(9600);
 Wire.begin(); // wake up I2C bus
}
void loop()
{
 Wire.beginTransmission(0x20);
 Wire.write(0x13); // set MCP23017 memory pointer to GPIOB address
 Wire.endTransmission();
 Wire.requestFrom(0x20, 1); // request one byte of data from MCP20317
 inputs=Wire.read(); // store the incoming byte into "inputs"
 if (inputs>0) // if a button was pressed
 {
 Serial.println(inputs, BIN); // display the contents of the GPIOB register in binary
 delay(200); // for debounce
 }
}

Each bit in inputs stands for one input line of port B (in this case) and for that reason you should see different output in your serial monitor, unless you have wired the extra buttons to the wrong port or in any other wrong way.
For this reason you’d need to give some more info about your wiring.


Hope to got you interested in Particle and its community :sunglasses:

1 Like

Thanks a lot…when I’m finished with my project I’ll take a closer look at your community…!!!

2 Likes

Hi all,

Well, I got my MCP23017 code finished and I’m using it on a Teensy 3.2 board with 2 MCP chips.

I’m back to take a closer look at Particle and what features you have to offer. After working most of this year with Ardunio and Teensy, the feature I need the most is one that you provide and they don’t: remote flashing capability.

I also need Mouse.moveTo() (implemented by Teensy but not Ardunio) which is an absolute mouse move feature so I’m looking into that with particle.

I also need to be able to send keyboard commands to my Win7 PC to operate a windows app I am trying to control.

If Particle has support for keyboard and absolute move moves, then I’ve found a new development platform!!

I’ve seen you posted on several USB HID threads :wink:

AFAIK the main guy dealing with this on the Particle side (@satishgn ) has taken a leave (for a while) and Particle is up to their neck with the upcoming Electron - but the GitHub issue/request is still open.

But my last experience with this is a while back. The respective files are still there and with local build it should still work, but the abs mouse move has not been implemented and also composite HID is not there yet.
I’ve been looking into it myself but just never got my head wrapped round a way to incorporate Paul Stoffregen’s (Teensy) HID descriptots into the Particle structure and how to find a way to control the Build conditional compiling (as the Teensyduino IDE does).

But if someone created a poll for who’d want this implemented the way it is on Teensy, I’d be definetly vote for it :wink:

Thanks for the update.

I’m so new around here I don’t know what Electron is? Is that a new board coming out?

I wish I had the programming skills to help with the implementation of Mouse.moveTo() (absolute) but I’ve not worked with embedded coding at all. My coding experience is ‘average’ with C and C# using IDE’s. I did some assembly work years back on the 8088/8086 chip and really enjoyed working in assembly.

Yup, it’s the latest child to the family which sports a 2G/3G radio rather than WiFi.

BTW: This is the GitHub issue I mentioned
https://github.com/spark/firmware/issues/528