A retired banker's first Raspberry Pi: a weather station on my terrace in Chennai
Contents
Dear friends,
I retired two years ago after 34 years in the IT department of a public sector bank. I began with punched cards, spent most of my career with COBOL, CICS and DB2, and learned Java in my fifties because the bank said so. My grandson, who is 17, informed me last year that COBOL is "basically dead" and that I should learn Python. I informed him that COBOL processed his grandmother's pension this morning. We agreed that I would learn Python if he would learn to make filter coffee properly. He has not kept his side of the agreement. I have kept mine.
கற்றது கைமண் அளவு, கல்லாதது உலகளவு. "What we have learned is a handful of sand; what we have not learned is the size of the world." Avvaiyar said it long before computers, and it has never been more true for me than this year.
What I built
A small weather station on the terrace: temperature, humidity and air pressure every ten minutes, stored in a database, with a simple graph my wife checks each morning to decide whether to put the clothes out to dry. For a Chennai household this is a serious application.
The parts
- Raspberry Pi 4, 2GB, purchased from a shop on Ritchie Street after a long negotiation
- A BME280 sensor module (temperature, humidity, pressure), which speaks I2C
- A USB pen drive instead of an SD card, on the advice of Matt from this very site
- Four jumper wires, and a plastic box from the kitchen, with permission
The steps, as a COBOL man understood them
- Enabled I2C in
sudo raspi-config, under Interface Options. - Connected the sensor: 3.3V, ground, SDA to GPIO 2, SCL to GPIO 3. I checked each wire twice, as one checks a JCL card before submitting a job.
- Ran
i2cdetect -y 1, and the number 76 appeared in the grid. That is the sensor's address. I was more pleased by this number than I have been by most salary revisions. - Installed the Python library. Here I met the first surprise: Raspberry Pi OS refuses
pip installsystem-wide now, with the message "externally-managed-environment". My grandson explained virtual environments, which reminded me of having a separate load library for each application. Some ideas simply come back with new names.
python3 -m venv /home/ram/wx
/home/ram/wx/bin/pip install RPi.bme280
The program itself is short. I wrote it in vi. Not Vim. vi.
import smbus2, bme280, sqlite3, time
bus = smbus2.SMBus(1)
cal = bme280.load_calibration_params(bus, 0x76)
d = bme280.sample(bus, 0x76, cal)
con = sqlite3.connect('/home/ram/weather.db')
con.execute("INSERT INTO readings VALUES (?, ?, ?, ?)",
(int(time.time()), d.temperature, d.humidity, d.pressure))
con.commit()
con.close()
And one line in the crontab, which needed no explanation from anybody, as cron is older than my grandson's father:
*/10 * * * * /home/ram/wx/bin/python /home/ram/read.py
Mistakes
- On the first sunny day the station reported 47 degrees. Chennai is hot, but it is not that hot. The sensor was in direct sun. I built a small radiation shield from five white plastic plates stacked with spacers, so that air passes through but the sun does not reach the sensor. It now reads within a degree of the airport figure.
- During the first heavy rain, water entered the kitchen box. My wife has asked for a new box. The station now lives in a proper junction box from the electrical shop, with a drip loop on the cable.
- In the first week I wrote the timestamp as a string in DD-MM-YYYY format. Sorting did not work. Thirty-four years in banking and I made the oldest date mistake in the book. The integer timestamp above is the corrected version.
To the young people
Learn something new every year, however old you are. And save twenty percent of your salary from the first month. The second advice is more important than the first, but nobody listens to it until they are fifty.
With regards,
S. Ramanathan
Get the best of #raspberry_pi_lab weekly
One email each Monday with the most useful posts. No spam; unsubscribe in one click.
Comments
Sign in to join the conversation.
Sign in to comment