Hardware Reference
In-Depth Information
Measuring the temperature and humidity
remotely
Now that the basics of the project are working, we can go further. We clearly don't want to
constantly have the serial monitor from the Arduino IDE open and type commands by
hand. This is why we need to build a graphical interface on your computer.
In this section, we are going to build a simple graphical interface using Python and the
graphical library that comes with it, Tkinter. All the code will simply be contained in a
Python file that can be executed later to open the interface.
The first step of the Python code is to import the correct Python modules. Python modules
are basically like Arduino libraries; they add additional functions to Python. We need the
time module, the serial module that we installed before, and every other component of
the Tkinter module:
import time
import serial
from Tkinter import *
If you need more information on the Tkinter module, you can visit the official documenta-
tion page at https://wiki.python.org/moin/TkInter .
We have to set up the serial connection just as we did in the serial monitor of the Arduino
IDE. The first step is to set the serial speed and the serial port. Of course, you will have to
modify the serial port depending on how it appears on your computer:
serial_speed = 115200
serial_port = '/dev/cu.AdafruitEZ-Link06d5-SPP'
We can now create the serial instance with the following parameters:
ser = serial.Serial(serial_port, serial_speed, timeout=1)
The next step is to create the class that will contain our graphical interface:
class Application(Frame):
Search WWH ::




Custom Search