Recording readings with datalogger.log()

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Recording readings with datalogger.log()

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line saves a temperature reading as a row in the micro:bit data log?
A datalogger.log("temperature")
B datalogger.log(datalogger.createCV("temperature", input.temperature()))
2. What does each call to datalogger.log() do?
A Replaces the whole data log with one row
B Adds a new row to the data log
3. In datalogger.createCV("temperature", input.temperature()), what is "temperature"?
A The column name for the reading
B The temperature value in degrees
4. You want a reading saved every second for a minute. Where should datalogger.log() go?
A Inside a loop, such as basic.forever()
B Once at the very start of the program
5. Do you need to write code to record the time of each row?
A No, the micro:bit adds a timestamp to each row
B Yes, you must create a time column yourself

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1datalogger.log(datalogger.createCV("temperature", input.temperature())) ASaves one new row in the data log with a column called temperature holding the current temperature reading
2datalogger.log(datalogger.createCV("temp", input.temperature()), datalogger.createCV("light", input.lightLevel())) Bbasic.forever(function () { datalogger.log(datalogger.createCV("temperature", input.temperature())) basic.pause(5000) })
3To record readings over time, put datalogger.log() inside a loop so each pass adds a new row to the log Cbasic.forever(function () { datalogger.log(datalogger.createCV("temperature", input.temperature())) })
4Pausing between logs spaces the readings out, for example one row every 5 seconds DSaves one row with two columns, temp and light, so two readings are recorded together at the same moment
5datalogger.log("temperature", input.temperature()) EThe reading is not wrapped in datalogger.createCV(), so the column name and value are not paired properly for the log.
6datalogger.log(datalogger.createCV("temperature", input.temperature)) Finput.temperature is missing its brackets (), so the function is never called and no reading is taken.

Definitions

datalogger.log()

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
datalogger.___( datalogger.createCV("temperature", input.temperature()))
2.
datalogger.log( datalogger.________("temperature", input.temperature()))
3.
basic._______(() => datalogger.log( datalogger.createCV("temperature", input.temperature())))
4.
datalogger.log( datalogger.createCV("l", input.__________()), datalogger.createCV("s", input.soundLevel()))
5.
datalogger.log( datalogger.createCV("temperature", input.___________()))

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A datalog.log(
B datalogger.createCV("temp",
C input.temperature()))
Question 2
A basic.forever(function () {
B datalogger.log(
C datalogger.createCV(tmp,
D input.temperature()))
E basic.pause(5000)
F })
Question 3
A for (let i = 0; i < 10; i--) {
B datalogger.log(
C datalogger.createCV("tmp",
D input.temperature()))
E basic.pause(1000)
F }
Question 4
A datalogger.log(
B datalogger.createCv("temp",
C input.temperature()),
D datalogger.createCV("light",
E input.lightLevel()))
Question 5
A basic.forever(function () {
B datalogger.save(
C datalogger.createCV("tmp",
D input.temperature()))
E basic.pause(1000)
F })

Answer Key

Recording readings with datalogger.log()
Section A: Quick Questions
Q1
B — datalogger.log(datalogger.createCV("temperature", input.temperature()))
Q2
B — Adds a new row to the data log
Q3
A — The column name for the reading
Q4
A — Inside a loop, such as basic.forever()
Q5
A — No, the micro:bit adds a timestamp to each row
Section B: Match the Pairs
Q1
datalogger.log(datalogger.createCV("temperature", input.temperature())) → Saves one new row in the data log with a column called temperature holding the current temperature reading
Q2
datalogger.log(datalogger.createCV("temp", input.temperature()), datalogger.createCV("light", input.lightLevel())) → Saves one row with two columns, temp and light, so two readings are recorded together at the same moment
Q3
To record readings over time, put datalogger.log() inside a loop so each pass adds a new row to the log → basic.forever(function () { datalogger.log(datalogger.createCV("temperature", input.temperature())) })
Q4
Pausing between logs spaces the readings out, for example one row every 5 seconds → basic.forever(function () { datalogger.log(datalogger.createCV("temperature", input.temperature())) basic.pause(5000) })
Q5
datalogger.log("temperature", input.temperature()) → The reading is not wrapped in datalogger.createCV(), so the column name and value are not paired properly for the log.
Q6
datalogger.log(datalogger.createCV("temperature", input.temperature)) → input.temperature is missing its brackets (), so the function is never called and no reading is taken.
Section C: Definitions
Q1
datalogger.log() — Saves one row of named sensor readings, with a timestamp, in the micro:bit data log. Each call adds a new row, so use it in a loop to record readings over time.
Section D: Fill in the Blanks
Q1
datalogger.log( datalogger.createCV("temperature", input.temperature()))
Q2
datalogger.log( datalogger.createCV("temperature", input.temperature()))
Q3
basic.forever(() => datalogger.log( datalogger.createCV("temperature", input.temperature())))
Q4
datalogger.log( datalogger.createCV("l", input.lightLevel()), datalogger.createCV("s", input.soundLevel()))
Q5
datalogger.log( datalogger.createCV("temperature", input.temperature()))
Section E: Spot the Error
Q1
A — The object is called datalogger, not datalog. The line should start datalogger.log( so the row is saved in the micro:bit data log.
Q2
C — The column name must be a string in quotes. It should be datalogger.createCV("tmp", so the log has a named column.
Q3
A — i-- makes i count down, so i < 10 is always true and the loop never stops. It should be i++ so the loop logs exactly 10 rows.
Q4
B — Function names are case sensitive. It must be createCV with a capital V, not createCv.
Q5
B — There is no datalogger.save(). The command that adds a row to the data log is datalogger.log(.