Repository for sharing code and information during the PTEE conference workshop.
During the workshop, you will work with a Raspberry Pi Pico and a SEN63C environmental sensor. You will also use 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.
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. All functions are documented and care is taken to optimally connect the sensor to the microcontroller (where supplementary electronics are either worked out or implemented).
The learninggoal is assessed with the following rubric:
| Points | Description |
|---|---|
| 30 pt | The student can control different sensors using different interfaces and can store measured data in a meaningful format. The code is well documented, and the sensors are used optimally with supplementary electronic hardware, either implemented or worked out on paper. |
| 25 pt | The student can control different sensors using different interfaces and can store measured data in a meaningful format. The code is well documented. |
| 20 pt | The student can control different sensors and store measured data in a meaningful format. The code is well documented. |
| 10 pt | The student can control different sensors and store measured data in a meaningful format. |
| 0 pt | The student cannot control a sensor. |
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.
Copy the code into a Thonny window and run it using the MicroPython environment on the Raspberry Pi Pico. 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 = FalseIf 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 = FalseCan you write a program that prints the temperature and toggles the LED every tenth measurement?
Continue working with the SEN63-C sensor.