We're Here To Help: (877) MAKER75 | info@makermaven.net

Environmental monitoring with the pi-top [4]

Article by David Sutton

The aim of this project was to create a working demonstration of Environmental Modelling. The system should be able to be built or enhanced by a Code Club, and also be used as a model to illustrate more advanced computing to Science Groups. A further aim was to introduce beginners to the world of Single Board Computers.

DESIGN

Being new to the pi-top [4] (although I’ve had a pi-top [3] for some time), I spent a few weeks getting used to it and the nuances of different language options that could be used for this project. I find it’s always better to verify that things will work as expected, before starting on something new.

To tie in with a planned talk to a Science Group, I decided on Environmental Modelling with a focus on natural disasters. New Zealand was an obvious choice is it suffers from both Earthquakes and Volcanos and uses advanced IT to predict them.

As I want this to be a fun project, I’m using LEGO for a physical model, simple robotics using Meccano, a pi-top [4] and sensors, and Micro:bits. I also want to do some interesting art work (an associated program).

SOLUTION

I’ll jump straight to the solution.

If you look closely you will see red circles around Christchurch and Wellington, and a white circle around Rotorua. Red illustrates a potential problem and white, everything is OK. At the bottom of the Mu Display, you may be able to make out a row of Environmental Monitoring Data.

There is a Micro:bit attached to the pi-top [4] that does the monitoring for Rotorua. You may also be able to make out the Air Quality sensor, attached to the top of the pi-top. This is used to monitor Co2 and TVOC (Total Volatile Organic Compounds). The symbols on the picture show where the robot, sensor and control are situated.

This shows the LEGO display sitting below the pi-top. The LEGO display is simple but hopefully shows recognisable points of interest in the cities and town (Cathedral Square Christchurch, Beehive Wellington, Wai-O-Tapu Rotorua). The red lights turn on to indicate potential earthquake problems. The yellow light indicates potential volcanic activity in Rotorua. I am using a simple robot, which is controlled by a Micro:bit, which I built some time ago. This is situated in Christchurch. The front Micro:bit is situated in Wellington. There is also a buzzer from the pi-top Sensor Foundation Kit.

HOW IT WORKS

The robot and Micro:bit, shown in the picture above, are situated in different places in the room rather than next to each other.

Pressing buttons “A” or “B” on the Micro:bit connected on to the pi-top, will drive the remote robot forward or backwards. Nothing more than this! This is to illustrate how a sensor on a robot can be moved to different locations and controlled from a central unit.

If either of the Micro:bits situated at Wellington or Christchurch are shaken, this will be registered.

Pressing button “A” on the Micro:bits will send both the shaken condition and the temperature to the controlling Micro:bit connected to the pi-top.

Pressing “A” and “B” on the controlling Micro:bit will send all readings to the pi-top.

When the pi-top receives the readings it will create a CSV file. It will also take eCO2 and VTOC readings from the Air Quality sensor and create a separate CSV file. Both files will have a common reference number and the same time stamp.

Libra Office Calc is used to combine the 2 files.

The Display program reads the combined file, turns on LEDS, sounds the buzzer and draws circles on the maps of New Zealand. The sequence is: When a potential disaster situation is identified the buzzer sounds and the appropriate LEDs light up to alert people; The LEDs and buzzer then switch off and the potential problem is shown on the maps by red circles. All monitoring data including vibration, temperature, VTOC and eCO2 is output to the Mu display line.

A LITTLE MORE DETAIL

The Micro:bits are connected using their standard “Radio” function.

The robot is based on a “move” robot with the chassis replaced with Meccano. “Move” provide an extension library for Micro:bit MakeCode. All Mico:bit code is written in the MakeCode Block language.

It's worth noting that the robot also has a MeArm robot arm, which can be controlled by the Micro:bit. It isn’t used in this project but it would be simple to add additional code to control it.

Micro:bit MakeCode has a Serial function that allows data to be exchanged with a central computer over USB. This was used to send data from the Control Micro:bit to a python program running on the pi-top. Python has a Serial library for reading and writing Serial Data.

In addition to using the Block based Micro:bit language, I also tried out Micropython on the Micro:bit. See 'Using Micropython' below for more information.

CSV files are commonly used for Data Analytics and AI. I use this file type for storing the sensor readings. These files can also be easily read into a spreadsheet and manipulated. Python has a CSV library which makes reading and writing them relatively simple. In addition to writing data values, you can also write header information containing the names of data fields. I do this.

The display of New Zealand and the placing of red and white circles is done using Python Game Zero. Game Zero is a sub-set of Python Game. The same program also uses pi-top libraries to switch on LEDs and a buzzer.

ADDITIONAL PROGRAM

While working on this project, I had a brief break where I designed something a bit more artistic. The idea was to convert a program I had previously written in “Processing” into “Scratch” and use the Air Quality sensor to modify the design in real time. Python reads the sensor data and sends sensor information to Scratch. This is done by using GPIO pins. Processing, Scratch and Python can all read and write GPIO pins. I generally Pull pins Up or Down in one program and read them in another.

This Scratch program starts and finishes with this picture of an image that slowly forms. Breathing on the sensor changes the colours. Only blue and red are used unless you breathe deeply. Alternatively burning a candle and capturing the Co2 in a cup that is then placed over the sensor, works equally well.

This is a picture of the image, just after you start to breathe on the sensor.

There are two versions of this program. One runs on any computer and mimics breathing on a sensor.

This link will run the PC version. Make sure you run Scratch in Turbo Mode and follow the instructions.

USING MICROPYTHON

Micropython is different from Python. It is a cut down version designed for microprocessors. Only a few microprocessors can actually run it. The Micro:bit is one of these. It has a facility called REPL that allows code written in Mu to be run directly on the Micro:bit. I tend to write functions for the Micro:bit in Micropython, download them and then call them from Mu. This works OK but didn’t provide any benefits for this project. I therefore tried a few things out but decided not to use it.

David Sutton is a retired IT director and supports a local Code Code Club in the North West of England. David also gives talks and demonstrations on IT and future technologies.

Leave a comment

Please note, comments must be approved before they are published