Sensing the winds and weather has been important to man over the centuries. Athenians built the eight-sided Tower of the Winds in the first century BC in honor of the eight gods of the winds. The Tower of the Winds stands to this day in the ancient agora, or market, in Athens.
Many significant weather events have effected mankind over the years. We know of these because their effects have become part of history. Since much of history is a recollection of a series of wars and battles, it is interesting to note that a well known early reference to the importance of the weather is from the Chinese philosopher Sun Tsu, who said, “Know yourself and know your enemy, and victory is guaranteed. Know the terrain and know the weather, and you will have total victory.”
Much later in history, we know that Napoleon’s invasion of Russia in 1812 was stymied when snow and cold weather came earlier in the season than he and his generals had planned. This, combined with Russian militia attacks, helped defeat the French, who invaded with 500, 00 troops and left with only 20, 000 survivors. One hundred thirty years later, this was repeated when Hitler’s invasion of the Soviet Union was again foiled in part by brutally cold winter weather.
In the 20th century, large population migrations were brought about by adverse weather conditions, including those of the Dust Bowl in the United States during the 1930s, multiple Asian droughts throughout the century, and three significant periods of drought in the Sahel region of Africa. Individual events that killed and affected many people include the great smog event in London in 1952, which killed 4, 000 people in five days in December, many hurricane impacts along the east coast of the United States, and several notable blizzards. Man’s effect upon the environment has also been seen in the weather, in more recent events, when the release of radioactive particles from the reactor accident at Chernobyl, Ukraine, was detected by sensors outside of the Soviet Union and traced back to Chernobyl using sophisticated weather sensors and meteorological models. In a similar fashion, local weather instruments were used to help estimate the impact of smoke and soot from oil well fires set during the 1991 Gulf War.
Today, the winds and other weather variables are of equal concern and can have an even greater impact on our modern, high-tech lifestyle. Weather affects a wide range of man’s activities, including agriculture, transportation, and leisure time. Often the effects involve the movement of gases and particulates through the atmosphere. Modern weather monitoring systems and networks are designed to make the measurements necessary to track these movements in a cost-effective manner. This requires that the total life-cycle cost of a monitoring system is minimized, and one way to do this is to minimize or eliminate the maintenance of the weather monitoring system. Using a solid-state system to measure the weather, including the wind speed and direction, is paramount to minimize equipment servicing and costs. The conventional weather monitoring system consisted of individual sensors to measure one meteorological variable, each connected to a data collection device or recorder. Modern technology has allowed the combination of several sensors into one integrated weather station that can be permanently located at one site or transported to a site where localized weather is needed.
So exploiting all the immense capabilities of Ada together with a collection of BM1383AGLV pressure-temperature sensors we are going to build a localized weather station with varied applications.
HardWare1. Raspberry Pi 3B+
As we all know Raspberry Pi is a series of small single-board computers, Raspberry Pi 3B+ is one of the latest editions of the family. I chose this because it is fast operating and easy to handle and also Ada has builtin support for Raspberry Pi.
But one of the major issues of RPI is that it is not capable of reading Analog inputs from its GPIO. To overcome this I chose a sensor with I2C support so that I can easily access the data from the sensor.
2. BM1383AGLV
BM1383AGLV is a piezo-resistive pressure sensor. It does temperature compensation for MEMS inside the chip, so it’s very easy to get pressure information. It consists of both temperature and pressure sensors and provides an I2C interface. It can read pressures ranging from 300hPa to 1100hPa and temperatures from -40°C to +85°C.
The schematics for hardware connection is given below. Connect the SDA pin to GPIO2 and SCL pin to GPIO3. The DRDY pin is optional. If you are using it in the code pull it to 1.
1. GNAT
GNAT is a free software compiler for the Ada programming language which forms part of the GNU Compiler Collection. It supports all versions of the language, i.e. Ada 2012, Ada 2005, Ada 95 and Ada 83.
To install the GNAT compiler in Raspberry Pi enter the following command in the terminal.
sudo apt-get install gnat
2. ADA Code
After choosing the sensor I went on searching for any Ada libraries giving I2C support, but I was disappointed as I wasn't able to find one. So I decided to build a library for BM1383AGLV from scratch.
I used some bash commands to communicate with the I2C modules and was able to read the data from the module.
i2cdetect
I used this command to search for connected I2C modules
i2cget
I used this command to read the data stored in the sensor.
So I started searching for an Ada module that can execute bash commands and I found Interfaces.C module.
Using this piece of code I was able to execute commands in the terminal
function System (Cmd : String) return Integer is
function C_System (S : Interfaces.C.char_array) return Integer;
pragma Import (C, C_System, "system");
begin
return C_System (Interfaces.C.To_C (Cmd));
end System;
Then I started incorporating the commands to the Ada code. The i2c.adb file reads as
with Interfaces.C;
with Ada.Strings.Fixed;
with GNAT.Expect;
package body i2c is
R,V1: Integer;
W1: String:="i2cset -y -a 1 0x5d 0x12 0x01";
W2: String:="i2cset -y -a 1 0x5d 0x13 0x01";
W3: String:="i2cset -y -a 1 0x5d 0x14 0x9";
R1: String:="i2cget -y -a 1 0x5d 0x19";
R2: String:="i2cget -y -a 1 0x5d 0x1A";
R3: String:="i2cget -y -a 1 0x5d 0x1B";
R4: String:="i2cget -y -a 1 0x5d 0x1C";
procedure write is
function System (Cmd : String) return Integer is
function C_System (S : Interfaces.C.char_array) return Integer;
pragma Import (C, C_System, "system");
begin
return C_System (Interfaces.C.To_C (Cmd));
end System;
pragma Inline (System);
begin
R := System (W1);
DELAY 0.5;
R := System (W2);
R := System (W3);
end write;
procedure read is
function System (Cmd : String) return Integer is
function C_System (S : Interfaces.C.char_array) return Integer;
pragma Import (C, C_System, "system");
begin
return C_System (Interfaces.C.To_C (Cmd));
end System;
pragma Inline (System);
Com: String:="sudo chmod +x i2c.sh && ./i2c.sh";
begin
V1 := System (Com);
end read;
end i2c;
WorkingNow it's time to check the working. Download the code and execute the following command to see them working.
gprbuild -d aws.gpr -XPrivate_Warnings=FALSE -XModule=MOD_RPI aws.adb
Then you can find an executable in the bin folder. Execute it using the following command
sudo ./aws
It will give you a result like this
We have now developed a localized weather station that is capable of monitoring the weather variables from time to time. Incorporating these variables into the existing machine learning models we will be able to predict the weather for upcoming days more precisely.
For further documentation and details visit the GitHub Repository.
Comments