File: adc.md

package info (click to toggle)
kuttypy 2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,896 kB
  • sloc: python: 58,651; javascript: 14,686; xml: 5,767; ansic: 2,716; makefile: 453; asm: 254; sh: 48
file content (45 lines) | stat: -rw-r--r-- 1,378 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 8 Channel 10 bit ADC
![Screenshot](images/voltmeter.gif?raw=true "Voltmeter")

PA0 - PA7 are ADC enabled pins on the ATMEGA32, and the graphical utility is capable of monitoring these.
This makes it easy to record expected input values from analog sensors before hard-coding them into C programs.

<video controls width="600">
    <source src="../images/joystick.webm"
            type="video/webm">
    Sorry, your browser doesn't support embedded videos.
</video>

This 2 axis joystick's output is being monitored on PA6 and PA7. Notice how the values change when
the joystick is tilted along either axis

## Access via Python

=== "readADC"
	```python hl_lines="1"
	def readADC(channel)
	reads a voltage value from the specified channel, and returns it
	
	  channel : 0 to 7
	  return: 10 bit number( an integer between 0 and 1023 )
	
	```

=== "data logger example with matplotlib"
	```python  hl_lines="1"
	# Read values from Analog to Digital converter(ADC) channel 5 (PA5), and plot them
	import time
	from kuttyPy import *
	from matplotlib import pyplot as plt
	
	setReg('ADMUX', (1<<6) | 5) #REF_AVCC | Channel 5
	for a in range(50):
	    setReg('ADCSRA', 196)
	    cl = getReg('ADCL')
	    ch = getReg('ADCH')
	    plt.scatter(a, (ch<<8)|cl ,s=5)
	    plt.pause(0.01) #Wait 10 mS
	```

![Screenshot](images/code.gif?raw=true "Recording of the ADC logging example")