I cannot interfacing PCF8885TS with arduino uno, if I touch the pad the interupt pin will change but when I want to clear interupt via software cannot working, anyone can help me..?
The problem has fix, the address device not 0x40 but 0x20, I try use code for I2C scanner on arduino. And I get 0x20 for address device, and all working now. Thanks
Hi,
Seems like you may not have communication between the mcu and the sensor.
Can you please share your I2C frame to find out if it is a communication issue, please?
Please also share your schematics for a review.
Regards,
Jose
Thanks Jose for reply,
This my schematic and code on arduino, there is something wrong on my schematic?
#include <Wire.h>
#define LED1 3
#define LED2 5
#define LED3 6
#define LED4 9
#define LED5 10
#define LED6 11
#define INT_PIN A2
#define SLEEP_PIN A3
#define STND_BY_LED 10
#define PCF8885_address 0x40
#define SOFT_RESET 0x00
#define CLR_INT 0x03
#define SLEEP 0x05
#define WAKE_UP 0x06
#define WRITE_CONFIG 0x30
#define READ_CONFIG 0x33
#define WRITE_CLOCK 0x35
#define READ_CLOCK 0x36
#define WRITE_MASK 0x39
#define READ_MASK 0x3A
#define INT_OVER_I2C 0x3C
void PC8885_Clear_INT(void) {
Wire.beginTransmission(PCF8885_address);
Wire.write(byte(CLR_INT));
Wire.endTransmission();
}
void PCF8885_SoftReset(void) {
Wire.beginTransmission(PCF8885_address);
Wire.write(byte(SOFT_RESET));
Wire.endTransmission();
}
void PCF8885_WakeUp(void) {
Wire.beginTransmission(PCF8885_address);
Wire.write(byte(WAKE_UP));
Wire.endTransmission();
}
void PCF8885_Sleep(void) {
Wire.beginTransmission(PCF8885_address);
Wire.write(byte(SLEEP));
Wire.endTransmission();
}
void PCF8885_Write_Config(byte data_bit) {
Wire.beginTransmission(PCF8885_address);
Wire.write(byte(WRITE_CONFIG));
Wire.write(data_bit);
Wire.endTransmission();
}
byte PCF8885_Read_Config(void) {
Wire.beginTransmission(PCF8885_address);
Wire.write(byte(READ_CONFIG));
Wire.endTransmission();
Wire.requestFrom(PCF8885_address,1);
byte value_byte = Wire.read();
return value_byte;
}
void PCF8885_Write_Clock(byte data_bit) {
Wire.beginTransmission(PCF8885_address);
Wire.write(WRITE_CLOCK);
Wire.write(data_bit);
Wire.endTransmission();
}
byte PCF8885_Read_CLock() {
Wire.beginTransmission(PCF8885_address);
Wire.write(READ_CLOCK);
Wire.endTransmission();
Wire.requestFrom(PCF8885_address,1);
byte value_byte = Wire.read();
return value_byte;
}
void PCF8885_Write_Mask(byte data_bit) {
Wire.beginTransmission(PCF8885_address);
Wire.write(WRITE_MASK);
Wire.write(data_bit);
Wire.endTransmission();
}
byte PCF8885_Read_Mask() {
Wire.beginTransmission(PCF8885_address);
Wire.write(READ_MASK);
Wire.endTransmission();
Wire.requestFrom(PCF8885_address,1);
byte value_byte = Wire.read();
return value_byte;
}
void PCF8885_IntOver_I2C(void) {
Wire.beginTransmission(PCF8885_address);
Wire.write(INT_OVER_I2C);
Wire.endTransmission();
}
byte read_sensor_touch(void) {
Wire.requestFrom(PCF8885_address,1);
byte value_bit = Wire.read();
return value_bit;
}
byte check_touch_pin(void) {
byte bit_data = digitalRead(INT_PIN);
while (bit_data == LOW) {
bit_data = digitalRead(INT_PIN);
Serial.println("INT Pin LOW");
PC8885_Clear_INT();
byte byte_data = read_sensor_touch();
Serial.print("data touch: ");
Serial.println(byte_data,BIN);
all_LED_ON();
}
Serial.println("INT Pin HIGH");
all_LED_stdby();
}
void all_LED_stdby(void) {
analogWrite(LED1, STND_BY_LED);
analogWrite(LED2, STND_BY_LED);
analogWrite(LED3, STND_BY_LED);
analogWrite(LED4, STND_BY_LED);
analogWrite(LED5, STND_BY_LED);
analogWrite(LED6, STND_BY_LED);
}
void all_LED_ON(void) {
analogWrite(LED1, 255);
analogWrite(LED2, 255);
analogWrite(LED3, 255);
analogWrite(LED4, 255);
analogWrite(LED5, 255);
analogWrite(LED6, 255);
}
void setup() {
// LED IO pin configuration
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(INT_PIN, INPUT_PULLUP);
pinMode(SLEEP_PIN, OUTPUT);
digitalWrite(SLEEP_PIN, LOW);
// USART & I2C configuration
Serial.begin(9600);
Wire.begin();
Serial.println("Riff Electronics");
Serial.println("Touch Device for Infant Incubator");
delay(500);
// set stand by mode for LED
analogWrite(LED1, STND_BY_LED);
analogWrite(LED2, STND_BY_LED);
analogWrite(LED3, STND_BY_LED);
analogWrite(LED4, STND_BY_LED);
analogWrite(LED5, STND_BY_LED);
analogWrite(LED6, STND_BY_LED);
Serial.println("LED in low light");
PCF8885_SoftReset();
PC8885_Clear_INT();
Serial.println("Reset touch driver");
}
void loop() {
check_touch_pin();
byte data_Config = PCF8885_Read_Config();
Serial.print("Register Config : ");
Serial.println(data_Config,BIN);
delay(1000);
}
Hi,
Your schematic seems correct.
Rather than your code on Arduino, I would like to see your I2C frame. I want to confirm that there are proper communication between the mcu and the sensor.
Regards,
Jose
do you mean looking at I2C frame with osciloscope?
Hi,
Yes, I need to look the I2C frame with an oscilloscope or more likely with a logic analyzer.
Regards,
Jose