Arduino hangs forever halfway through setup()

I'm trying to get the LSM9DS0 gyro/accelerometer/magnetometer to work with my Arduino. I'm using the example included in the library from the adafruit website on the gyro. About halfway through setup, the whole thing just freezes and nothing progresses.
This is the example sketch:

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

Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();



void setupSensor()
{
  // 1.) Set the accelerometer range
  lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);

  // 2.) Set the magnetometer sensitivity
  lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);
 

  // 3.) Setup the gyroscope
  lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);
  

void setup() 
{
  
  Serial.begin(9600);
  Serial.println("LSM raw read demo");
  
  // Try to initialise and warn if we couldn't detect the chip
  if (!lsm.begin())
  {
    Serial.println("Oops ... unable to initialize the LSM9DS0. Check your wiring!");
    while (1);
  }
  Serial.println("Found LSM9DS0 9DOF");
  Serial.println("");
  Serial.println("");
}

void loop() 
{
  lsm.read();

  Serial.print("Accel X: "); Serial.print((int)lsm.accelData.x); Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.accelData.y);       Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.accelData.z);     Serial.print(" ");
  Serial.print("Mag X: "); Serial.print((int)lsm.magData.x);     Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.magData.y);         Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.magData.z);       Serial.print(" ");
  Serial.print("Gyro X: "); Serial.print((int)lsm.gyroData.x);   Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.gyroData.y);        Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.gyroData.z);      Serial.println(" ");
  Serial.print("Temp: "); Serial.print((int)lsm.temperature);    Serial.println(" ");
  delay(200);
}

This is the simplified version:

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Sensor.h>  // not used in this demo but required!

// i2c
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();


void setupSensor()
{
  // 1.) Set the accelerometer range
  lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);
 
  // 2.) Set the magnetometer sensitivity
  lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);
 
  // 3.) Setup the gyroscope
  lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);
}  

void setup() 
{
  
  Serial.begin(9600);
  Serial.println("LSM raw read demo");
  
  if (!lsm.begin())
  {
    Serial.println("Oops ... unable to initialize the LSM9DS0. Check your wiring!");
    while (1);
  }
  Serial.println("Found LSM9DS0 9DOF");
  Serial.println("");
  Serial.println("");
}

void loop() 
{
  lsm.read();

  Serial.print("Accel X: "); Serial.print((int)lsm.accelData.x); Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.accelData.y);       Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.accelData.z);     Serial.print(" ");
  Serial.print("Mag X: "); Serial.print((int)lsm.magData.x);     Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.magData.y);         Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.magData.z);       Serial.print(" ");
  Serial.print("Gyro X: "); Serial.print((int)lsm.gyroData.x);   Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.gyroData.y);        Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.gyroData.z);      Serial.println(" ");
  Serial.print("Temp: "); Serial.print((int)lsm.temperature);    Serial.println(" ");
  delay(200);
}

In the Serial monitor, both of them just stop working after "LSM raw read demo".

What happens if you take out (or just comment out) this line:

while (1);

Which is in the setup routine.

Taking out while(1) doesn't change anything. It still hangs.

How is it wired up? Do you have pull-up resistors? Try running the I2C address detector sketch:

Here are some pictures of how I have it wired up (using the Arduino Uno):

Red wire is VIN ==> 5V
Blue Wire is GND ==> GND
Green Wire is SDA ==> A4
Yellow Wire is SCL ==>A5

Picture of the whole thing: Imgur: The magic of the Internet

Picture of the Arduino's wiring: Imgur: The magic of the Internet

Picture of the LSM9DS0's wiring: Imgur: The magic of the Internet

No pull-up resistors, and as far as I'm aware, I have it wired up correctly.

When I ran the i2c detector sketch, the serial monitor gave me the line ÒZÒZÿ¤ˆÿ
Then I changed Serial.begin(115200); to Serial.begin(9600); and it gave me the output:

I2C scanner. Scanning ...
Done.
Found 0 device(s).

