| 1 | # 8 Channel 10 bit ADC |
| 2 |  |
| 3 | |
| 4 | PA0 - PA7 are ADC enabled pins on the ATMEGA32, and the graphical utility is capable of monitoring these. |
| 5 | This makes it easy to record expected input values from analog sensors before hard-coding them into C programs. |
| 6 | |
| 7 | <video controls width="600"> |
| 8 | <source src="../images/joystick.webm" |
| 9 | type="video/webm"> |
| 10 | Sorry, your browser doesn't support embedded videos. |
| 11 | </video> |
| 12 | |
| 13 | This 2 axis joystick's output is being monitored on PA6 and PA7. Notice how the values change when |
| 14 | the joystick is tilted along either axis |
| 15 | |
| 16 | ## Access via Python |
| 17 | |
| 18 | === "readADC" |
| 19 | ```python hl_lines="1" |
| 20 | def readADC(channel) |
| 21 | reads a voltage value from the specified channel, and returns it |
| 22 | |
| 23 | channel : 0 to 7 |
| 24 | return: 10 bit number( an integer between 0 and 1023 ) |
| 25 | |
| 26 | ``` |
| 27 | |
| 28 | === "data logger example with matplotlib" |
| 29 | ```python hl_lines="1" |
| 30 | # Read values from Analog to Digital converter(ADC) channel 5 (PA5), and plot them |
| 31 | import time |
| 32 | from kuttyPy import * |
| 33 | from matplotlib import pyplot as plt |
| 34 | |
| 35 | setReg('ADMUX', (1<<6) | 5) #REF_AVCC | Channel 5 |
| 36 | for a in range(50): |
| 37 | setReg('ADCSRA', 196) |
| 38 | cl = getReg('ADCL') |
| 39 | ch = getReg('ADCH') |
| 40 | plt.scatter(a, (ch<<8)|cl ,s=5) |
| 41 | plt.pause(0.01) #Wait 10 mS |
| 42 | ``` |
| 43 | |
| 44 |  |
| 45 |