Sunteți pe pagina 1din 4

Food

Living

Outside

Play

Technology

Workshop

Analog Read Tutorial


by pcduino on March 2, 2014

Table of Contents
Analog Read Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Intro: Analog Read Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 1: Hardware Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 2: PcDuino piouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 3: Analog Read Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

http://www.instructables.com/id/Analog-Read-Tutorial/

Intro: Analog Read Tutorial


This tutorial will show you how to program the pcDuino to read an analog input.
It assumes you have a basic working knowledge of the pcDuino on Linux. It builds upon the pcDuino Blink Tutorial.
For this tutorial you will need the following items:
1.A pcDuino running the 20130531 Ubuntu image with ssh.
2.A breadboard.
3.A potentiometer.
4.Three wire jumpers.
5.The source code below for analog.c

Step 1: Hardware Setup


A potentiometer also known as a pot has three terminals. These terminals connect to the the input voltage, the input channel and ground. The input channel terminal is
connected inside the pot to a wiper that moves across resistive material in the pot. The closer it is to the terminal with ground connected the lower the voltage and the
closer it is to the terminal with the input voltage higher the voltage is.
I used a 10K Ohm breadboard compatible potentiometer similar to the one in the picture below.

Step 2: PcDuino piouts


From left to right on the breadboard in the picture above are connected: ground, ADC2, and 3.3V.
At this point you are ready to power up your pcDuino.

http://www.instructables.com/id/Analog-Read-Tutorial/

Step 3: Analog Read Program


To read an analog pin you just need to open a special file and then read the file.
The file is /proc/adc# where the # is replaced with 0 5 depending on the pin you are using. ADC0 and ADC1 work with voltages from 0V to 2V and have 6 bits. This
means that you are going to be reading values from 0 to 63. ADC1 ADC5 work with voltages from 0V to 3.3V and have 12 bits which means you will read values from 0
4095. When /proc/adc# is read it returns the following string: adc#: where # is the adc pin 0 to 5 and value is 0 to 63 for ADC0 and ADC1 and 0 to 4095 for ADC2 to
ADC5.
Download the code here: analog
Program Setup
Using the editor of your choice or the command cat > analog.c you will need to get the program on to your pcDuino. See the Blink Tutorial for screen shots on how to
do this.
Next you will need to load the appropriate driver if it isnt already loaded when you boot your system. You can check using the lsmod command and then load the driver
using sudo modprobe adc again there are screenshots of this in the Blink Tutorial.
Next compile your program using gcc analog.c o analog and then run it using ./analog. You should get a series of numbers printed on your screen. These numbers
should change when you rotate the pot attached to the pcDuino.
Acknowledgements
Thanks to the folks at Sparkfun and their great Getting Started with pcDuino for getting me started with putting this tutorial together. Also thanks to the folks on the
pcDuino website for their support. Check out the website and forums for more information.
Source: http://digitalhacksblog.blogspot.com/2013/09/pcdu...

Related Instructables

Introduce by
Yanny Guo

PCDUINO Robot
by iloveandroid

Use 3D printer
to print the
enclosure for
pcDuino 3 by
Yanny Guo

Play Pong with


Scratch for
pcDuino by
Linksprite

http://www.instructables.com/id/Analog-Read-Tutorial/

Use pressure
sensor on
pcduino by
Yanny Guo

Use picoBoard
for Scratch on
pcDuino by
jingfeng

Advertisements

Comments
1 comments

Add Comment

geraldpaxton says:

May 25, 2014. 7:50 AM REPLY


I nof userseeded 12 bit resolution for position sensing so I ordered 2 galileo boards from Mouser in January, the IDE runs under w7 but the unix environment
I've been trying to download and compile is still 'buggy'. I received a PCduino3 less than a week ago, plugged in a usb expander for keyboard &mouse, hdmi
cable to tv, powered it up and it worked out of the box...Intel's piece o' crap still has 100's of users trying to debug the operating system. Thank you PCduino!
Does anyone have information on running a 'forth' system in a sandbox under Ubuntu?

http://www.instructables.com/id/Analog-Read-Tutorial/

S-ar putea să vă placă și