[Solved] analogRead fluctuating?

Hi,
I have four ADXL335 Module 3-Axis Analog Output Accelerometer.
I also have an Arduino UNO and the sparkcore.
The x,y and z outputs on the ADXL335 are connected to A0-A2 on UNO and sparkcore. The Vin On ADXL335 is connected to the 3.3v on both boards, the GND is also connected.
The following code runs fine and gives accurate output on the UNO, but when I run the same code on the sparkcore, the output is wacky.

Here is the code (source: http://bildr.org/2011/04/sensing-orientation-with-the-adxl335-arduino/):

//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code for the ADXL335, prints calculated orientation via serial
//////////////////////////////////////////////////////////////////


//Analog read pins
const int xPin = A0;
const int yPin = A1;
const int zPin = A2;

//The minimum and maximum values that came from
//the accelerometer while standing still
//You very well may need to change these
int minVal = 265;
int maxVal = 402;


//to hold the caculated values
double x;
double y;
double z;


void setup(){
  Serial.begin(9600); 
}


void loop(){

  //read the analog values from the accelerometer
  int xRead = analogRead(xPin);
  int yRead = analogRead(yPin);
  int zRead = analogRead(zPin);

  //convert read values to degrees -90 to 90 - Needed for atan2
  int xAng = map(xRead, minVal, maxVal, -90, 90);
  int yAng = map(yRead, minVal, maxVal, -90, 90);
  int zAng = map(zRead, minVal, maxVal, -90, 90);

  //Caculate 360deg values like so: atan2(-yAng, -zAng)
  //atan2 outputs the value of -π to π (radians)
  //We are then converting the radians to degrees
  x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
  y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI);
  z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);

  //Output the caculations
   Serial.print("x(");
  Serial.print(xRead);
  Serial.print("): ");
  Serial.print(x);
  
  Serial.print(" y(");
  Serial.print(yRead);
  Serial.print("): ");
  Serial.print(y);
  
  Serial.print(" z(");
  Serial.print(zRead);
  Serial.print("): ");
  Serial.println(z);

  delay(3000);//just here to slow down the serial output - Easier to read
}

Note that both ADXL335 are taped to my desk so they don’t move.
here is the output from arduino:
x(326): 189.87 y(325): 188.25 z(281): 230.19
x(326): 189.59 y(325): 188.02 z(280): 230.19
x(326): 189.59 y(325): 188.02 z(280): 230.19
x(326): 189.87 y(325): 188.25 z(281): 230.19
x(326): 189.87 y(325): 188.25 z(281): 230.19
x(326): 189.87 y(325): 188.25 z(281): 230.19
x(326): 189.87 y(325): 188.25 z(281): 230.19

