I am having trouble connecting these modules. My target is to send accelerometer data from the ADXL345 via the Xiao and the ESP8266-01 to my laptop. I have searched for the connectivity to no avail. Could you provide any help or guidance?
connect
- the ADXL345 to the Xiao using I2C
- the Xiao UART to ESP-01 UART
- the ESP-01 to WiFi
or
- the ADXL345 to the ESP-01 using I2C
- . the ESP-01 to WiFi
have a look at cayenne-mqtt-and-standalone-esp8266-esp-01
to check the ESP-01 I2C I connected a LSM9DS1 (9-axis iNEMO inertial module (IMU): 3D magnetometer, 3D accelerometer, 3D gyroscope with I2C and SPI) sensor and tested with code
// ESP-01 (ESP8266) test of LSM9DS1 sensor
// connect SCL to GP2 and SDA to GP0
#include <Wire.h>
//#include <SPI.h>
#include "Adafruit_LSM9DS1.h"
//#include <Adafruit_Sensor.h> // not used in this demo but required!
void xprintf(const char *format, ...)
{
char buffer[256];
va_list args;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
Serial.print(buffer);
}
void setupSensor()
{
// 1.) Set the accelerometer range
LSM9DS1_setupAccel(LSM9DS1_ACCELRANGE_2G);
//LSM9DS1_setupAccel(LSM9DS1_ACCELRANGE_4G);
//LSM9DS1_setupAccel(LSM9DS1_ACCELRANGE_8G);
//LSM9DS1_setupAccel(LSM9DS1_ACCELRANGE_16G);
// 2.) Set the magnetometer sensitivity
LSM9DS1_setupMag(LSM9DS1_MAGGAIN_4GAUSS);
//LSM9DS1_setupMag(LSM9DS1_MAGGAIN_8GAUSS);
//LSM9DS1_setupMag(LSM9DS1_MAGGAIN_12GAUSS);
//LSM9DS1_setupMag(LSM9DS1_MAGGAIN_16GAUSS);
// 3.) Setup the gyroscope
LSM9DS1_setupGyro(LSM9DS1_GYROSCALE_245DPS);
//LSM9DS1_setupGyro(LSM9DS1_GYROSCALE_500DPS);
//LSM9DS1_setupGyro(LSM9DS1_GYROSCALE_2000DPS);
}
void setup()
{
Serial.begin(115200);
delay(10000);
Serial.print("blinking pin ");
Serial.println(LED_BUILTIN);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
for(int i=0;i<10;i++) {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
Serial.print("blinking pin ");
Serial.println(LED_BUILTIN);
}
Wire.begin(0, 2); // for ESP-01 I2C use pins GPIO0 (SDA) and GPIO2 (SCL)
Serial.println("ESP-01 (ESP8266) LSM9DS1 data read demo");
LSM9DS1();
// Try to initialise and warn if we couldn't detect the chip
if (!LSM9DS1_begin()) {
Serial.println("Oops ... unable to initialize the LSM9DS1. Check your wiring!");
while (1);
}
Serial.println("Found LSM9DS1 9DOF");
setupSensor();
}
void loop()
{
char text[100] = {0};
LSM9DS1_begin();
setupSensor();
delay(1000);
int16_t axhi, ayhi, azhi, mxhi, myhi, mzhi, gxhi, gyhi, gzhi ;
byte f[20], buff[100];
LSM9DS1_read(&axhi, &ayhi, &azhi, &mxhi, &myhi, &mzhi, &gxhi, &gyhi, &gzhi, f); /* ask it to read in the data */
for (int i = 0; i < 18; i++) xprintf("0x%02x ", f[i]);
xprintf("\n");
xprintf("Accel %#06x %#06x %#06x ", axhi & 0xFFFF, ayhi & 0xFFFF, azhi & 0xFFFF);
xprintf("Mag %#06x %#06x %#06x ", mxhi & 0xFFFF, myhi & 0xFFFF, mzhi & 0xFFFF);
xprintf("Gyro %#06x %#06x %#06x\n", gxhi & 0xFFFF, gyhi & 0xFFFF, gzhi & 0xFFFF);
float accelerationx = (((float)((int16_t)(f[1] << 8) | f[0]) * LSM9DS1_ACCEL_MG_LSB_2G) / 1000) * SENSORS_GRAVITY_STANDARD;
float accelerationy = (((float)((int16_t)(f[3] << 8) | f[2]) * LSM9DS1_ACCEL_MG_LSB_2G) / 1000) * SENSORS_GRAVITY_STANDARD;
float accelerationz = (((float)((int16_t)(f[5] << 8) | f[4]) * LSM9DS1_ACCEL_MG_LSB_2G) / 1000) * SENSORS_GRAVITY_STANDARD;
xprintf("Acceleration X: %5.2f m/s^2 Y: %5.2f m/s^2 Z: %5.2f m/s^2 \n", accelerationx, accelerationy, accelerationz);
sprintf(text, "Acceleration X: %5.2f m/s^2 Y: %5.2f m/s^2 Z: %5.2f m/s^2 \n", accelerationx, accelerationy, accelerationz);
//Serial1.write(text);
float magneticx = ((float)((int16_t)(f[7] << 8) | f[6]) * LSM9DS1_MAG_MGAUSS_4GAUSS) / 1000;
float magneticy = ((float)((int16_t)(f[9] << 8) | f[8]) * LSM9DS1_MAG_MGAUSS_4GAUSS) / 1000;
float magneticz = ((float)((int16_t)(f[11] << 8) | f[10]) * LSM9DS1_MAG_MGAUSS_4GAUSS) / 1000;
xprintf("magnetic X: %5.2f m/s^2 Y: %5.2f m/s^2 Z: %5.2f m/s^2 \n", magneticx, magneticy, magneticz);
float gyrox = (float)((int16_t)(f[13] << 8) | f[12]) * LSM9DS1_GYRO_DPS_DIGIT_245DPS;
float gyroy = (float)((int16_t)(f[15] << 8) | f[14]) * LSM9DS1_GYRO_DPS_DIGIT_245DPS;
float gyroz = (float)((int16_t)(f[17] << 8) | f[16]) * LSM9DS1_GYRO_DPS_DIGIT_245DPS;
xprintf("Gyroscope X: %5.2f m/s^2 Y: %5.2f m/s^2 Z: %5.2f m/s^2 \n", gyrox, gyroy, gyroz);
/* Get a new sensor event */
sensors_event_t a, m, g, temp;
LSM9DS1_getEvent(&a, &m, &g, &temp);
xprintf("\n");
}
as I moved the sensor around a run gave
ESP-01 (ESP8266) LSM9DS1 data read demo
initI2C
Found LSM9DS1 9DOF
0x04 0x30 0x9c 0xf2 0x57 0x2f 0x2f 0x0a 0x6f 0xfb 0x59 0x02 0x04 0x16 0x0f 0x0c 0xe5 0x0a
Accel 0x3004 0xf29c 0x2f57 Mag 0x0a2f 0xfb6f 0x0259 Gyro 0x1604 0x0c0f 0x0ae5
Acceleration X: 7.35 m/s^2 Y: -2.05 m/s^2 Z: 7.25 m/s^2
magnetic X: 0.36 m/s^2 Y: -0.16 m/s^2 Z: 0.08 m/s^2
Gyroscope X: 49.31 m/s^2 Y: 27.01 m/s^2 Z: 24.40 m/s^2
0x54 0xe3 0x39 0xfb 0x85 0x4c 0xd3 0xfc 0xbb 0xfa 0xfa 0xfe 0x89 0x18 0x6e 0xa9 0x59 0xfa
Accel 0xe354 0xfb39 0x4c85 Mag 0xfcd3 0xfabb 0xfefa Gyro 0x1889 0xa96e 0xfa59
Acceleration X: -4.39 m/s^2 Y: -0.73 m/s^2 Z: 11.72 m/s^2
magnetic X: -0.11 m/s^2 Y: -0.19 m/s^2 Z: -0.04 m/s^2
Gyroscope X: 54.96 m/s^2 Y: -193.92 m/s^2 Z: -12.66 m/s^2
0xdd 0xe6 0xba 0xdf 0x15 0x47 0xfd 0xff 0x33 0x02 0x99 0xfd 0x57 0x14 0x00 0x2a 0x1c 0x08
Accel 0xe6dd 0xdfba 0x4715 Mag 0xfffd 0x0233 0xfd99 Gyro 0x1457 0x2a00 0x081c
Acceleration X: -3.85 m/s^2 Y: -4.94 m/s^2 Z: 10.89 m/s^2
magnetic X: -0.00 m/s^2 Y: 0.08 m/s^2 Z: -0.09 m/s^2
Gyroscope X: 45.56 m/s^2 Y: 94.08 m/s^2 Z: 18.17 m/s^2
0xfe 0x25 0x49 0xe7 0x8a 0x19 0x65 0x0b 0x2f 0xfe 0x65 0x02 0x64 0xe6 0x1b 0x22 0x48 0x1b
Accel 0x25fe 0xe749 0x198a Mag 0x0b65 0xfe2f 0x0265 Gyro 0xe664 0x221b 0x1b48
Acceleration X: 5.82 m/s^2 Y: -3.78 m/s^2 Z: 3.91 m/s^2
magnetic X: 0.41 m/s^2 Y: -0.07 m/s^2 Z: 0.09 m/s^2
Gyroscope X: -57.37 m/s^2 Y: 76.40 m/s^2 Z: 61.11 m/s^2
0x94 0xf2 0xa0 0x15 0x8d 0x36 0x01 0xff 0xa1 0xf7 0x3d 0x01 0x9c 0x07 0xa9 0xa9 0x4e 0x0d
Accel 0xf294 0x15a0 0x368d Mag 0xff01 0xf7a1 0x013d Gyro 0x079c 0xa9a9 0x0d4e
Acceleration X: -2.06 m/s^2 Y: 3.31 m/s^2 Z: 8.35 m/s^2
magnetic X: -0.04 m/s^2 Y: -0.30 m/s^2 Z: 0.04 m/s^2
Gyroscope X: 17.05 m/s^2 Y: -193.40 m/s^2 Z: 29.80 m/s^2
0xb2 0xca 0xd1 0xec 0x10 0x1f 0x5d 0xf5 0x63 0xfd 0xa6 0x04 0xe2 0x0c 0x3a 0x0e 0x50 0x08
Accel 0xcab2 0xecd1 0x1f10 Mag 0xf55d 0xfd63 0x04a6 Gyro 0x0ce2 0x0e3a 0x0850
Acceleration X: -8.16 m/s^2 Y: -2.94 m/s^2 Z: 4.76 m/s^2
magnetic X: -0.38 m/s^2 Y: -0.09 m/s^2 Z: 0.17 m/s^2
Gyroscope X: 28.86 m/s^2 Y: 31.87 m/s^2 Z: 18.62 m/s^2
0x3e 0x25 0xd9 0xf2 0x76 0x2a 0x47 0x08 0xed 0xfb 0x17 0x00 0x3e 0xf6 0x96 0x3a 0x8b 0x05
Accel 0x253e 0xf2d9 0x2a76 Mag 0x0847 0xfbed 0x0017 Gyro 0xf63e 0x3a96 0x058b
Acceleration X: 5.70 m/s^2 Y: -2.01 m/s^2 Z: 6.50 m/s^2
magnetic X: 0.30 m/s^2 Y: -0.15 m/s^2 Z: 0.00 m/s^2
Gyroscope X: -21.86 m/s^2 Y: 131.23 m/s^2 Z: 12.42 m/s^2
wiring the LSM9DS1 to the ESP-01 using I2C
These are the components I am using. I want to send the accelerometer data to my laptop
Why not simply the project and get a wemos D1 mini?
Thanks, I have a wemos D1 mini but I wanted a smaller component because of where I am going to place it on a tool
do you require the Xiao?
why not connect the ADXL345 directly to the ESP-01 using I2C
then use the WiFi to transmit to the laptop
but Xiao + esp-01 is larger than Wemos mini
Can you help with the pinout or the connection. how do I program because I am not sure the ESP-01 has a microcontroller.
Yes, is larger but I am looking at the width
Every ESP is a microcontroller. It is the same microcontroller as wemos mini, but with fewer pins. It has only 4 GPIO pins. One is RX, another is TX, and there are 2 more GPIO which can be used for SDA, SCL.
what do you think is ecxecuting the code of the program in post #3 reading the LSM9DS1 sensor data and displaying Acceleration etc on the serial monitor
Thnks for the suggestions thus far. Can I disconnect the FDTI after programming using the Arduino IDE and power with a Battery?
try a web search for esp-01 battery you will find some helpful links
I encountered some difficulties when trying to program my ADXL345 breakout board with ESP8266 nodemcu. It gives the error below.
Nodemcu ADXL345
SCL ---------------SCL
SDA ----------------SDA
3v3 ----------------- VIO or VS
GND ------------------ GND
Soft WDT reset
>>>stack>>>
ctx: cont
sp: 3ffffdf0 end: 3fffffc0 offset: 01a0
3fffff90: 3ffee648 3ffe8946 3ffee7a4 4020134c
3fffffa0: 3fffdad0 00000000 3ffee7f8 40203158
3fffffb0: feefeffe feefeffe 3ffe85e0 40100e21
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
When I used the same connection and code for another ADXL345 shown below it worked well
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.