Approved content

The content below is provided by a partner.

KitronikLtd/pxt-kitronik-air-quality 1.0.14 GitHub

Open this page at https://kitronikltd.github.io/pxt-kitronik-air-quality/

Use as Extension

This repository can be added as an extension in MakeCode.

ZIP LEDs

The ZIP LEDs section contains blocks for controlling the 3 onboard status LEDs.
Note: Any block which does not have “show” in the name needs to be followed by a ||kitronik_air_quality.show|| block to make the changes visible.

The first block sets up the ZIP LEDs as a variable, enabling them to be controlled in the program.

let statusLEDs = kitronik_air_quality.createAirQualityZIPDisplay()

To set the colour of all the ZIP LEDs (or a whole range), use the ||kitronik_air_quality.set color|| block. To view the changes there needs to be a ||kitronik_air_quality.show|| block after this block.

let statusLEDs: kitronik_air_quality.statusLEDs = null
statusLEDs.setColor(kitronik_air_quality.colors(ZipLedColors.Red))

To set the colour of all the ZIP LEDs (or a whole range) and then show the change, use the ||kitronik_air_quality.show color|| block.

let statusLEDs: kitronik_air_quality.statusLEDs = null
statusLEDs.showColor(kitronik_air_quality.colors(ZipLedColors.Red))

To set the colour of an individual LED, use the ||kitronik_air_quality.set ZIP LED|| block. To view the changes there needs to be a ||kitronik_air_quality.show|| block after this block.

let statusLEDs: kitronik_air_quality.statusLEDs = null
statusLEDs.setZipLedColor(1, kitronik_air_quality.colors(ZipLedColors.Green))

The ||kitronik_air_quality.show|| block makes visible the changes made since the last ||kitronik_air_quality.show||.

let statusLEDs: kitronik_air_quality.statusLEDs = null
statusLEDs.show()

To turn the LEDs off, use the ||kitronik_air_quality.clear|| block. To view the changes there needs to be a ||kitronik_air_quality.show|| block after this block.

let statusLEDs: kitronik_air_quality.statusLEDs = null
statusLEDs.clear()

||kitronik_air_quality.rotate|| moves each LED colour setting along the chain, and then takes the end one back to the first. To view the changes there needs to be a ||kitronik_air_quality.show|| block after this block.

let statusLEDs: kitronik_air_quality.statusLEDs = null
statusLEDs.rotate(1)

The brightness of the LEDs can be controlled with the ||kitronik_air_quality.set brightness|| block. To view the changes there needs to be a ||kitronik_air_quality.show|| block after this block.

let statusLEDs: kitronik_air_quality.statusLEDs = null
statusLEDs.setBrightness(180)

The final three blocks in the ZIP LEDs section are all different ways of choosing or setting a colour for the LEDs.

Display

These blocks are used to control the OLED display on the board.
It is split into 8 lines, all of which can be used to display text (up to 26 characters in length).

Text, Numbers and values stored in variables can all be displayed using the ||kitronik_air_quality.show|| block.
The block can be expanded to select which line should be used (the default is always the top of the screen, line 1).

kitronik_air_quality.show("Some text on line 3", 3)

The other two blocks are used for clearing the display, either an individual line, or the entire screen:

kitronik_air_quality.clearLine(3)
kitronik_air_quality.clear()

Clock

These blocks are laid out in groups of linked functionality.

Set Time

This block is used to set the time on the Real Time Clock (RTC) chip.

kitronik_air_quality.setTime(11, 45, 30)

Set Date

This block is used to set the date on the RTC chip.

kitronik_air_quality.setDate(10, 9, 20)

Read Time

These blocks are used to read the current time as either a string of the complete time, or the individual elements as numbers.

basic.showString(kitronik_air_quality.readTime())
basic.showNumber(kitronik_air_quality.readTimeParameter(TimeParameter.Hours))
basic.showNumber(kitronik_air_quality.readTimeParameter(TimeParameter.Minutes))
basic.showNumber(kitronik_air_quality.readTimeParameter(TimeParameter.Seconds))

Read Date

These blocks are used to read the current date as either a string of the complete date, or the individual elements as numbers.

basic.showString(kitronik_air_quality.readDate())
basic.showNumber(kitronik_air_quality.readDateParameter(DateParameter.Day))
basic.showNumber(kitronik_air_quality.readDateParameter(DateParameter.Month))
basic.showNumber(kitronik_air_quality.readDateParameter(DateParameter.Year))

Alarm

