Problem with ADXL345_Sparkfun_Particle.h

its the library example code from particle ide mpu6050 library so it should work without any problem but we couldn't get the data out of particle ide with it own example. which make me wonder if there is any problem in the code or our setting on web ide?

Hi @talhaSiddiquii -

Let me check, give me a minute.

Regards, Friedl.

Hi @talhaSiddiquii @cal39

Ok, with regards to the library in the webIDE;

It is hard to test really as I do not have the module. Have a look at the screen grabs below. Fir make sure to choose this library;

Then choose this example;

Once you click on that example you will have the option to select "USE THIS EXAPLE". It will then open a new sketch with that example and include the libraries and dependancies automatically as far as I know.

From there you will need to add some code if you do not have something like "Putty" to provide serial monitor from the WebIDE. If you are using Workbench of course a serial monitor is available from within VSC. For now I suggest making the edit to include a simple Particle publish to get going. See below:

#ifdef OUTPUT_READABLE_ACCELGYRO
        // display tab-separated accel/gyro x/y/z values
        Serial.print("a/g:\t");
Particle.publish("a/g:\t", PRIVATE);
        Serial.print(ax); Serial.print("\t");
Particle.publish("AX" + String(ax) + " \t", PRIVATE);
        Serial.print(ay); Serial.print("\t");
        Serial.print(az); Serial.print("\t");
        Serial.print(gx); Serial.print("\t");
        Serial.print(gy); Serial.print("\t");
        Serial.println(gz);
    #endif

delay(1000);

If you get results from this, you know it is working and you can finalise the code. This library should also blink a LED connected to pin D&, which is also the onboard LED for Particle devices. Of course you can add an external led or change the pun, but I would to this for now.

Let me know if this does not work. There is another library you can use in GitHub. It is maintained by Adafruit and seem more straight forward.

Hope this helps!
Friedl.

@friedl_1977 that really a great description, I test the code and check if the code works fine and send data to console by publish command cause we dont have any serial command for putty on webide and I just need to see mpu6050 data how it getting the values so from that i can make my further logic according to it. Thanks Again

1 Like

HI @talhaSiddiquii -

It is a pleasure, I hope it works. If you do not have serial monitor, the below is an example of that you will use instead:

// instead of Serial.print(); 
        Serial.print(ax); Serial.print("\t");

// you will use Particle.publish();  The first part "AX" is printing TEXT, and the +String(var); part is the 
// variable you want to print.
       Particle.publish("AX" + String(ax) + " \t", PRIVATE);

Best of luck!
Friedl

1 Like

we found you scan code and i think its working :grinning:
says scanning done and an address0x68

Hi @cal39 -

This is good news. This is indeed the default I2C address for this IC.

Now you can implement the example as per my previous post :slight_smile:

1 Like

thanks for all your help
we tried and we seem to be getting an event in consol
now but we dont see any data and our led is not lighting
here is the code talha sent:

// Once you import this library into an app on the web based IDE, modify the code to look something like the following.
// This code is a heavily modified version of the MPU6050_raw.ino example found elsewhere in this repo.
// This code has been tested against the MPU-9150 breakout board from Sparkfun.

// This #include statement was automatically added by the Particle IDE.
#include "MPU6050.h"

int ledPin = D7;

// MPU variables:
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;

bool ledState = false;
void toggleLed() {
ledState = !ledState;
digitalWrite(ledPin, ledState);
}

void setup() {
pinMode(ledPin, OUTPUT);

Wire.begin();
Serial.begin(9600);

// The following line will wait until you connect to the Spark.io using serial and hit enter. This gives
// you enough time to start capturing the data when you are ready instead of just spewing data to the UART.
//
// So, open a serial connection using something like:
// screen /dev/tty.usbmodem1411 9600
while(!Serial.available()) SPARK_WLAN_Loop();

Serial.println("Initializing I2C devices...");
accelgyro.initialize();

// Cerify the connection:
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");

}

void loop() {
// read raw accel/gyro measurements from device
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
Serial.print("a/g:\t");
Particle.publish("a/g:\t", PRIVATE);
Serial.print(ax); Serial.print("\t");
Particle.publish("AX" + String(ax) + " \t", PRIVATE);
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.println(gz);

toggleLed();

}

i uploaded at 9;41 and tried again at 947
dont see any data in the rt big box

;

did we not understand your previous post :sweat_smile:

oh im confused on libraries i added 6050 buy not wire could that be the problem?
thanks

Hi @cal39 -

The outputs you see there is simply the events of the device starting up. If you manage to install the Example code correctly, and change the serial prints to Particle.publish as per the code I sent you, you should see the AX value being posted in the first column. Same where you saw the results from the I2C scanner

If you do not mind, please click on the share button on the webIDE while in your sketch, then copy and past the link here.

I can then see exactly what your code looks like :slight_smile:

we have the code exactly you given for particle.publish command in place of serial.print the code compile successfully but it not show any data receiving on console. its the problem we facing currently

