Widget ADXL345

Hi, which widget could i use for my adxl345.
It is working on the Arduino Plotter but I dont find the right widget.

11

You’d need to build up the [x,y,z] string

Cayenne.virtualWrite(12, [x,y,z], "accel", "g");

you mean in this position? Which Widget should i use?

//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_OUT(1)
{
//Cayenne.virtualWrite(1, millis());
Cayenne.virtualWrite(12, [x,y,z], “accel”, “g”);
}

 CAYENNE_OUT12)
 {
 Cayenne.virtualWrite(12, [x,y,z], “accel”, “g”);
 }

it will auto create the widget.

do you have the complete code? Because now with this change I get:
xwas not declared in this scope

Here my code:

#define CAYENNE_PRINT Serial
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#include <CayenneMQTTESP32.h>

// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "----";
char password[] = "";
char clientID[] = "----";

unsigned long lastMillis = 0;

/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void displaySensorDetails(void)
{
  sensor_t sensor;
  accel.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" m/s^2");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" m/s^2");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" m/s^2");  
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

void displayDataRate(void)
{
  Serial.print  ("Data Rate:    "); 
  
  switch(accel.getDataRate())
  {
    case ADXL345_DATARATE_3200_HZ:
      Serial.print  ("3200 "); 
      break;
    case ADXL345_DATARATE_1600_HZ:
      Serial.print  ("1600 "); 
      break;
    case ADXL345_DATARATE_800_HZ:
      Serial.print  ("800 "); 
      break;
    case ADXL345_DATARATE_400_HZ:
      Serial.print  ("400 "); 
      break;
    case ADXL345_DATARATE_200_HZ:
      Serial.print  ("200 "); 
      break;
    case ADXL345_DATARATE_100_HZ:
      Serial.print  ("100 "); 
      break;
    case ADXL345_DATARATE_50_HZ:
      Serial.print  ("50 "); 
      break;
    case ADXL345_DATARATE_25_HZ:
      Serial.print  ("25 "); 
      break;
    case ADXL345_DATARATE_12_5_HZ:
      Serial.print  ("12.5 "); 
      break;
    case ADXL345_DATARATE_6_25HZ:
      Serial.print  ("6.25 "); 
      break;
    case ADXL345_DATARATE_3_13_HZ:
      Serial.print  ("3.13 "); 
      break;
    case ADXL345_DATARATE_1_56_HZ:
      Serial.print  ("1.56 "); 
      break;
    case ADXL345_DATARATE_0_78_HZ:
      Serial.print  ("0.78 "); 
      break;
    case ADXL345_DATARATE_0_39_HZ:
      Serial.print  ("0.39 "); 
      break;
    case ADXL345_DATARATE_0_20_HZ:
      Serial.print  ("0.20 "); 
      break;
    case ADXL345_DATARATE_0_10_HZ:
      Serial.print  ("0.10 "); 
      break;
    default:
      Serial.print  ("???? "); 
      break;
  }  
  Serial.println(" Hz");  
}

void displayRange(void)
{
  Serial.print  ("Range:         +/- "); 
  
  switch(accel.getRange())
  {
    case ADXL345_RANGE_16_G:
      Serial.print  ("16 "); 
      break;
    case ADXL345_RANGE_8_G:
      Serial.print  ("8 "); 
      break;
    case ADXL345_RANGE_4_G:
      Serial.print  ("4 "); 
      break;
    case ADXL345_RANGE_2_G:
      Serial.print  ("2 "); 
      break;
    default:
      Serial.print  ("?? "); 
      break;
  }  
  Serial.println(" g");  
}

void setup(void) {
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);


#ifndef ESP32
  while (!Serial); // for Leonardo/Micro/Zero
