Using Crystal Signal Pi, Part 3 – Setup a Caution Light Solution made with Raspberry Pi – Creating Tools

Using Crystal Signal Pi, Part 3 – Setup a Caution Light Solution made with Raspberry Pi – Creating Tools

crystal-signal-pi

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”)

Before Customizing (Install samba and bc)

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.

crystal-signal-pi-3-install-samba

On edit for nano, open smb.com and add the line below.
/etc/samba/smb.conf

crystal-signal-pi-3-install-samba

Fig.1

crystal-signal-pi-3-fig2Fig.2

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).

crystal-signal-pi-3-code

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.

crystal-signal-pi-3-code

Prepping the Temperature Sensor

Let’s start by first setting the temperature sensor at the proper conditions.

crystal-signal-pi-3-fig3Fig.3

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.

crystal-signal-pi-3-code

Let’s add the line below. The number at the end will be from the GPIO (this time, it’ll be 23).

crystal-signal-pi-3-code

After rebooting, 1-Wire will be activated and a file will be made inside the “/sys/bus/w1devices” directory.

Fig.4

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.

crystal-signal-pi-3-fig5Fig.5

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.

Creating a Program

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.

  • When temperatures are more than 27℃→ Flash red lights
  • When temperatures are less than 20℃→Flash blue lights/li>

/var/lib/crystal-signal/scripts/temperature.sh

crystal-signal-pi-3-code

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.

crystal-signal-pi-3-fig6Fig.6

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.”

  1. Pushing the button starts the temperature.sh(De-synchronized flashing)
  2. When temperatures drop below 20℃→Flashes blue light
  3. Pushing the button halts the alert(Ack.sh)
  4. Pushing the button starts the temperature.sh(De-synchronized flashing)
  5. When temperatures rise above 27℃→Flashes red light
  6. Pushing the button halts the alert(Ack.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.

crystal-signal-pi-3-code

Whenever an alert occurred when temperatures dipped below 20℃ and above 27℃, they were displayed in the “Info” line with the temperature recorded.

Summary

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!