In the third entry of our ongoing Crystal Signal Pi series, we’ll be making tools, finally! Today, we’ll try generating an alert according to the changes in temperature, using the Crystal Signal Pi and a temperature sensor (DS18B20).
This article was translated to English, and was originally published for deviceplus.jp.
In this article, we’ll be using the same Raspberry Pi setup that we used last time (Body: Raspberry Pi 3/OS: Raspbian Jessie Lite).
As soon as you access the Raspberry Pi IP address from the browser, we’ll start! (The IP address used in this article is “192.168.0.9”)
By installing the samba package, it’ll make things go a lot smoother since you’ll be able to edit the file directly from the outside.
On edit for nano, open smb.com and add the line below.
Each folder’s contents should look something like this.
Next, let’s try editing the access permission for these files. Since you can also edit existing files, it’ll look like the picture below (*when no edits are necessary, change access permissions to the appropriate individuals).
On the GitHub page, a warning like the one below will be displayed. Let’s try to be careful not to name the script files the same.
Warning: The script that has been prepared as a sample will be written over whenever there is a middleware update. If you would like to customize this script, please copy and use this script under a separate name. Do not edit directly.
We’ll be using the shell script and writing a new source code this time around by using the “bc” command for calculations involving decimals, so install it first if necessary.
Let’s start by first setting the temperature sensor at the proper conditions.
Because the Crystal Signal Pi uses 12 pins to connect to the Raspberry Pi, we wired it like in Fig. 3. This time, we’ll be using GPIO23 for the signal line connection.
Let’s add the line below. The number at the end will be from the GPIO (this time, it’ll be 23).
After rebooting, 1-Wire will be activated and a file will be made inside the “/sys/bus/w1devices” directory.
Fig. 4 follows the “root” directory that we set up on “samba” a while back. To get the temperature, we’ll be using the file names displayed in Fig. 4. In today’s case, that file name will be “28-0000006470bec.”
We’ll then get the command to measure the temperature as seen below.
The “t=” at the end of the second line will indicate the temperature in the thousandths place. In Fig. 5, this number would put the temperature at 26.812 degrees Celsius.
Referring to the middleware script in the “scripts” directory, let’s try making some programs! We’ll be trying to make a program that lets out two types of alerts under the below conditions.
Because it’s hard to tell if nothing is occurring when temperatures are moderate (in this case around 20-27℃), let’s try using “De-synchronized flashing” with a smooth flash.
On the “Settings” screen, I’ll set the button operations for the Crystal Signal Pi.
For normal pushes on “light off,” we’ll set it at “temperature.sh” while we divvy up “Ack.sh” to “light on” for normal pushes (delete alert operations).
Additionally, to stop alerts and reboot at the same time, I set the long pushes on “light on” to “temperature.sh.”
The general flow of the video plays out like this. Temperature sensor was tested by using a cold insulator and our fingers to shift between hot and cold. By doing this, we were able to test out how the device reacted to the temperature differences.
The “Log” screen also turned out like this.
Whenever an alert occurred when temperatures dipped below 20℃ and above 27℃, they were displayed in the “Info” line with the temperature recorded.
At the end of the day, we were able to make a tool using a temperature sensor and the Crystal Signal Pi! By just choosing a script in the middleware, we were able to make button functions with relative ease. Since this also covered some of the difficulties in electronic work, I highly recommend this to even Raspberry Pi beginners.
What else can I say besides, how gorgeous that light looks!