// This #include statement was automatically added by the Particle IDE.
#include <MPU6050.h>

// Once you import this library into an app on the web based IDE, modify the code to look something like the following.
// This code is a heavily modified version of the MPU6050_raw.ino example found elsewhere in this repo.
// This code has been tested against the MPU-9150 breakout board from Sparkfun.

// This #include statement was automatically added by the Particle IDE.
#include "MPU6050.h"

int ledPin = D7;

// MPU variables:
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;


bool ledState = false;
void toggleLed() {
    ledState = !ledState;
    digitalWrite(ledPin, ledState);
}

void setup() {
    pinMode(ledPin, OUTPUT);

    Wire.begin();
    Serial.begin(9600);

    // The following line will wait until you connect to the Spark.io using serial and hit enter. This gives
    // you enough time to start capturing the data when you are ready instead of just spewing data to the UART.
    //
    // So, open a serial connection using something like:
    // screen /dev/tty.usbmodem1411 9600
    while(!Serial.available()) SPARK_WLAN_Loop();
    
    Serial.println("Initializing I2C devices...");
    accelgyro.initialize();

    // Cerify the connection:
    Serial.println("Testing device connections...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
    
}

void loop() {
    // read raw accel/gyro measurements from device
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    Serial.print("a/g:\t");
Particle.publish("a/g:\t", PRIVATE);
    Serial.print(ax); Serial.print("\t");
Particle.publish("AX" + String(ax) + " \t", PRIVATE);
    Serial.print(ay); Serial.print("\t");
    Serial.print(az); Serial.print("\t");
    Serial.print(gx); Serial.print("\t");
    Serial.print(gy); Serial.print("\t");
    Serial.println(gz);
    
	

    toggleLed();
    
}

Hi -

You need to make sue you re in the app before sharing, else it is empty :slight_smile:

Let me look at your code posted in you next code.

Regards,
Friedl.

Hi @talhaSiddiquii -

If you select to use the example as I showed in my previous post, you should have two includes in the code, see below.

Usually I2C libraries are not needed with Particle devices, but without going through the entire library it is hard to know whether it might be a dependancy of the MPU6050.h library. Also, simply adding the line of code will not help, you need to include it from the library panel on the left if you do not use the example.

It is a little difficult to troubleshoot without having the same sensor on hand, but I cannot see a reason for it not to work should you use the example and add Particle.publish(). It seems your sensor is not initialing meaning it is blocked by the while loop.

Let's debug.... Maybe add this before the while loop():

void setup() {

    Particle.publish("Initialising sensor", PRIVATE);
    delay(500);

    pinMode(ledPin, OUTPUT);

    Wire.begin();
    Serial.begin(9600);

    // The following line will wait until you connect to the Spark.io using serial and hit enter. This gives
    // you enough time to start capturing the data when you are ready instead of just spewing data to the UART.
    //
    // So, open a serial connection using something like:
    // screen /dev/tty.usbmodem1411 9600
    while(!Serial.available()) SPARK_WLAN_Loop();
    
    Serial.println("Initializing I2C devices...");
    accelgyro.initialize();

    // Cerify the connection:
    Serial.println("Testing device connections...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
    
}

Then add this in your loop()

void loop() {

    Particle.publish("Entering Loop", PRIVATE);
    
    // read raw accel/gyro measurements from device
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    Serial.print("a/g:\t");
    Particle.publish("a/g:\t", PRIVATE);
    Serial.print(ax); Serial.print("\t");
    Particle.publish("AX" + String(ax) + " \t", PRIVATE);
    Serial.print(ay); Serial.print("\t");
    Serial.print(az); Serial.print("\t");
    Serial.print(gx); Serial.print("\t");
    Serial.print(gy); Serial.print("\t");
    Serial.println(gz);

    toggleLed();
    
}

Let me know if you see any results.

Regards, Friedl

Do you see the serial output?
Does the LED toggle as expected?

Your publishing rate is too fast. You can only publish once per second otherwise the device gets muted.

I'd remove this line from setup()

It may keep the code flow trapped there till you connect a serial monitor (BTW, SPARK_WLAN_Loop() has been replaced by Particle.process())

And for your loop I'd only produce one publish and add a delay like this

void loop() {
  char msg[128];

  toggleLed();

  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);   // read raw accel/gyro measurements from device
  snprintf(msg, sizeof(msg)
          , "ax: %4d, ay: %4d, az: %4d, "
            "gx: %4d, gy: %4d, gz: %4d"
          , ax, ay, az
          , gx, gy, gz
          );
  Serial.printlnf("a/g: %s", msg);
  Particle.publish("a/g", msg);
  delay(1000);   
}
1 Like

I dont think it blocked by while loop because , the while loop is only testing if the data is receiving from sensor or not which only possible if sensor not connected or the sensor is not power up, if the sensor is power up properly and its i2c wire are connected properly which i double checked too that sensor is connected properly so there is no mean of blocked by while loop.