Tutorial 2 on Advanced Input for Intel® Galileo Boards

Documentation

Install & Setup

000006653

06/10/2022

The circuit you build has two inputs (microphone and touch capacitor), and two outputs (two LEDs). Before wiring everything up, let's look at the types of inputs we are using.

Microphone Sensor

Our microphone sensor is an analog input. This type of input means it takes values from the physical world and converts them into machine-readable values. We then use these values in our program.

Capacitive Touch Sensor

Our touch sensor is digital input. This type of input means that it only interprets HIGH and LOW (true/false, 0/1) incoming values.

Understanding the differences between the two types of inputs is important. The Intel® Galileo board has six analog inputs label A0-A5. Analog pins are input only. Analog pins maps incoming voltage signals (0 to 5 V) into integer values between 0 and 1023. In code, we read and write analog values using the analog functions.

// Declare and assign "val" to the incoming value from pin A0 (ranging between 0-1023)
int val = analogRead(A0);
// Writes incoming values from A0 (ranging between 0-255, after mapping the value)
analogWrite(13, val);

For more details on how and when to use the analog functions, refer to the reference guide:
analogRead reference info
analogWrite reference info

Why is there an analogWrite function? What are we writing to?

Here, we use the Pulse Width Modulation (PWM) pins. We'll go over how PWM works, and how and when to use it in the next section.

Test Input values

  1. Power the breadboard:
    • Connect two jumper cables to the 5 V and GND pins on the Galileo board respectively.
    • Connect the two ends of those cables to the breadboard's vertical strips, marked +, - (which represent PWR and GND).
    • This connection provides power to the entire vertical strips for other modules to connect to.
  2. Connect the microphone:
    • Connect two jumper cables from the microphone's PWR and GND pins to their respective vertical tracks on the breadboard.
    • Connect the remaining jumper from the microphone to a row on the inner section of the breadboard.
    • Then, connect a jumper cable from that same row into pin A0.
  3. Connect the touch sensor:
    • Connect the touch sensor's PWR and GND inputs (just as you did with the microphone's cables). Then, connect the cable ends to the breadboards vertical PWR and GND strips.
    • Connect the final cable to a row on the inner section of the breadboard.
    • It must be a different row from the microphone. Finally, connect the remaining jumper cable from the same row to pin 2.

Upload the following sketch. Open up your serial monitor to see what's happening:

// Declare and assign two variables that represent the pins for the sensors

Note The word const in front of a variable declaration tell the compiler that this variable can't be updated by the program.

const int touch = 2;
const int sound = A0;
void setup(){
Serial.begin(57600);
// Set the pin mode for the touch sensor.
pinMode(touch, INPUT);

}

Note Because the sound sensor is an Analog input, we don't need to set a pin mode.

void loop(){ // Declare and assign two variables that represent the input reading from the sensors
int touch_input = digitalRead(touch);
int sound_input = analogRead(sound);
// Print the values to the serial monitor
Serial.print("sound: ");
Serial.println(sound_input);
Serial.print("touch: ");
Serial.println(touch_input);
Serial.println("");
// Wait 10 milliseconds before the next reading
delay(10);

}