Acceldemo spitting out random characters

I am trying to do a project with an arduino using an accelerometer. I am completely new to arduino and electronics in general so bare with me.
I am following the tutorial listed below, to try and get my feet wet. However, after wiring the accelerometer up, and installing the libraries, the serial output is not outputting correctly. It will output the correct thing at first, but then start spitting out random characters. (screen shot below)

In the tutorial I am following I wired it using the SPI wiring method. In the tutorial it tells me to comment off the parts of the code that refer to the 12C wiring method. However, there are options to uncomment SPI Software, and SPI Hardware and software (again screenshot below) Am I doing something wrong with the demo code? I can post more screen shots if need be.
Thanks for you help.
PS. remember I am new to this, so please explain like I’m 5 :slight_smile:

OUTPUT

CODE

// Basic demo for accelerometer readings from Adafruit LIS3DH

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>

// Used for software SPI
#define LIS3DH_CLK 13
#define LIS3DH_MISO 12
#define LIS3DH_MOSI 11
// Used for hardware & software SPI
#define LIS3DH_CS 10

// software SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
// hardware SPI
Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
// I2C
//Adafruit_LIS3DH lis = Adafruit_LIS3DH();

void setup(void) {
  Serial.begin(115200);
  while (!Serial) delay(10);     // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("LIS3DH test!");

  if (! lis.begin(0x18)) {   // change this to 0x19 for alternative i2c address
    Serial.println("Couldnt start");
    while (1) yield();
  }
  Serial.println("LIS3DH found!");

  // lis.setRange(LIS3DH_RANGE_4_G);   // 2, 4, 8 or 16 G!

  Serial.print("Range = "); Serial.print(2 << lis.getRange());
  Serial.println("G");

  // lis.setDataRate(LIS3DH_DATARATE_50_HZ);
  Serial.print("Data rate set to: ");
  switch (lis.getDataRate()) {
    case LIS3DH_DATARATE_1_HZ: Serial.println("1 Hz"); break;
    case LIS3DH_DATARATE_10_HZ: Serial.println("10 Hz"); break;
    case LIS3DH_DATARATE_25_HZ: Serial.println("25 Hz"); break;
    case LIS3DH_DATARATE_50_HZ: Serial.println("50 Hz"); break;
    case LIS3DH_DATARATE_100_HZ: Serial.println("100 Hz"); break;
    case LIS3DH_DATARATE_200_HZ: Serial.println("200 Hz"); break;
    case LIS3DH_DATARATE_400_HZ: Serial.println("400 Hz"); break;

    case LIS3DH_DATARATE_POWERDOWN: Serial.println("Powered Down"); break;
    case LIS3DH_DATARATE_LOWPOWER_5KHZ: Serial.println("5 Khz Low Power"); break;
    case LIS3DH_DATARATE_LOWPOWER_1K6HZ: Serial.println("16 Khz Low Power"); break;
  }
}

void loop() {
  lis.read();      // get X Y and Z data at once
  // Then print out the raw data
  Serial.print("X:  "); Serial.print(lis.x);
  Serial.print("  \tY:  "); Serial.print(lis.y);
  Serial.print("  \tZ:  "); Serial.print(lis.z);

  /* Or....get a new sensor event, normalized */
  sensors_event_t event;
  lis.getEvent(&event);

  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print("\t\tX: "); Serial.print(event.acceleration.x);
  Serial.print(" \tY: "); Serial.print(event.acceleration.y);
  Serial.print(" \tZ: "); Serial.print(event.acceleration.z);
  Serial.println(" m/s^2 ");

  Serial.println();

  delay(200);
}

TUTORIAL

Please don’t take a picture of your code. Paste your code between code tags </>.
As this is your first post, please read - “How to use this forum - sticky”.

The junk characters look like baud rate mismatch. I don't understand why you are seeing them mixed in with correct output though. But I didn't read your code, because you posted a picture of code.

The only time you should EVER post a picutre of text is when it's not possible to copy and paste it.

Okay, there's also a place for taking pictueres of text to make fun of something, like error message or blue-screens showing on billboards or point of sale terminals. But not when you're asking for help

DrAzzy:
The junk characters look like baud rate mismatch. I don't understand why you are seeing them mixed in with correct output though. But I didn't read your code, because you posted a picture of code.

The only time you should EVER post a picutre of text is when it's not possible to copy and paste it.

Okay, there's also a place for taking pictueres of text to make fun of something, like error message or blue-screens showing on billboards or point of sale terminals. But not when you're asking for help