It may be an optical illusion, but it appears the blue wire is connected to the GND pin on the Arduino and the 3.3v pin on the LSM9. Can you verify that? On the LSM9, the GND pin is next to the yellow wire, not the red one.

You can attach images to replies you know.

Found 0 device(s).

Until it is reported here, don't bother trying to debug your sketch.

Assuming what SurferTim spotted is an optical illusion, I can't see anything obviously wrong.

Are those pins soldered to the LSM9DS0? They seem to stick up a bit.

Can you take another photo of the LSM9DS0 board? From the side? It looks a bit odd.

Tim - I think that is an optical illusion, yes. Here is a clearer picture of the LSM9DS0:

Nick - Here are two more pictures from both sides:

Edit: It looks like the images won't load for some reason. Here's a link to the album:

I don't understand how you have the pins wired to the board. Compare to this board of mine (not the same board):

The pins go downwards, not up, and the solder is at the top, where the pins are soldered to the board.

Can you photograph your board alone (not stuck into the breadboard), like, sitting on a desk?

I guess I do have it wired up pretty weirdly, I don't see why it wouldn't work though.

Imgur
Imgur

Sorry that I can't seem to figure out how to embed images correctly...

Did you click on "Attachments and other options" to expand it and then browse for your images? If so, what happened? If not, why not?

I don't see why it wouldn't work though.

Well, I can.

Your "wiring":

You can't just push them together. You have to solder them, with the longer pins going downwards so they make contact with the metal inside the breadboard.

Demonstrating with a spare board I have lying around ...

Line up with the short pins ready to insert into the board:

Insert, and then solder along the top (each pin individually):

The finished result would look like my earlier photo, with a nice blob of solder on the top of each pin, flowing around it.

Ah ok, I think I got it this time. So, is there any explanation for what is happening? Am I experiencing some kind of software glitch with the arduino?
Edit: Ah, I didn't see that you posted again. I'll try my hand at soldering and get back to you. But, if the metal parts are all in contact with each other, why would it matter if they're soldered?

Am I experiencing some kind of software glitch with the arduino?

Hardly. You are experiencing bad contacts made by not soldering. Just pushing wires together (where they may have films of oxidation on them) is not going to give you a good joint.

A pity you chose to ignore my earlier question. It might have saved both of us quite a bit of time mucking around with the camera.

You turned out to be completely correct and I wish I could shake your hand and thank you in person. Everything worked perfectly after some soldering.

Apologies for ignoring your question, I assure you it wasn't intentional. I didn't realize what you meant and didn't know what I was doing. It would indeed have saved us quite a lot of time.

I feel a little bad for asking you even more questions after this whole ordeal, but would you happen to know anything about getting meaningful values from the board?

Temp: 34 
Accel X: -2040 Y: -103 Z: 16931
 Mag X: -2856 Y: -2107 Z: -32768
 Gyro X: -123 Y: -141 Z: -382

That's what I'm getting from the board currently, and even when it's just sitting still, there's a huge amount of variance every 200 ms. The Gyro values seem to climb and fall by up to 40 (degrees?) every time, the Accelerometer returns a value around 2000 and varies by up to 150, and the Magnetometer seems to have a similar issue to the Accelerometer.

I realize this doesn't have much to do with my original post, and I understand if you're fed up with me at this point! But I'd still like to thank you for all your help.

Just confirm what code is producing those results. You posted a couple of versions before. I don't have that board, so I will be guessing a bit about what the problem is.

Also can you please post more data? Like, 10 or 20 readings? So we can see if it is just random, or varying by smallish amounts.

Sure, here's the first few (the board was laying flat on a table and wasn't being moved):

emp: 34 
Accel X: -2041 Y: -85 Z: 16986
 Mag X: -2845 Y: -2177 Z: -32768
 Gyro X: -160 Y: -181 Z: -325
 
Temp: 34 
Accel X: -2045 Y: -72 Z: 16826
 Mag X: -2905 Y: -2201 Z: -32768
 Gyro X: -138 Y: -148 Z: -337
 
