Blynk for Raspberry Pi
Getting Started with Blynk
With all the pieces in place, you are ready to build your first Blynk project. Launch the app on your mobile device and create a new account (Figure 1). Note that if you run your own Blynk server, you also have to specify its address. Log in using the created account credentials and tap the Create New Project canvas. Give the project a descriptive name and select the correct Raspberry Pi model. Note the project's unique token and tap the Create button to create the project (Figure 2).
Once you've created the project, you are dropped into an empty canvas. Building a graphical interface in Blynk involves adding and configuring widgets. Because it's a relatively new project, the Blynk app comes with only a handful of widgets, but it's enough to get you started.
Before you populate the project with widgets, however, you need to set up the Raspberry Pi. To see Blynk in action, start with a standard blinking LED example and wire an LED with a resistor to the Raspberry Pi as shown in Figure 3.
In a Terminal window on your Raspberry Pi, switch to the blynk-library/linux
directory and start the server using the command below (replace <AuthToken>
with the actual token generated by the Blynk app):
sudo ./blynk --token=<AuthToken>
This command connects to Blynk's default service, so if you are running your own server, you need to specify its address and port manually; for example:
sudo ./blynk --server=192.168.1.101 --port=8555 --token=AuthToken
If the connection has been established successfully, you should see the Ready! message.
To control the LED connected to the Raspberry Pi using the Blynk mobile app, you need to add a button to the project. To do this, press on the Plus icon in the upper-right corner of the screen to open the widget box, then tap on the Button widget to add it to the project (Figure 4).
You can place the button (and any other widget for that matter) anywhere on the screen by dragging the widget to the desired location. Tapping on the widget opens its configuration screen (Figure 5). Here, you can add a label for the widget and change its default color. More importantly, you can specify the GPIO pin that it controls. In this case, the LED is connected to pin 25, so tap the PIN button, choose Digital gp25 from the scroll list, and press Continue.
Using the appropriate option, you can also specify the button type, and you can choose between Push and Switch. Once you're done configuring the settings, tap the Back button to return to the project. Next, tap the Play button in the upper-right corner of the screen to run the created project. Tap the button widget, and the LED should turn on. Congratulations, your first Blynk project is working!
Using other widgets in Blynk is equally easy. The regular and large sliders, for example, can be used to control devices connected to the PWM GPIO pins of the Raspberry Pi. As an experiment, you can connect the LED circuit to pin 18 and use the slider to control the brightness of the LED. In the Blynk app, pick the regular or large slider from the widget box and place in on the canvas. Tap on the slider to configure its settings. Make sure you select the correct pin (pin 18 in this case) and specify the minimum and maximum values (try the default 0 and 255 values to begin with). Run the project, and use the slider to adjust the LED's brightness.
Final Thoughts
As a relatively new project, Blynk is still not complete. The Blynk app, for example, features only a few widgets that let you create simple projects. However, the Blynk developers promise to add more widgets in the near future. At the moment, the documentation is lacking, and it's focused on the Arduino platform. Thus, you'll not get much help when it comes to creating Raspberry Pi-based Blynk projects. Fortunately, Blynk's website provides community forums where you can ask for help if you run into problems, and this teething issue doesn't change the fact that Blynk looks like a very promising platform indeed.
The ability to build graphical interfaces quickly for controlling Raspberry Pi via the Internet using a mobile device opens a whole new world of possibilities and makes it significantly easier, even for users with no coding skills, to build creative and useful Raspberry Pi-based projects.
Infos
- Blynk: http://www.blynk.cc
« Previous 1 2 Next »
Buy this article as PDF
Pages: 4
(incl. VAT)