hi all,
want to get inputs for mcp23017 by touch sensors TTP223 .
TTP223 for default recognizes 'pressed button' as 1 like HIGH.
One can modify this behavior by setting on Hardware way,
what I dont't like (in my age the handling gets not so easy )
MCP23017 for default recognizes 'pressed button' as 0 like LOW.
Is it possible, to modify that behaviour in sketch ?
What I have here is the TTP223-Board, not the Chip !
One can find a useful picture and description is at
To answer your question. Yes the MCP23017 can do it. It is highly configurable (with one exception that you don't have a pin pull down resistor which anyway does not affect you).
The data sheet https://ww1.microchip.com/downloads/aemDocuments/documents/APID/ProductDocuments/DataSheets/MCP23017-Data-Sheet-DS20001952.pdf is not that easy to follow but your use case is relatively simple. You just want to read the port and see if the pin of your attached sensor is high or low and act accordingly. There is also an Arduino library to interface to the MCP23017.
Had you not put your link to the sensor on a separate line, it would have been displayed as a simple link instead of retrieving content.
Here are some "code highlights" of accessing an MCP23017 without using the library but instead using I2C directly to read a port. I've lifted it directly from a project and hope I've not missed anything :
#include <Wire.h>
// MCP23017
const uint8_t i2cAddr1 = 0x20 ;
setup() {
char buf[80] = {0} ; // general buffer
int rc ;
Wire.beginTransmission( i2cAddr1 );
rc = Wire.endTransmission();
sprintf( buf , "mcp23017 test for 0x20 rc=%d\n" , rc ) ;
Serial.print( buf ) ;
Wire.beginTransmission( i2cAddr1 );
Wire.write(0x00); // IODIR
Wire.write(0b11111111); // input
Wire.write(0b11111111); // input (B)
Wire.endTransmission();
}
loop() {
. . .
uint8_t readX[2] ;
// X buttons
Wire.beginTransmission( i2cAddr1 );
Wire.write(0x12); // GPIOA
Wire.requestFrom(i2cAddr1, (size_t)2); // request X byte(s) of data from MCP20317
readX[ 0 ] = Wire.read();
readX[ 1 ] = Wire.read();
Wire.endTransmission();
// your data is in readX[]
. . .
}
hi all,
while cardriving i had an additional idea : for default
in sketch reading inputs was done this way (simplified)
int pinlist[5]={1,2,3,4,5};
int posinput = 0;
for( int i = 0;i < 5;i++)
{
posinput=digitalread(i);
if(posinput)
System.println("Input recognized from sensor "+String(i));
}
and for mcp.. only modified to this
posinput=digitalread(i);
if(! posinput)
System.println("Neg.Input recognized from sensor "+String(i));
so its done simply with this ?
ok, for using sensors with Arduino directly additionally
a separated loop has to be added..
hi all,
have read and tested several sketches here, but cant proceed with
simple reading of mcp23017..
please check
// Controls an LED via an attached button.
// ok to include only the one needed
// both included here to make things simple for example
#include <Adafruit_MCP23X08.h>
#include <Adafruit_MCP23X17.h>
#define LED_PIN 2 // MCP23XXX pin LED is attached to
#define BUTTON_PIN 3 // MCP23XXX pin button is attached to
// only used for SPI
#define CS_PIN 6
// uncomment appropriate line
Adafruit_MCP23X08 mcp;
//Adafruit_MCP23X17 mcp;
void setup()
{
Serial.begin(9600);
//while (!Serial);
Serial.println("MCP23xxx Combo Test!");
// uncomment appropriate mcp.begin
//if (!mcp.begin_I2C())
if (!mcp.begin_I2C(0x23))
{
//if (!mcp.begin_SPI(CS_PIN)) {
Serial.println("Error.");
while (1);
}
Serial.println("MCP ok !");
delay(1000);
// configure LED pin for output
pinMode(LED_PIN, OUTPUT);
// configure button pin for input with pull up
//mcp.pinMode(BUTTON_PIN, INPUT_PULLUP);
mcp.pinMode(BUTTON_PIN, INPUT);
//Serial.println("Looping...");
Serial.println("Setup Ready !");
}
void loop()
{
int event = mcp.digitalRead(BUTTON_PIN);
delay(10);
Serial.println("Event-Val : "+String(event));
//digitalWrite(LED_PIN, !mcp.digitalRead(BUTTON_PIN));
}
this is the minimal modified code from adafruit lib. master button example..
neither input nor input_pullup works !
isnt there anything to do to distinguish between PAx and PBx ?
dont see this in the original example..
I have merged your topics due to them having too much overlap on the same subject matter @lupus51.
In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.
The reason is that generating multiple threads on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
now mcp23017 does its job even with TTP223-Sensor without
modifying thats behaviour, code here
// Blinks an LED attached to a MCP23XXX pin.
#include <Wire.h>
//- ergaenzt durch LCD-Anzeige zur Adressklaerung
#include <Adafruit_MCP23X17.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include <Adafruit_PWMServoDriver.h>
#define LED_PIN1 0 // MCP23XXX pin LED on PA0 is attached to red
#define LED_PIN2 2 // MCP23XXX pin LED on PB0 is attached to yellow
#define MCP_PIN_INPUT 2
// declare the lcd object for auto i2c address location
//hd44780_I2Cexp lcd;
hd44780_I2Cexp lcd = hd44780_I2Cexp(0x27, 16, 2);
Adafruit_MCP23X17 mcp;
//-testen,ob weitere I2C-Adrese akzeptiert wird..klappt auch !
Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40); //setup the board address 0
// LCD geometry
const uint8_t LCD_COLS = 16;
const uint8_t LCD_ROWS = 2;
uint8_t lcd_status = 0;
String message = "";
bool bLed_On = false;
uint8_t event = 1;
void setup()
{
Serial.begin(9600);
lcd_status = lcd.begin(LCD_COLS, LCD_ROWS);
Serial.println("LCD-Status : " + String(lcd_status));
if (lcd_status) // non zero status means it was unsuccessful
{
// begin() failed so blink error code using the onboard LED if possible
//hd44780::fatalError(status); // does not return
}
message = "mcp23xxx_wLCD_test_input1.ino for Nano";
Serial.println(message);
lcd.clear();
lcd.print(message);
delay(1000);
//while (!Serial);
Serial.println("MCP23xxx Blink Test!");
//if (!mcp.begin_I2C(0x70))
if (!mcp.begin_I2C(0x23))
{
Serial.println("MCP-Error.");
while (1);
}
lcd.clear();
lcd.print("MCP ok !");
// configure pin for output
//mcp.pinMode(LED_PIN1, OUTPUT);
//mcp.pinMode(LED_PIN2, OUTPUT);
mcp.pinMode(MCP_PIN_INPUT, INPUT_PULLUP);
//- LED am A.nano
pinMode(LED_PIN2, OUTPUT);
digitalWrite(LED_PIN2,HIGH);
delay(1500);
digitalWrite(LED_PIN2,LOW);
message = "Setup ready";
Serial.println(message);
lcd.clear();
lcd.print(message);
delay(2000);
}
void loop()
{
int loop_time = 700;
mcp.digitalWrite(LED_PIN2, HIGH);
Serial.println("loopy");
lcd.clear();
lcd.print("loopy");
//delay(1000);
delay(loop_time);
event = mcp.digitalRead(MCP_PIN_INPUT);
lcd.clear();
lcd.print("Event-Val : "+String(event));
delay(10);
if(event == 1)
{
lcd.clear();
lcd.print("Button clicked");
digitalWrite(LED_PIN2, LOW);
}
delay(loop_time);
lcd.clear();
lcd.print("loopz");
Serial.println("loopz");
//delay(2000);
delay(loop_time);
}
one will see, thats is the combo-example adapted to my needs and testing other
equipment on i2c-compatibility.
sensor is TTP223-BA6, guess other sensor-types will match too..