The ||kitronik_air_quality.set alarm|| block allows the user to input a time for an alarm to trigger either once, or repeating daily. The alarm can either be silenced by the user, or silenced automatically.

kitronik_air_quality.simpleAlarmSet(kitronik_air_quality.AlarmType.Single, 9, 30, kitronik_air_quality.AlarmSilence.autoSilence)

The ||kitronik_air_quality.on alarm trigger|| bracket block and ||kitronik_air_quality.alarm triggered|| block both allow actions to be carried out when the alarm goes off.

kitronik_air_quality.onAlarmTrigger(function () {
    music.startMelody(music.builtInMelody(Melodies.PowerUp), MelodyOptions.Once)
})
basic.forever(function () {
    if (kitronik_air_quality.simpleAlarmCheck()) {
        music.startMelody(music.builtInMelody(Melodies.PowerUp), MelodyOptions.Once)
    }
})

The ||kitronik_air_quality.turn off alarm|| block allows the alarm to be silenced by the user.

input.onButtonPressed(Button.A, function () {
    kitronik_air_quality.simpleAlarmOff()
})

Sensors

These blocks are used to control and take readings from the BME688 Air Quality and Environmental sensor.
These blocks are laid out in groups of linked functionality.

Setup

The Temperature, Pressure and Humidity sections of the sensor will work straight away, but the gas sensor (which is used for the Air Quality measurements) needs to be setup.
The first block sets the correct gas plate temperature and heating time (300°C and 150ms).
The second block takes a series of gas resistance and temperature measurements over a 5 minute period (the board will not be useable during this time).
These values are then averaged to provide baselines which are then used in the air quality calculations.

kitronik_air_quality.setupGasSensor()
kitronik_air_quality.calcBaselines()

Measure

This block carries out the read process for all sections of the sensor: Temperature, Pressure, Humidity and Gas Resistance.
It needs to be called before individual values are read or data is logged.

kitronik_air_quality.measureData()

Climate

These blocks are used to take Temperature (°C or °F), Pressure (Pa or mBar) and Humidity (%) readings, which output as numbers.

basic.showNumber(kitronik_air_quality.pressure(PressureUnitList.Pa))
basic.showNumber(kitronik_air_quality.temperature(TemperatureUnitList.C))
basic.showNumber(kitronik_air_quality.humidity())

Air Quality

These blocks are used to take Air Quality readings and calculate the estimated CO2 level (all output as numbers).
Air Quality can be given as an IAQ (Index of Air Quality) Score [0 - 500: 0 = Very Good, 500 = Very Bad] or as a percentage [0 - 100%,: 0 = Very Bad, 100% = Very Good].

basic.showNumber(kitronik_air_quality.getAirQualityScore())
basic.showNumber(kitronik_air_quality.getAirQualityPercent())
basic.showNumber(kitronik_air_quality.readeCO2())

Data Logging

The Data Logging blocks are used to organise and format measured information, and then transfer this information to a computer connected to the micro:bit via USB.
Several things are setup automatically in the background:

The blocks are laid out in groups of linked functionality.

Setup

This block is used to add project information (Name and Subject) to the data logging output.

Note: The pound stirling symbol (“£“) must NOT be used in either text field as it is the end of line character.

kitronik_air_quality.addProjectInfo("My Name", "My Subject")

Add Data

The ||kitronik_air_quality.log data|| block is used add a data entry to the data store (the entry will automatically include: Date, Time, Temperature, Pressure, Humidity, IAQ Score, eCO2 and Light Level).
Note: There is a maxmium of 1000 data entries - if this is exceeded, the first data in the memory will start to be overwritten.

input.onButtonPressed(Button.A, function () {
    kitronik_air_quality.logData()    
})

The ||kitronik_air_quality.erase all data|| block does exactly what it says: it removes all the previously stored data entries.

input.onButtonPressed(Button.B, function () {
    kitronik_air_quality.eraseData()
})

Transfer

Once data has been collected, it will need to be transferred to a connected computer (all the data entries are transmitted at once).
In order to see the transmitted data, a serial port monitor needs to be used.
If the micro:bit is connected to MakeCode via WebUSB, the built in serial monitor can be used and the output can then be copied from there into a separate file, or a dedicated serial monitor program can be downloaded.

input.onButtonPressed(Button.A, function () {
    kitronik_air_quality.sendAllData()
})

License

MIT

Metadata (used for search, rendering)

kitronik-air-quality=github:KitronikLtd/pxt-kitronik-air-quality#v1.0.14