Userspace Arduino:AnalogReadSerial

Introduction
Just like an Arduino, a potentiometer can be hooked up to the Beaglebone Black and its analog value can be printed to the console using "Serial". There are a few differences, however. 
 * Firstly, the analog voltages on the Beaglebone Black are scaled from 0 to 1.8 V. Any voltage higher than this can damage the bone.
 * Also, the Beaglebone Black has a dedicated reference voltage level for analog operations. The pin P9_32 needs to be used as AVcc and P9_34 needs to be used as AGND.

Hardware
You need:


 * Potentiometer, a 10kΩ will do fine
 * Wire to join the stuff

Wire the potentiometer with the two extreme pins to P9_32 and P9_34. The middle pin of the potentiometer goes to AIN5, i.e., P9_36.

You can also use the Bacon Cape which has a nice sliding potentiometer already hooked up to AIN5.

Sketch
Derived from AnalogReadSerial

/* AnalogReadSerial Reads an analog input on AIN5 (P9_36) or pin 20 in the current variant, prints the result to the console. This example code is in the public domain. */ // the setup routine runs once when you press reset: void setup { }
 * 1) define Pot 20

// the loop routine runs over and over again forever: void loop { // read the input on analog pin 0: int sensorValue = analogRead(Pot); // print out the value you read: Serial.println(sensorValue); delay(1);       // delay in between reads for stability }