The project consists of an esp8266 nodemcu v3, which receives data via a tca9548a multiplexer from four adxl345 accelerometers, and transmits the data via wi-fi to the phone to display graphs of sensor positions. But the sketch doesn’t work, can someone tell me how to set it up?
#include <Wire.h>
#include <TCA9548A.h>
#include <SparkFun_ADXL345.h>
#include <ESP8266WiFi.h>
// Replace with your network credentials
const char* ssid = “ESPap”;
const char* password = “password”;
// Initialize the TCA9548A multiplexer
TCA9548A tca;
// Initialize the ADXL345 sensors
ADXL345 adxl1;
ADXL345 adxl2;
ADXL345 adxl3;
ADXL345 adxl4;
void setup() {
// Start I2C communication
Wire.begin();
//Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println(“Connecting to WiFi…”);
}
Serial.println(“Connected to WiFi”);
// Initialize the TCA9548A multiplexer
tca.begin();
// Select the channels for each ADXL345 sensor
tca.openChannel(0);
adxl1.powerOn();
tca.openChannel(1);
adxl2.powerOn();
tca.openChannel(2);
adxl3.powerOn();
tca.openChannel(3);
adxl4.powerOn();
}
void loop() {
// Read data from each ADXL345 sensor
tca.openChannel(0);
int x1, y1, z1;
adxl1.readAccel(&x1, &y1, &z1);
tca.openChannel(1);
int x2, y2, z2;
adxl2.readAccel(&x2, &y2, &z2);
tca.openChannel(2);
int x3, y3, z3;
adxl3.readAccel(&x3, &y3, &z3);
tca.openChannel(3);
int x4, y4, z4;
adxl4.readAccel(&x4, &y4, &z4);
// Send the data over Wi-Fi
Serial.print("Sensor 1: ");
Serial.print(x1);
Serial.print(", ");
Serial.print(y1);
Serial.print(", ");
Serial.println(z1);
Serial.print("Sensor 2: ");
Serial.print(x2);
Serial.print(", ");
Serial.print(y2);
Serial.print(", ");
Serial.println(z2);
Serial.print("Sensor 3: ");
Serial.print(x3);
Serial.print(", ");
Serial.print(y3);
Serial.print(", ");
Serial.println(z3);
Serial.print("Sensor 4: ");
Serial.print(x4);
Serial.print(", ");
Serial.print(y4);
Serial.print(", ");
Serial.println(z4);
delay(1000); // Delay for stability
}