And here is the output from sparkcore ((Notice how the values are fluctuating):
x(440.00): 45.44 y(435.00): 47.53 z(433.00): 42.91
x(419.00): 49.90 y(425.00): 47.29 z(415.00): 47.63
x(420.00): 51.71 y(425.00): 49.67 z(412.00): 47.08
x(441.00): 35.87 y(414.00): 47.92 z(433.00): 33.14
x(440.00): 31.22 y(406.00): 47.09 z(434.00): 29.40
x(439.00): 45.00 y(439.00): 45.00 z(439.00): 45.00
x(439.00): 34.09 y(411.00): 47.12 z(433.00): 32.15
x(439.00): 33.69 y(411.00): 46.68 z(434.00): 32.15
x(439.00): 31.36 y(405.00): 47.56 z(432.00): 29.12
x(441.00): 43.18 y(429.00): 47.92 z(433.00): 40.27
x(441.00): 47.12 y(439.00): 47.92 z(433.00): 44.19

FYI, I switch the ADXL335 and still same results.
I added 0.1 MF cap for each A0-A2 to ground and that did not help eaither.
Does anyone know why the readings are so different and why the values are fluctuating?
Could someone point me to the correct direction how to fix this please?

thanks,
/N

Hi @NaAl

I don’t see anywhere where you correct for the fact that the Arduino ADC is 10-bit but the Spark ADC is 12-bit. You can divide by 4 on Spark (throwing away some precision) to make them the same.

Just one other thing–you say: [quote=“NaAl, post:1, topic:3331”]
The Vin On ADXL335 is connected to the 3.3v on both boards, the GND is also connected.
[/quote]

I would not try to connect the 3.3V supplies on the two boards together. GND is OK. Maybe you meant that you connect them to one or other depending what you are doing, which is OK too.

[EDIT]

One other thing–there was bug that was recently fixed when using more than ADC channel. That bug is fixed if you build locally but I am not sure if it rolled out for compiling on the webIDE yet.

bko,
Sorry for the confusion, UNO and spakcore are not connected to getter in anyway, I meant to say (as you mentioned) I am using 3.3 v pins on UNO/spark to power the ADXL335 :slight_smile:

Thanks for pointing it out, I divided the outputs by four, but still the reading is fluctuating (the ADXL335 are taped to the desk so they don’t move).
I am expecting the values not to be the same .

x(511.25): 233.68 y(396.25): 212.85 z(454.00): 244.61
x(462.75): 224.60 y(435.75): 219.93 z(432.25): 229.68
x(501.25): 236.65 y(417.00): 221.22 z(485.75): 240.04
x(512.00): 236.24 y(417.50): 217.91 z(483.50): 242.51
x(470.75): 226.19 y(442.75): 221.10 z(449.75): 230.08
x(511.25): 236.17 y(419.75): 218.39 z(484.00): 242.03
x(510.75): 236.11 y(418.75): 218.45 z(483.50): 241.93
x(511.25): 236.51 y(415.00): 218.18 z(483.50): 242.52
Thanks,
/N

I changed the code on arduino to write the read values from ADXL335, back to the sparkcore, i.e arduino reads the x,y and z from the ADXL335 and writes it (analogWrite) to A3-A5 that are connected to sparkcore A0-A2.
here is the output from Arduino (every 3 sec)
x(325): 188.25 y(326): 189.87 z(281): 219.81
x(325): 188.25 y(326): 189.87 z(281): 219.81
x(325): 188.25 y(326): 189.87 z(281): 219.81
x(325): 188.25 y(326): 189.87 z(281): 219.81
x(325): 188.25 y(326): 189.87 z(281): 219.81
x(325): 187.43 y(327): 189.87 z(281): 216.87
x(325): 187.43 y(327): 189.87 z(281): 216.87
x(325): 188.25 y(326): 189.87 z(281): 219.81
x(325): 188.25 y(326): 189.87 z(281): 219.81

and the output from sparkcore:

x(524.50): 235.33 y(407.75): 212.28 z(471.25): 246.40
x(520.25): 239.78 y(395.00): 216.51 z(487.00): 246.67
x(517.25): 224.67 y(441.75): 209.07 z(439.50): 240.65
x(521.50): 238.60 y(400.50): 215.58 z(484.50): 246.41
x(517.00): 238.88 y(401.00): 217.16 z(486.25): 245.41
x(518.00): 237.25 y(414.00): 216.87 z(486.25): 244.25
x(520.25): 239.00 y(395.50): 215.66 z(483.50): 246.67
x(518.50): 237.71 y(397.00): 215.12 z(477.50): 246.04
x(477.25): 219.67 y(441.75): 213.27 z(405.25): 231.65

anyone knows what is going on?

@NaAl – This sort of thing is most often caused by noise on the ADC reference voltage input – or VDDA (STM32 pin 9) in the case of the 'core.

EDIT (for Google hits later on, since I missed this, before I started rambling on … D’oh!):
See @bko’s post below, where he points out that VDDA is in fact exposed on the pin marked, “3V3*”. You should use this pin to power external devices with analogue feedback, rather than the one simply labelled, “3V3”.


Looking at the Spark Core’s schematic, we see that it does have the recommended type of power rail filtering for VDDA …

Another possibility is power rail noise feeding the ADXL335, compared to the UNO. The Spark core runs on 3.3V, whereas the UNO actually runs on 5V and has a 3.3V regulator. Therefore, the Spark Core is more likely to incur digital noise on its 3.3V rail, than is the UNO. (EDIT: Which is why you need to use the VDDA/3V3* output.)

In either case, all I can suggest is that you try putting another capacitor across the 3V3/GND junction at both the 'core and the ADXL335 power input junctions, each in turn to see what helps. A 1uF tantalum might be best. But even a 100nF (0.1uF) ceramic should help.

Failing that, try also a 5.6 ohm or 10 ohm resistor in series with the supply rail feeding the ADXL335. This will significantly increase the filtering effect of the added decoupling cap – so long as it does not limit the current too much for the device (unlikely). Another ferrite bead in the supply feed (instead of or as well as) the resistor could be even better. This is because the 3V3 pins on the Spark Core board are both tied directly to the digital power rail – with no RF noise filtering. So they will have some digital noise on them.

Yet another option would be to use a separate outboard 3.3V regulator to feed your ADXL335. This would give it similar benefits to those delivered by the UNO’s separate 3.3V regulator. Be sure to install decoupling caps on the input and output of that regulator, in the usual fashion. A ferrite bead on its output, close to the ADXL335 wouldn’t hurt, but should not be required – save when the WiFi module is transmitting, possibly.

The UNO also possesses a separate AREF input pin, which I presume you have tie to the 3.3V regulated output. In my circuits, doing that results in much better ADC stability, compared to using the 5V rail, which is quite noisy. Unfortunately, there is no direct equivalent option available on the Spark Core, since the main MCU runs directly on 3.3V, VDDA pin is not broken out (data sheet says it must be tied to VCC anyway) and AFAIK, the STM32 chip does not have a separate AREF input. However, the internal filtering, as shown above, ought to have been sufficient.

Hope that helps in some way.

Gruvin

Disclaimer: I’m a Spark Core end user – not staff – and I have not yet experimented with ADC inputs on my Spark Cores.

You are in luck I have two of these old 5DOF boards from Sparkfun with ADXL335’s on them

http://www.imgur.com/fXbgIgF

So give me a bit to play with this and see what it’s doing. BTW, are you compiling with the Sparkulator or locally? If locally, what branch/commit are you using? I’m basically going to try the Web and latest local.

HI @NaAl and @BDub

I just checked the branch used for the webIDE compiler and it is a little behind the most recent ADC changes but not a lot. It does not have the bug where channels were being mixed but it does have the bug where a one-out-of-twenty samples from the ADC is zero and so the average of the values that you get from analogRead is slightly off. If you can compile locally, that problem is fixed in the current master branch.

Here a link to the pic with the power pins–you want to use 3.3V* OUT for the ADXL335. Spark can be electrically noisy if you are using the Wifi radio a lot.

http://docs.spark.io/images/core-power1.jpg

I am sure @BDub will track it down. I have some of those accelerometers (the guys that design them are local here in Boston) but they are buried.

Ok first results of local build with latest master look good and stable. I’m only using 0.01uF caps on each input. If I pull out the caps, the inputs don’t fluctuate much more than they do with the caps so I’d say the impedances are matched pretty well.

x(2001): 358.60 y(1993): 360.00 z(2365): 270.00
x(2004): 358.60 y(1994): 360.00 z(2368): 270.00
x(2001): 358.60 y(1994): 360.00 z(2366): 270.00
x(2000): 358.60 y(1994): 360.00 z(2366): 270.00
x(2002): 358.60 y(1994): 360.00 z(2366): 270.00
x(2001): 358.60 y(1994): 360.00 z(2367): 270.00
x(2004): 358.60 y(1995): 360.00 z(2367): 270.00
x(2002): 358.60 y(1994): 360.00 z(2367): 270.00
x(2001): 358.60 y(1993): 360.00 z(2365): 270.00
x(2002): 358.60 y(1993): 360.00 z(2366): 270.00
x(2000): 358.60 y(1993): 360.00 z(2366): 270.00
x(2004): 358.60 y(1995): 360.00 z(2365): 270.00
x(2001): 358.60 y(1994): 360.00 z(2366): 270.00
x(2001): 358.60 y(1993): 360.00 z(2365): 270.00
x(2001): 358.62 y(1994): 360.00 z(2369): 270.00
x(2001): 358.59 y(1993): 360.00 z(2364): 270.00
x(2004): 359.30 y(1996): 360.00 z(2366): 270.00
x(2001): 358.60 y(1994): 360.00 z(2366): 270.00
x(2001): 358.60 y(1992): 360.00 z(2365): 270.00
x(2002): 358.60 y(1995): 360.00 z(2365): 270.00
x(2001): 358.60 y(1994): 360.00 z(2365): 270.00
x(2004): 359.30 y(1996): 360.00 z(2365): 270.00
x(2001): 358.60 y(1994): 360.00 z(2365): 270.00
x(2001): 358.60 y(1994): 360.00 z(2366): 270.00
x(2004): 358.60 y(1995): 360.00 z(2367): 270.00
x(2000): 358.60 y(1994): 360.00 z(2365): 270.00
x(2004): 358.60 y(1994): 360.00 z(2366): 270.00
x(2002): 358.60 y(1992): 360.00 z(2366): 270.00
x(2000): 358.60 y(1993): 360.00 z(2366): 270.00
x(2003): 358.60 y(1995): 360.00 z(2366): 270.00
x(2001): 358.60 y(1994): 360.00 z(2366): 270.00
x(2003): 358.60 y(1995): 360.00 z(2366): 270.00
x(2002): 358.60 y(1993): 360.00 z(2365): 270.00
x(2000): 358.59 y(1993): 360.00 z(2364): 270.00
x(2004): 358.60 y(1994): 360.00 z(2367): 270.00
x(2003): 358.59 y(1993): 360.00 z(2364): 270.00
x(2003): 358.60 y(1994): 360.00 z(2366): 270.00
x(2002): 358.60 y(1993): 360.00 z(2366): 270.00
x(2001): 358.60 y(1992): 360.00 z(2367): 270.00
x(2002): 359.30 y(1996): 360.00 z(2365): 270.00
x(2001): 358.60 y(1994): 360.00 z(2366): 270.00
x(2003): 358.60 y(1994): 360.00 z(2366): 270.00
x(2002): 358.60 y(1995): 360.00 z(2367): 270.00
x(2002): 358.60 y(1993): 360.00 z(2365): 270.00
x(2004): 358.60 y(1995): 360.00 z(2368): 270.00
x(2002): 358.60 y(1994): 360.00 z(2366): 270.00
x(2002): 358.60 y(1995): 360.00 z(2367): 270.00
x(2002): 358.60 y(1994): 360.00 z(2365): 270.00
x(2001): 358.60 y(1994): 360.00 z(2366): 270.00

First thing I’m noticing is you need to set your min/max values correctly, but then also your A/D readings are all very very low.

int minVal = 1600;
int maxVal = 2400;

I’ll try the Sparkulator next… brb

Web IDE is pumping out complete garbage for the most part with the A/D. It can have stable times, but those readings are way off, and that’s even with the caps in circuit.

x(2403): 344.48 y(1959): 68.20 z(2161): 353.66
x(2403): 358.41 y(1999): 68.20 z(2161): 359.36
x(2403): 332.18 y(1918): 68.20 z(2161): 348.08
x(2402): 332.18 y(1918): 68.20 z(2160): 348.08
x(2402): 332.18 y(1917): 68.20 z(2160): 348.08
x(2403): 344.48 y(1959): 68.20 z(2161): 353.66
x(2403): 360.00 y(2000): 68.20 z(2161): 360.00
x(2402): 332.18 y(1918): 68.20 z(2161): 348.08
x(2401): 332.18 y(1919): 68.20 z(2161): 348.08
x(2396): 342.55 y(1954): 68.53 z(2156): 352.95
x(2402): 358.41 y(1999): 68.20 z(2161): 359.36
x(2402): 322.13 y(1877): 68.20 z(2161): 342.72
x(2403): 344.48 y(1958): 68.20 z(2161): 353.66
x(2404): 332.18 y(1918): 68.20 z(2162): 348.08
x(2400): 344.05 y(1957): 68.75 z(2159): 353.66
x(2402): 332.18 y(1919): 68.20 z(2161): 348.08
x(2403): 332.18 y(1918): 68.20 z(2161): 348.08
x(2401): 358.41 y(1998): 68.20 z(2160): 359.36
x(2403): 322.13 y(1878): 68.20 z(2161): 342.72
x(2402): 322.13 y(1877): 68.20 z(2161): 342.72
x(2404): 322.13 y(1879): 68.20 z(2163): 342.72
x(2402): 332.18 y(1917): 68.20 z(2160): 348.08
x(2402): 344.48 y(1958): 68.20 z(2161): 353.66
x(2403): 322.13 y(1878): 68.20 z(2162): 342.72
x(2401): 322.13 y(1876): 68.20 z(2160): 342.72
x(2404): 333.43 y(1920): 68.20 z(2162): 348.69
x(2402): 314.22 y(1836): 68.20 z(2161): 337.65
x(2401): 314.22 y(1836): 68.20 z(2160): 337.65
x(2401): 314.22 y(1837): 68.20 z(2160): 337.65
x(2402): 314.22 y(1837): 68.20 z(2161): 337.65
x(2402): 314.22 y(1838): 68.20 z(2161): 337.65
x(2401): 308.05 y(1796): 68.20 z(2160): 332.93
x(2401): 308.05 y(1796): 68.20 z(2160): 332.93
x(2404): 308.05 y(1796): 68.20 z(2162): 332.93
x(2263): 84.29 y(2181): 86.12 z(2021): 34.14
x(2261): 97.13 y(2180): 94.93 z(1979): 34.59
x(2261): 72.00 y(2179): 77.37 z(2060): 34.59
x(2403): 14.04 y(2041): 68.20 z(2161): 5.71
x(2261): 97.13 y(2180): 94.93 z(1978): 34.59
x(2402): 14.04 y(2040): 68.20 z(2160): 5.71
x(2402): 12.53 y(2039): 68.20 z(2161): 5.08
x(2262): 84.29 y(2180): 86.05 z(2020): 34.59
x(2405): 14.04 y(2041): 68.42 z(2162): 5.65
x(2401): 12.53 y(2039): 68.20 z(2160): 5.08
x(2404): 358.41 y(1999): 68.20 z(2161): 359.36
x(2402): 12.53 y(2039): 68.20 z(2161): 5.08
x(2401): 358.41 y(1998): 68.20 z(2160): 359.36
x(2262): 84.29 y(2181): 86.05 z(2020): 34.59
x(2402): 358.41 y(1998): 68.20 z(2160): 359.36
x(2263): 84.29 y(2181): 86.12 z(2020): 34.14
x(2261): 84.29 y(2180): 86.05 z(2019): 34.59
x(2401): 358.36 y(1998): 68.75 z(2159): 359.36
x(2383): 72.00 y(2182): 81.40 z(2062): 24.94
x(2402): 358.41 y(1998): 68.20 z(2161): 359.36
x(2260): 72.00 y(2179): 77.37 z(2059): 34.59
x(2404): 360.00 y(2000): 68.20 z(2162): 360.00
x(2261): 84.29 y(2179): 86.05 z(2019): 34.59
x(2402): 14.04 y(2040): 68.20 z(2161): 5.71
x(2400): 358.36 y(1998): 68.75 z(2159): 359.36
x(2401): 358.36 y(1998): 68.75 z(2159): 359.36
x(2403): 358.41 y(1999): 68.20 z(2161): 359.36
x(2401): 344.48 y(1958): 68.20 z(2160): 353.66
x(2404): 14.04 y(2041): 68.20 z(2162): 5.71
x(2401): 344.48 y(1958): 68.20 z(2160): 353.66
x(2403): 14.04 y(2040): 68.20 z(2160): 5.71
x(2403): 344.48 y(1959): 68.20 z(2161): 353.66
x(2403): 14.04 y(2040): 68.20 z(2161): 5.71
x(2384): 72.00 y(2182): 81.40 z(2062): 24.94
x(2401): 344.48 y(1958): 68.20 z(2160): 353.66
x(2402): 344.48 y(1958): 68.20 z(2160): 353.66
x(2401): 358.41 y(1999): 68.20 z(2160): 359.36
x(2402): 344.48 y(1957): 68.20 z(2160): 353.66
x(2404): 36.87 y(2120): 68.20 z(2162): 16.70
x(2382): 72.00 y(2180): 81.30 z(2060): 25.20
x(2403): 344.48 y(1958): 68.20 z(2161): 353.66
x(2402): 14.04 y(2040): 68.20 z(2160): 5.71
x(2401): 344.48 y(1957): 68.20 z(2160): 353.66

So I’d say if you are using the Web IDE that’s most of your problem right now. Maybe we can get the ADC patched up sooner than later over there.

EDIT: Looking at my data here more closely, I’m seeing some strange artifacts of the map() function. My limits are set to 1600 and 2400. Notice what’s happening when it goes just above 2400… the output is wrapping around, probably due to the signed numbers? Hmm… some more testing is needed. But the ADC values are still wrong regardless.

Thank you all. you are AWESOME. :smile:
B​Dub, yes I am using WebIDE, that must be it.
I am going to dig around and find out how to setup my local development environment.
Thanks again for your advice and help.
Thanks,
/N

1 Like

@BDub @bko Next Birthday, I am buying you both capes!

3 Likes

Ha! Now why/how did I not see/read/know that? Thank you! :smiley:

Hey I am having trouble to set it up in the WEB IDE can you provide me with the code that demonstrate it. Thanks Meth

Hi @Meth

I am not sure what exactly you need here.

This is a very old thread about some problems with ADC setup back in March and those problems have been fixed for a long time now.

Hi Bko,
The issue I have with mine is that when I run it from the WEB IDE nothing seems to happen. I think is due to the fact that I am not using GET /v1/devices/{DEVICE_ID}/{VARIABLE} and Spark variable.
Here is how my code is so far taken from http://wiring.org.co/learning/basics/accelerometer.html and the one up, any help is appreciated thanks Meth

//Analog read pins
const int xPin =AO;
const int yPin =A1;
const int zPin =A2;

void setup()
{
  Serial.begin(9600);      // sets the serial port to 9600
}

void loop()
{

 // //read the analog values from the accelerometer
    int xRead = analogRead(xPin);
    int yRead = analogRead(yPin);
    int zRead = analogRead(zPin);
    
    //output the 
    serial.print ("accelerations are x,y,z")
    Serial.print("x(");
    Serial.print(xRead);
    Serial.print("): ");
    Serial.print(x);

    Serial.print(" y(");
    Serial.print(yRead);
    Serial.print("): ");
    Serial.print(y);
    
    Serial.print(" z(");
    Serial.print(zRead);
    Serial.print("): ");
    Serial.println(z);
    
    delay(3000);//just here to slow down the serial output - Easier to read

So this code print out values to the USB serial port. Are you running a terminal emulator on the host your core is plugged into? Is it a PC? If so there is a different way you might need to start up, making the core wait for you to type a character in setup.

See this part of the docs for the setup() you need:

http://docs.spark.io/firmware/#communication-serial

Hey @Meth just chiming in here with some assistance.

When you flash that code to your Core does your RGB LED blink Magenta?

The code you posted will run but you won’t notice it until you open your Serial terminal.

Try this to give you an idea if the code you just flashed is actually running… it should blink the onboard blue LED as well:

Also just noticed the first line had a typo, was not A0 (zero) but AO (letter O)

#include "application.h"

//Analog read pins
#define xPin A0
#define yPin A1
#define zPin A2

void setup()
{
  Serial.begin(9600);      // sets the serial port to 9600
  pinMode(D7,OUTPUT);

  Serial.println("accelerations are x,y,z");
}

void loop()
{
    digitalWrite(D7, !digitalRead(D7));  // toggle blue LED

 // //read the analog values from the accelerometer
    int xRead = analogRead(xPin);
    int yRead = analogRead(yPin);
    int zRead = analogRead(zPin);

    Serial.print("x:");
    Serial.print(xRead);
    Serial.print("\t");

    Serial.print(" y:");
    Serial.print(yRead);
    Serial.print("\t");

    Serial.print(" z:");
    Serial.println(zRead);

    delay(3000);//just here to slow down the serial output - Easier to read
}

Hi Thanks for the reply, When I verify the code you just wrote I get an error this is the error.

In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from accelerometertest.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"`indent preformatted text by 4 spaces`
^
accelerometertest.cpp: In function 'void loop()':
accelerometertest.cpp:22:5: error: 'serial' was not declared in this scope
int xRead = analogRead(xPin);
^
accelerometertest.cpp:23:5: error: expected ';' before 'Serial'
int yRead = analogRead(yPin);
^
accelerometertest.cpp:26:18: error: 'x' was not declared in this scope
//output the
^
accelerometertest.cpp:31:18: error: 'y' was not declared in this scope
Serial.print(x);
^
accelerometertest.cpp:36:20: error: 'z' was not declared in this scope
Serial.print(y);
^

make: *** [accelerometertest.o] Error 1
Error: Could not compile. Please review your code.

Just a typo--this should be

Serial.print ("accelerations are x,y,z");

Does that help

Yes I had to remove the Serial.print(x);Serial.print(y);Serial.print(z); in the output… I hadn’t declared them.
Thanks