(WeMos D1 ESP Wroom 02 Board ESP8266 Mini-WiFi Nodemcu Module) with ADXL345.

Hello Everyone,

I have interfaced wemos ESP8266 battery module with ADXL_345 and I am uploading the values on the server. I can see the values uploading over the server.

In the code I am giving SPI clock rate of 40 MHz and I have checked from different clock rate values from 1 MHz to 40 MHz. Actually ,I want the minimum 1K sample rate over wifi, But After uploading the code When i check the SPI clock rate on ADXL_345 over oscilloscope it comes in around (90 - 160) hertz even if I comment serial section in the programming and Data rate on SDO pin also comes in Hertz.

But if I check the same thing on the device on the normal code without any wifi settings in that case i can see data rate at around 20 K and SPI clock at specified clock rate in the code.

I am not able to understand the problem here. Is it wifi connectivity issue or coding issue?

Is it wifi connectivity issue or coding issue?


Since you have posted no code, or any links to any products, we can not see what you are doing in the code or with the hardware.

Are you communicating with the ADXL345 using SPI? That appears to be an I2C device, so using SPI to communicate with it would be strange.


Thank you for your reply, Actually the one ADXL_345 board which I am using supports both the interfaces SPI and I2C I have attached the picture of it with this reply and Also I have posted the code below.

link for the esp8266 board which I am using for this project.

#define INTERVAL 10
#define SCLpin   14 //D5=
#define SDOpin   12 //D6
#define SDApin   13 //D7
#define SSpin     5 //D1 

char BW_RATE = 0x2C;   // Data Rate and power mode control
char POWER_CTL=0x2D;   // Power Control Register
char DATA_FORMAT=0x31; // Data Format Register
char DATAX0=0x32;
char DATAX1=0x33;
char DATAY0=0x34;
char DATAY1=0x35;
char DATAZ0=0x36;
char DATAZ1=0x37;

int X_Data, Y_Data, Z_Data;

char str[10];
long lastMsg=0;
byte TO_READ = 6;

WiFiClient espClient;
PubSubClient client(espClient);

void setup_wifi()
  Serial.print("Connecting to ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
void reconnect()
  while (!client.connected()) 
    Serial.print("Attempting MQTT connection...");
    String clientId = "ESP8266Client-";
    clientId += String(random(0xffff), HEX);
    if (client.connect(clientId.c_str()))
      client.publish("outTopic", "My First MQTT Code");
      client.subscribe("Welcome ESP8266");
      Serial.print("failed, rc=");
      Serial.println(" try again in 5 seconds");

void setup()
  SPI.beginTransaction(SPISettings(40000000,MSBFIRST,SPI_MODE3));//max 40 MHz

  client.setServer(mqtt_server, 1883);
  pinMode(SSpin , OUTPUT);
  digitalWrite(SSpin , HIGH);
  writeRegister(POWER_CTL, 0x00);// Configured in Stand By Mode
  writeRegister(POWER_CTL, 0x08); // Configured in Measurement Mode 
  writeRegister(DATA_FORMAT, 0x0B); // ±16g 10bit, 4mg/LSB.
  writeRegister(BW_RATE, 0x0F); // Baud Rate Register configuration. 3200 Hz

void loop()
  if (!client.connected())

  long now = millis();
  if (now - lastMsg > INTERVAL)
    lastMsg = now;
void read_345()
// DATAX0 
  readRegister(DATAX0, TO_READ, str); 
  X_Data= ((int)str[1] << 8) & (0x1F00) | (int)str[0];//(0xF00 for getting 13 bit output)
  Y_Data= ((int)str[3] << 8) & (0x1F00) | (int)str[2];
  Z_Data= ((int)str[5] << 8) & (0x1F00) | (int)str[4];
  sprintf(str,"%d %d %d",X_Data,Y_Data,Z_Data);

void writeRegister(char registerAddress, char value) 
    digitalWrite(SSpin , LOW);
    digitalWrite(SSpin , LOW);

void readRegister(char registerAddress, int16_t numBytes,char * str) 
    char address = (0x80 | registerAddress);
    if (numBytes > 1)address = address | 0x40;
    digitalWrite(SSpin , LOW);
       for (int i = 0; i < numBytes; i++)
            str[i] = SPI.transfer(0x00);
    digitalWrite(SSpin , HIGH);