31.07.2015 Views

A-Teachers-Guide-to-the-Intel-Galileo-Final

A-Teachers-Guide-to-the-Intel-Galileo-Final

A-Teachers-Guide-to-the-Intel-Galileo-Final

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

57 | Using <strong>the</strong> <strong>Galileo</strong> as a ComputerConnect temperature sensor <strong>to</strong> <strong>the</strong> <strong>Galileo</strong> as follows:1. Solder jumper wires <strong>to</strong> five of <strong>the</strong> six connec<strong>to</strong>rs on <strong>the</strong> TMP102. Leave <strong>the</strong> ALTconnection clear.For instructions on how <strong>to</strong> solder see http://www.wikihow.com/Solder-Electronics2. Connect ADD0 pin <strong>to</strong> GND on <strong>the</strong> <strong>Galileo</strong>.3. Connect VCC pin <strong>to</strong> 3.3V on <strong>the</strong> <strong>Galileo</strong>.4. Connect SDA pin <strong>to</strong> Analog Pin 4 on <strong>the</strong> <strong>Galileo</strong> (A4).5. Connect SCL pin <strong>to</strong> Analog Pin 5 on <strong>the</strong> <strong>Galileo</strong> (A5).6. Connect GND pin on <strong>the</strong> TMP102 <strong>to</strong> GND on <strong>the</strong> <strong>Galileo</strong>.Coding <strong>the</strong> ArduinoUpload <strong>the</strong> following sketch <strong>to</strong> your Arduino.// This program reads a value from <strong>the</strong> TMP102 temp sensor on <strong>the</strong>// <strong>Galileo</strong> and writes it <strong>to</strong> a file and <strong>the</strong> serial output for debugs.//////////////////////////////////////////////////////////////////#include int tmp102Address = 0x48;FILE* tempFile;void setup(){Serial.begin(9600);Wire.begin();}void loop(){float celsius = getTemperature();Serial.print("Celsius: ");Serial.println(celsius);// create file for writing temperature <strong>to</strong> if it doesn't existtempFile = fopen("/home/root/currentTemperature", "w+");// now write <strong>to</strong> file on <strong>the</strong> <strong>Galileo</strong>if (tempFile != NULL) {// convert float <strong>to</strong> a stringfprintf(tempFile,"%.2f",celsius);fclose(tempFile);}else {Serial.println("File doesn't exist");}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!