Temp: 34 
Accel X: -2062 Y: -103 Z: 16975
 Mag X: -2894 Y: -2152 Z: -32768
 Gyro X: -45 Y: -138 Z: -341
 
Temp: 34 
Accel X: -2108 Y: -90 Z: 16932
 Mag X: -2912 Y: -2155 Z: -32768
 Gyro X: -96 Y: -151 Z: -335
 
Temp: 34 
Accel X: -2021 Y: -59 Z: 16920
 Mag X: -2900 Y: -2178 Z: -32768
 Gyro X: -105 Y: -142 Z: -327
 
Temp: 34 
Accel X: -2135 Y: -94 Z: 17021
 Mag X: -2859 Y: -2199 Z: -32768
 Gyro X: -67 Y: -93 Z: -344
 
Temp: 34 
Accel X: -2098 Y: -110 Z: 17083
 Mag X: -2883 Y: -2176 Z: -32768
 Gyro X: -90 Y: -179 Z: -320
 
Temp: 35 
Accel X: -1999 Y: -64 Z: 16883
 Mag X: -2880 Y: -2187 Z: -32768
 Gyro X: -103 Y: -131 Z: -355
 
Temp: 35 
Accel X: -2046 Y: -94 Z: 16891
 Mag X: -2884 Y: -2176 Z: -32768
 Gyro X: -66 Y: -188 Z: -337
 
Temp: 35 
Accel X: -2053 Y: -74 Z: 16858
 Mag X: -2886 Y: -2142 Z: -32768
 Gyro X: -118 Y: -149 Z: -307
 
Temp: 34 
Accel X: -2101 Y: -139 Z: 16987
 Mag X: -2894 Y: -2136 Z: -32768
 Gyro X: -178 Y: -172 Z: -306
 
Temp: 34 
Accel X: -2132 Y: -114 Z: 17010
 Mag X: -2881 Y: -2166 Z: -32768
 Gyro X: -110 Y: -136 Z: -342
 
Temp: 34 
Accel X: -2039 Y: -90 Z: 16902
 Mag X: -2931 Y: -2205 Z: -32768
 Gyro X: -71 Y: -125 Z: -363
 
Temp: 34 
Accel X: -1990 Y: -37 Z: 16799
 Mag X: -2911 Y: -2140 Z: -32768
 Gyro X: -97 Y: -149 Z: -375
 
Temp: 35 
Accel X: -2048 Y: -69 Z: 16856
 Mag X: -2853 Y: -2122 Z: -32768
 Gyro X: -112 Y: -99 Z: -352
 
Temp: 34 
Accel X: -1938 Y: -83 Z: 16829
 Mag X: -2876 Y: -2154 Z: -32768
 Gyro X: -92 Y: -146 Z: -340
 
Temp: 34 
Accel X: -2034 Y: -73 Z: 16913
 Mag X: -2824 Y: -2195 Z: -32768
 Gyro X: -135 Y: -103 Z: -306
 
Temp: 35 
Accel X: -2055 Y: -89 Z: 17088
 Mag X: -2917 Y: -2181 Z: -32768
 Gyro X: -104 Y: -136 Z: -319
 
Temp: 34 
Accel X: -2048 Y: -123 Z: 16960
 Mag X: -2906 Y: -2170 Z: -32768
 Gyro X: -125 Y: -112 Z: -345
 
Temp: 33 
Accel X: -2038 Y: -60 Z: 16871
 Mag X: -2922 Y: -2125 Z: -32768
 Gyro X: -80 Y: -92 Z: -361
 
Temp: 34 
Accel X: -2044 Y: -72 Z: 16964
 Mag X: -2847 Y: -2135 Z: -32768
 Gyro X: -112 Y: -163 Z: -346
 
Temp: 34 
Accel X: -2065 Y: -70 Z: 16824
 Mag X: -2862 Y: -2233 Z: -32768
 Gyro X: -51 Y: -114 Z: -284
 