Ok, I change the post to include the code. What is baud rate?

I had to repost this, because in my previous post, I didn’t include enough information.

I am trying to do a project with an arduino using an accelerometer. I am completely new to arduino and electronics in general so bare with me.
I am following the tutorial listed below, to try and get my feet wet. However, after wiring the accelerometer up, and installing the libraries, the serial output is not outputting correctly. It will output the correct thing at first, but then start spitting out random characters. (screen shot below)

In the tutorial I am following I wired it using the SPI wiring method. In the tutorial it tells me to comment off the parts of the code that refer to the 12C wiring method. However, there are options to uncomment SPI Software, and SPI Hardware and software (again screenshot below) Am I doing something wrong with the demo code? I can post more screen shots if need be.
Thanks for you help.
PS. remember I am new to this, so please explain like I’m 5 :slight_smile:

OUTPUT

CODE

// Basic demo for accelerometer readings from Adafruit LIS3DH

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>

// Used for software SPI
#define LIS3DH_CLK 13
#define LIS3DH_MISO 12
#define LIS3DH_MOSI 11
// Used for hardware & software SPI
#define LIS3DH_CS 10

// software SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
// hardware SPI
Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
// I2C
//Adafruit_LIS3DH lis = Adafruit_LIS3DH();

void setup(void) {
  Serial.begin(115200);
  while (!Serial) delay(10);     // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("LIS3DH test!");

  if (! lis.begin(0x18)) {   // change this to 0x19 for alternative i2c address
    Serial.println("Couldnt start");
    while (1) yield();
  }
  Serial.println("LIS3DH found!");

  // lis.setRange(LIS3DH_RANGE_4_G);   // 2, 4, 8 or 16 G!

  Serial.print("Range = "); Serial.print(2 << lis.getRange());
  Serial.println("G");

  // lis.setDataRate(LIS3DH_DATARATE_50_HZ);
  Serial.print("Data rate set to: ");
  switch (lis.getDataRate()) {
    case LIS3DH_DATARATE_1_HZ: Serial.println("1 Hz"); break;
    case LIS3DH_DATARATE_10_HZ: Serial.println("10 Hz"); break;
    case LIS3DH_DATARATE_25_HZ: Serial.println("25 Hz"); break;
    case LIS3DH_DATARATE_50_HZ: Serial.println("50 Hz"); break;
    case LIS3DH_DATARATE_100_HZ: Serial.println("100 Hz"); break;
    case LIS3DH_DATARATE_200_HZ: Serial.println("200 Hz"); break;
    case LIS3DH_DATARATE_400_HZ: Serial.println("400 Hz"); break;

    case LIS3DH_DATARATE_POWERDOWN: Serial.println("Powered Down"); break;
    case LIS3DH_DATARATE_LOWPOWER_5KHZ: Serial.println("5 Khz Low Power"); break;
    case LIS3DH_DATARATE_LOWPOWER_1K6HZ: Serial.println("16 Khz Low Power"); break;
  }
}

void loop() {
  lis.read();      // get X Y and Z data at once
  // Then print out the raw data
  Serial.print("X:  "); Serial.print(lis.x);
  Serial.print("  \tY:  "); Serial.print(lis.y);
  Serial.print("  \tZ:  "); Serial.print(lis.z);

  /* Or....get a new sensor event, normalized */
  sensors_event_t event;
  lis.getEvent(&event);

  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print("\t\tX: "); Serial.print(event.acceleration.x);
  Serial.print(" \tY: "); Serial.print(event.acceleration.y);
  Serial.print(" \tZ: "); Serial.print(event.acceleration.z);
  Serial.println(" m/s^2 ");

  Serial.println();

  delay(200);
}

TUTORIAL

I got it to work. The problem was my serial.begin was set to high. I reset seral.begin to 9600 and now it works

@thespankles

TOPIC MERGED.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.

Da hell....

I don't immediately see why that would generate garbage like that...

Does the correct data come in every time, or just the first reading? If just the first reading, does it all come in at once, or do you get a blob of garbage of approximately equal length every 200ms (when it would be printing a reading)? If not every 200ms, is it just one blob of garbage then nothing, or what?

If anyone else with that hardware is here, they might be able to provide more clues.

Answers to those questions provide some hints about what might be going on (each of them implies some general classes of imaginable bugs that might lead to it, and rules out others) - though regardless of what's going on, I'd reckon it's gotta be something going terribly wrong in the adafruit libraries...