107
Chapter 7 AD/DA Converter
delay
(
100
);
}
Details about analogRead() and analogWrite():
v o id a nalogWrite ( int p in, i nt v alue) ;
This writes the given value to the supplied analog pin. You will need to register additional analog modules
to enable this function for devices.
i n t a nalogRead (int pin) ;
This returns the value read on the supplied analog input pin. You will need to register additional analog
modules to enable this function for devices.
For more detailed instructions about PCF8591 of wiringPi, please refer to:
http://wiringpi.com/extensiones/i2c-pcf8591/
Python Code 7.1.1 ADC
First install a smbus module, and the command is as follows:
sudo apt-get install python-smbus
After the installation is completed, operate according to the following steps. Observe the project result, and
then analyze the code.
1. Use cd command to enter 07.1.1_ADC directory of Python code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/07.1.1_ADC
2. Use the python command to execute the Python code “ADC.py”.
python ADC.py
After the program is executed, shift the potentiometer, then the terminal will print out the potentiometer
voltage value and the converted digital content. When the voltage is greater than 1.6V (voltage need to turn
on red LED), LED starts emitting light. If you continue to increase the output voltage, the LED will become
more bright gradually.
The following is the code:
1
2
3
4
5
6
7
i m port
smbus
i m port
time
address
=
0x48
#default address of PCF8591
bus
=
smbus
.
SMBus
(
1
)
cmd
=
0x40
#command
Summary of Contents for Ultimate Starter Kit
Page 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Page 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Page 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Page 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Page 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Page 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...