Temp: 34 
Accel X: -2077 Y: -52 Z: 16936
 Mag X: -2854 Y: -2168 Z: -32768
 Gyro X: -132 Y: -188 Z: -308
 
Temp: 34 
Accel X: -2043 Y: -78 Z: 16924
 Mag X: -2933 Y: -2197 Z: -32768
 Gyro X: -153 Y: -122 Z: -312
 
Temp: 34 
Accel X: -2022 Y: -75 Z: 16897
 Mag X: -2835 Y: -2163 Z: -32768
 Gyro X: -98 Y: -105 Z: -310
 
Temp: 34 
Accel X: -2070 Y: -80 Z: 16908
 Mag X: -2890 Y: -2149 Z: -32768
 Gyro X: -75 Y: -168 Z: -348
 
Temp: 34 
Accel X: -2080 Y: -90 Z: 17112
 Mag X: -2885 Y: -2194 Z: -32768
 Gyro X: -117 Y: -161 Z: -320
 
Temp: 34 
Accel X: -2117 Y: -104 Z: 17088
 Mag X: -2887 Y: -2229 Z: -32768
 Gyro X: -90 Y: -145 Z: -329
 
Temp: 34 
Accel X: -2022 Y: -43 Z: 16881
 Mag X: -2882 Y: -2200 Z: -32768
 Gyro X: -128 Y: -197 Z: -341
 
Temp: 34 
Accel X: -2074 Y: -62 Z: 16939
 Mag X: -2903 Y: -2219 Z: -32768
 Gyro X: -103 Y: -142 Z: -348
 
Temp: 34 
Accel X: -2068 Y: -62 Z: 16920
 Mag X: -2909 Y: -2179 Z: -32768
 Gyro X: -122 Y: -132 Z: -351
 
Temp: 34 
Accel X: -2063 Y: -105 Z: 17058
 Mag X: -2840 Y: -2144 Z: -32768
 Gyro X: -102 Y: -113 Z: -339
 
Temp: 34 
Accel X: -2038 Y: -77 Z: 16882
 Mag X: -2892 Y: -2170 Z: -32768
 Gyro X: -108 Y: -127 Z: -312
 
Temp: 34 
Accel X: -2151 Y: -109 Z: 17009
 Mag X: -2946 Y: -2140 Z: -32768
 Gyro X: -134 Y: -163 Z: -320
 
Temp: 34 
Accel X: -2094 Y: -81 Z: 16847
 Mag X: -2904 Y: -2238 Z: -32768
 Gyro X: -80 Y: -106 Z: -346
 
Temp: 34 
Accel X: -2016 Y: -49 Z: 16763
 Mag X: -2882 Y: -2161 Z: -32768
 Gyro X: -170 Y: -119 Z: -325
 
Temp: 34 
Accel X: -2090 Y: -85 Z: 16887
 Mag X: -2794 Y: -2174 Z: -32768
 Gyro X: -65 Y: -177 Z: -345
 
Temp: 34 
Accel X: -2048 Y: -107 Z: 17022
 Mag X: -2875 Y: -2129 Z: -32768
 Gyro X: -116 Y: -110 Z: -354
 
Temp: 34 
Accel X: -2036 Y: -107 Z: 16870
 Mag X: -2888 Y: -2176 Z: -32768
 Gyro X: -112 Y: -169 Z: -337
 
Temp: 34 
Accel X: -2125 Y: -102 Z: 17062
 Mag X: -2847 Y: -2197 Z: -32768
 Gyro X: -142 Y: -83 Z: -349
 
Temp: 34 
Accel X: -2056 Y: -53 Z: 16855
 Mag X: -2900 Y: -2208 Z: -32768
 Gyro X: -106 Y: -153 Z: -347
 
Temp: 34 
Accel X: -2018 Y: -69 Z: 16884
 Mag X: -2948 Y: -2223 Z: -32768
 Gyro X: -119 Y: -138 Z: -328
 
Temp: 34 
Accel X: -2095 Y: -84 Z: 16903
 Mag X: -2921 Y: -2194 Z: -32768
 Gyro X: -153 Y: -161 Z: -351
 