#endif
  Serial.begin(115200);
  Serial.println("Accelerometer Test"); Serial.println("");
  
  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }

  /* Set the range to whatever is appropriate for your project */
  accel.setRange(ADXL345_RANGE_16_G);
  // displaySetRange(ADXL345_RANGE_8_G);
  // displaySetRange(ADXL345_RANGE_4_G);
  // displaySetRange(ADXL345_RANGE_2_G);
  
  /* Display some basic information on this sensor */
  displaySensorDetails();
  
  /* Display additional settings (outside the scope of sensor_t) */
  displayDataRate();
  displayRange();
  Serial.println("");
}

void loop(void) {
Cayenne.loop();

  //Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
  if (millis() - lastMillis > 100) {
    lastMillis = millis();
    /* Get a new sensor event */ 
    sensors_event_t event; 
    accel.getEvent(&event);
   
    /* Display the results (acceleration is measured in m/s^2) */
    //Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print("  ");
    //Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print("  ");
    //Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print("  ");Serial.println("m/s^2 ");
    //delay(10);
    
    //For telemetry viewer uncomment/comment this
    
    Serial.print(event.acceleration.x);
    Serial.print(", ");
    Serial.print(event.acceleration.y);
    Serial.print(", ");
    Serial.print(event.acceleration.z);
    Serial.println("");
  
  }
}
//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_OUT(1)
{
  Cayenne.virtualWrite(1, millis());
  //Cayenne.virtualWrite(12, [x,y,z], "accel", "g");
  
  
}


CAYENNE_IN(1)
{
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

Store the acceleration value in the variable x, y, z and create the sting.

    float x;
    float y;
    float z;

  buffer[0] = '[';
  size_t offset = 1;
  dtostrf(x, 1, 3, &buffer[offset]);
  offset += strlen(&buffer[offset]);
  buffer[offset++] = ',';
  dtostrf(y, 1, 3, &buffer[offset]);
  offset += strlen(&buffer[offset]);
  buffer[offset++] = ',';
  dtostrf(z, 1, 3, &buffer[offset]);
  offset += strlen(&buffer[offset]);
  buffer[offset++] = ']';
  buffer[offset] = 0;
  Serial.println(buffer);

Cayenne.virtualWrite(12, buffer, “accel”, “g”);

Hi, I get some complex with your code.
How could I link this 3 codes in one function? See the picture attached, there are the 3 values in the Dashboard but i need in one graph15

Cayenne.virtualWrite(1, event.acceleration.x);
Cayenne.virtualWrite(2, event.acceleration.y);
Cayenne.virtualWrite(3, event.acceleration.z);

the above code which i gave does the thing. it creates a single widget with all three values.

11%20PM

This is the last part of the code with your support but i become some error codes. Sure i have to delete some codes but i´m not sure

//Cayenne.virtualWrite(1, event.acceleration.x);
//Cayenne.virtualWrite(2, event.acceleration.y);
//Cayenne.virtualWrite(3, event.acceleration.z);

}
}
//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_OUT(12)
{

buffer[0] = ‘[’;
size_t offset = 1;
dtostrf(x, 1, 3, &buffer[offset]);
offset += strlen(&buffer[offset]);
buffer[offset++] = ‘,’;
dtostrf(y, 1, 3, &buffer[offset]);
offset += strlen(&buffer[offset]);
buffer[offset++] = ‘,’;
dtostrf(z, 1, 3, &buffer[offset]);
offset += strlen(&buffer[offset]);
buffer[offset++] = ‘]’;
buffer[offset] = 0;
Serial.println(buffer);

//Cayenne.virtualWrite(1, millis());
Cayenne.virtualWrite(12, buffer, “accel”, “g”);

}

CAYENNE_IN(12)
{
CAYENNE_LOG(“CAYENNE_IN_DEFAULT(%u) - %s, %s”, request.channel, getValue.getId(), getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}

you can delete the entire CAYENNE_IN(12) function

Do it, but i get the error: stray \342in program, see picture

you can delete the entire CAYENNE_IN(12) function

Hi, i have delete the entire CAYENNE_IN(12) function as you can see in the picture above without result. I get the fault stray \342 in program

delete the (double quotes)" from "accel" and "g" and retype them.