Replies: 4 comments 1 reply
-
I'm not sure what the rules are in this case, but for stm32duino, there are 4 different Wire.begin() functions, chosen by the type of the parameters - distinguishing between int and uint8_t ; https://www.stm32duino.com/viewtopic.php?t=765
So, it looks like by using #define you're getting type int when you need uint8_t for the pin definitions. i.e. try changing:
to
|
Beta Was this translation helpful? Give feedback.
-
I expect you're right - Wire is just using TwoWire. I guess we could track down the code behind it, but it can probably just be worked out by experiment. There shouldn't be any difference between using WIRE after #define WIRE Wire, rather than just using Wire. So, if setting the pins before Wire.begin() (with no arguments) works, I guess do that. If not, you could try setting the pins after Wire.begin(). Possibly they're overriden to the defaults by Wire.begin(), but aren't needed until the i2c read or write, so perhaps you can set them afterwards. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Thanks guys, setting the pins before Wire.begin() did the trick! I did try this on one of my (many) earlier attempts and while it compiled OK, it didn't find the CAP1188 which led me down the pin assignment path. I now suspect that the problem there was actually with the i2c address not the pin assignment, but in any case all good now, thanks again. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm having some problems getting the Adafruit CAP1188 capacitive switch board to work with the Pico W over i2c. I've managed to get it working on a Nano using the Adafruit CAP1188 library and example sketch, so I think the board, library and example code are basically fine. However, running the example sketch on the Pico W gives the "CAP1188 not found" error message in the monitor. I'm connecting the CAP1188 SDA to the Pico GPIO pin 0, and SCL to pin 1. The CAP1188 board's AD pin is connected to 3V3 to set it's i2c address to 0x28. I ran this sketch to check if the Pico could talk to the CAP1188 board:
`#include <Wire.h>
// Set I2C bus to use: Wire, Wire1, etc. Wire = bus 0, Wire1 = bus 1
#define WIRE Wire
void setup() {
WIRE.setSDA(0);
WIRE.setSCL(1);
WIRE.begin();
Serial.begin(9600);
while (!Serial)
delay(10);
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
WIRE.beginTransmission(address);
error = WIRE.endTransmission();
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}`
This reported a device at 0x28, so all good there. Since the Adafruit sketch requires the Wire library, I wondered if the SCL and SDA pins needed to be explicitly defined for the Pico, as in the code above. Googling tells me that Wire.begin(SDApin, SCLpin) should do this, however compiling the code below gives the error "Compilation error: no matching function for call to 'TwoWire::begin(int, int)'". Here's the code I'm trying to run (essentially a slightly modified version of the Adafruit example sketch):
`#include <Wire.h>
#include <SPI.h>
#include <Adafruit_CAP1188.h>
// Reset Pin is used for I2C or SPI
#define CAP1188_RESET 9 // Can be any GPIO pin
#define I2C_SDA 0
#define I2C_SCL 1
// Use I2C without a reset pin
Adafruit_CAP1188 cap = Adafruit_CAP1188();
void setup() {
Serial.begin(9600);
Wire.begin(I2C_SDA, I2C_SCL);
while (!Serial)
;
Serial.println("CAP 1188 Test");
if (!cap.begin(0x28)) { // Connecting pin AD to 3V3 sets up the i2c address 0x28
Serial.println("CAP1188 not found");
} else Serial.println("CAP1188 found!");
}
void loop() {
uint8_t touched = cap.touched();
if (touched == 0) {
// No touch detected
return;
}
for (uint8_t i = 0; i < 8; i++) {
if (touched & (1 << i)) {
Serial.print("C");
Serial.print(i + 1);
Serial.print("\t");
}
}
Serial.println();
delay(50);
}
`
All advice would be very welcome, thank you!
Beta Was this translation helpful? Give feedback.
All reactions