Temp: 33 
Accel X: -2056 Y: -70 Z: 16905
 Mag X: -2848 Y: -2214 Z: -32768
 Gyro X: -76 Y: -92 Z: -372
 
Temp: 34 
Accel X: -2091 Y: -105 Z: 16931
 Mag X: -2886 Y: -2213 Z: -32768
 Gyro X: -158 Y: -180 Z: -276
 
Temp: 34 
Accel X: -2076 Y: -88 Z: 16975
 Mag X: -2898 Y: -2174 Z: -32768
 Gyro X: -109 Y: -122 Z: -314
 
Temp: 34 
Accel X: -2030 Y: -51 Z: 16923
 Mag X: -2928 Y: -2165 Z: -32768
 Gyro X: -89 Y: -148 Z: -352
 
Temp: 33 
Accel X: -1973 Y: -73 Z: 16884
 Mag X: -2837 Y: -2126 Z: -32768
 Gyro X: -6 Y: -153 Z: -353
 
Temp: 34 
Accel X: -2021 Y: -76 Z: 16876
 Mag X: -2894 Y: -2139 Z: -32768
 Gyro X: -47 Y: -95 Z: -354
 
Temp: 34 
Accel X: -2162 Y: -72 Z: 17037
 Mag X: -2907 Y: -2190 Z: -32768
 Gyro X: -89 Y: -155 Z: -321
 
Temp: 33 
Accel X: -2093 Y: -143 Z: 16927
 Mag X: -2828 Y: -2163 Z: -32768
 Gyro X: -125 Y: -153 Z: -373
 
Temp: 35 
Accel X: -2033 Y: -25 Z: 16793
 Mag X: -2858 Y: -2143 Z: -32768
 Gyro X: -97 Y: -172 Z: -307
 
Temp: 34 
Accel X: -2038 Y: -42 Z: 16912
 Mag X: -2878 Y: -2175 Z: -32768
 Gyro X: -63 Y: -177 Z: -337
 
Temp: 34 
Accel X: -2051 Y: -93 Z: 16916
 Mag X: -2887 Y: -2185 Z: -32768
 Gyro X: -115 Y: -148 Z: -358
 
Temp: 34 
Accel X: -2078 Y: -110 Z: 17073
 Mag X: -2853 Y: -2177 Z: -32768
 Gyro X: -129 Y: -147 Z: -386
 
Temp: 34 
Accel X: -2073 Y: -107 Z: 16977
 Mag X: -2819 Y: -2170 Z: -32768
 Gyro X: -178 Y: -128 Z: -333
 
Temp: 35 
Accel X: -2012 Y: -83 Z: 16881
 Mag X: -2821 Y: -2133 Z: -32768
 Gyro X: -153 Y: -198 Z: -294
 
Temp: 34 
Accel X: -1985 Y: -69 Z: 16896
 Mag X: -2896 Y: -2164 Z: -32768
 Gyro X: -145 Y: -184 Z: -324
 
Temp: 35 
Accel X: -2097 Y: -78 Z: 16957
 Mag X: -2936 Y: -2183 Z: -32768
 Gyro X: -96 Y: -159 Z: -317
 
Temp: 34 
Accel X: -2048 Y: -21 Z: 16797
 Mag X: -2933 Y: -2140 Z: -32768
 Gyro X: -110 Y: -129 Z: -352
 
Temp: 34 
Accel X: -2052 Y: -112 Z: 16936
 Mag X: -2891 Y: -2175 Z: -32768
 Gyro X: -120 Y: -86 Z: -357
 
Temp: 34 
Accel X: -2123 Y: -83 Z: 16969
 Mag X: -2896 Y: -2209 Z: -32768
 Gyro X: -70 Y: -104 Z: -351
 
Temp: 35 
Accel X: -2062 Y: -59 Z: 16969
 Mag X: -2863 Y: -2182 Z: -32768
 Gyro X: -96 Y: -108 Z: -338