I am attempting to connect a Boron and P2 through an I2C connection. When I complete the SDA & SCL connections, the P2 immediately throws a type 14 heap error and resets.
My Boron is acting as a the central device to utilize cellular to communicate back to the cloud. It's Tx/Rx pins are in use with another device.
I've connected D0 on the Boron & P2 as well as D1 on the Boron & P2. Each have a pull up resistor.
My firmware is scanning for available addresses in order to confirm it can connect with the P2. But immediately upon completing the SDA/SCl circuit the error gets thrown.
Any ideas on how to avoid a type 14 error? Is there a different communication protocol I should use?
Here is my Boron code:
#include "Particle.h"
const int PHOTON_ADDRESS = 0x08; // I2C address of the Photon 2
void setup() {
Wire.begin(); // Join the I2C bus as a central device
Serial.begin(9600);
while (!Serial.isConnected()) {
delay(100);
}
Serial.println("I2C setup complete");
}
void loop() {
Serial.println("Requesting data from Photon");
// Request data from the Photon 2
Wire.requestFrom(PHOTON_ADDRESS, 32); // Request 32 bytes from the Photon 2
// Read the response
String response = "";
while (Wire.available()) {
char c = Wire.read();
response += c;
}
// Print the response to the serial monitor
if (response.length() > 0) {
Serial.println("Received from Photon: " + response);
} else {
Serial.println("No response from Photon");
}
delay(1000); // Wait for 1 second before the next request
}
and the P2 code:
// Photon 2 I2C Peripheral Code
#include "Particle.h"
void setup() {
Serial.begin(9600);
Wire.begin(0x08); // Join the I2C bus with address 0x08
Wire.onRequest(requestEvent); // Register the request event handler
Particle.publish("I2C setup complete!");
}
// Function to handle request from the central device
void requestEvent() {
Particle.publish("I2C request received");
// Send a response to the Boron
Wire.write("Hello from Photon 2!");
Particle.publish("Response Sent");
}
void loop() {
// Main loop can perform other tasks
delay(1000);
}