Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PTEE – Sensors, microcontrollers and rubrics: How Do They Connect?

Repository for sharing code and information during the PTEE and SEFI conference workshop.

Materials

During the workshop, you will work with a Raspberry Pi Pico and a SEN63C environmental sensor. You will also use the internal temperature sensor. During the SEFI workshop the focus will be on the internal temperature sensor.

We have collected some materials that you can use during the workshop. The aim is for you to work with the hardware rather than to develop the supporting software from scratch. We take the same approach in our classes and share drivers with students who are working with the hardware. These drivers are either found online or written by us.

Assessment Rubric

Learninggoal:

Write (micro)python code which can collect data from sensors. The code is documented and produces output which is stored in a meaningful format. Care is taken to optimally connect the sensor to the microcontroller (where supplementary electronics are either worked out on paper or implemented).

The learninggoal is assessed with the following rubric:

Points Description
100 The student has full control over the hardware, including all sensors, actuators, and the resulting data. They can independently use alternative interfaces and produce well-documented, reusable code that is suitable for future work. Hardware limitations are minimised through implemented electronic solutions or through fully documented circuit designs. Sensor performance is validated with appropriate evidence, such as calibration, repeatability, accuracy, or error measurements.
80 The student obtains reliable, validated data from the sensors and operates the actuator as intended. Validation is supported by appropriate evidence, such as calibration, repeatability, accuracy, or error measurements. The code is well documented and structured for future reuse. The hardware configuration is used effectively but is not modified to address its limitations. The data have been collected and are usable, although further processing or analysis may be required for future research.
60 The student obtains data from the sensor and interfaces with the actuator. The sensor data may be correct, but have not been adequately validated; for example, calibration, repeatability, accuracy, or error measurements are missing. The code is documented, but is not sufficiently structured or reusable for future work.
40 The student obtains data from the sensor and activates the actuator, but the data are not supported by evidence of reliability or validation. The code is undocumented or requires substantial revision before it can be reused in a future implementation.
0 The student cannot obtain data from a sensor or operate an actuator.

MicroPython and Thonny

There are several options for programming a Raspberry Pi Pico with MicroPython, but my preferred tool is Thonny. Follow the instructions on the website to set up a working environment.

Software – Reading the Temperature

Copy the code into a Thonny window and run it using the MicroPython environment on the Raspberry Pi Pico (check the Python environment in the right-lower corner of the Thonny window). You should see the current timestamp and temperature printed in the REPL (Read-Evaluate-Print Loop) window.

import machine
import time


def readTemperature(adc):
    # Convert the 16-bit ADC value to a voltage (0–3.3 V)
    adc_v = (3.3 / (2**16 - 1)) * adc.read_u16()
    # From the RP2350 datasheet (p. 1073)
    temp = 27 - (adc_v - 0.706) / 0.001721
    return temp


adc = machine.ADC(4)         # Temperature sensor on ADC4
running = True               # Stop the while loop when done
while running:
    try:
        print(time.time(), readTemperature(adc))
        time.sleep(1)        # Measure once per second
    except KeyboardInterrupt:  # Ctrl+C pressed; stop the loop
        running = False

Here you read the Analogue to Digital (ADC) pin 4 which is connected to the internal temperature sensor. The value is a 12 bit readout, stored in a 16 bit number. With the reference voltage (3.3V or you should measure it!) you can convert the ADC readout to a voltage. With the Raspberrypi Datasheet the conversion between measuered voltage and temperature can be obtained.

The code keeps running until you press CTRL-C. Halting the loop and returning to the REPL.

Software – Blinking the LED

If you want to blink the onboard LED, you can use the following code:

import machine
import time

led = machine.Pin('LED', machine.Pin.OUT)

running = True
while running:
    try:
        led.value(1)
        time.sleep(0.5)
        led.value(0)
        time.sleep(0.5)
    except KeyboardInterrupt:
        running = False

Where the interal LED is activated using the name 'LED' as pin-number. When using the Raspberry Pi Pico without the wireless chip the LED is connected trough pin 25. Can you write a program that prints the temperature and toggles the LED every tenth measurement?

SEN63-C

The SEN63-C is an all-in-one sensor solution which meassures the indoor climate. With just one cable you have access to temperature, humidity, particulate matter and CO2 concentrations. Continue working with the SEN63-C sensor.

About

Repository for sharing of code and information during the PTEE conference.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages