Using digital pins

Let's build a Blynk app and write code to display data coming from the potentiometer attached to the Raspberry Pi using digital pins. To build the project, you will need the following things:

  • A potentiometer
  • Breadboard
  • Hookup wires

Following diagram shows the wiring diagram for building the circuit. Connect the center pin of the potentiometer to the Raspberry Pi BCM_GPIO pin 18 (WiringPi pin 1). Connect one of the outer pins of the potentiometer with the Raspberry Pi 5V pin. Connect the other outer pin of the potentiometer with Raspberry Pi GND:

Potentiometer attached to the Raspberry Pi BCM_GPIO pin 18 (WiringPi pin 1)

Now, let's configure the Value Display widget with the digital pin (BCM_GPIO pin 18 / WiringPi pin 1):

  1. Tap the Value Display widget to open the Value Display Settings page.
  2. Tap PIN, and from the left-hand side list, select Digital. Then, from the right-hand side list, select gp 18 PWM (see the following screenshot):
Selecting a digital pin
  1. Tap OK and now your Value Display Settings page should look like this (see the following screenshot):
Value Display widget configured with a digital pin
  1. Tap the back button on the toolbar to view the canvas. The Value Display widget is now configured with digital pin BCM_GPIO pin 18 (WiringPi pin 1), as shown in the following screenshot:
Configured Value Display widget on canvas
  1. Modify the main.cpp file as shown in Listing 4.1 (https://github.com/PacktPublishing/Hands-On-Internet-of-Things-with-Blynk/blob/master/Chapter%204/Listing%204-1/main.cpp). Use the following command to locate and open the file with the PuTTY terminal by connecting through SSH to the Raspberry Pi:
pi@raspberrypi:~ $ cd blynk-library/linux
pi@raspberrypi:~/blynk-library/linux $sudonano main.cpp
  1. Save the file and exit the editor by pressing Ctrl + O, followed by Enter, followed by CtrlX.
  2. Now, build the C++ project with the following command:
pi@raspberrypi:~/blynk-library/linux $ ./build.sh raspberry
  1. Run the C++ project using the following command with the auth token associated with your Blynk project:
pi@raspberrypi:~/blynk-library/linux $sudo ./blynk --token=ca7bed1c92214503a65de8e20164994f
  1. Now, tap the play button to start the app. The Value Display widget will show the current analog reading value of the potentiometer. You can take potentiometer values between 0 and 1023.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.144.197