I'm a beginner with microcontrollers, my first project is simply to hook up a pt100 temperature sensor to my Pico to make a PID controller. I've managed to do this using circuit python and it works great but when I tried with micropython i keep getting a bad pin error. Have not been able to resolve this. The code below is a modified version of the adafruit Max31865 amplifier example code which is supplied with circuit python in mind.
Please see below for answer to "why not just use circuit python then?"
---------------------------
Code: Select all
"""Simple demo of the MAX31865 thermocouple amplifier.
Will print the temperature every second."""
import time
import machine
import adafruit_max31865
CS = machine.Pin(22, machine.Pin.OUT)
# Initialize SPI bus and sensor.
SPI = machine.SPI(0, sck=machine.Pin(24, machine.Pin.OUT),
mosi=machine.Pin(25, machine.Pin.OUT),
miso=machine.Pin(21,machine.Pin.OUT)#<-----"bad SCK pin" error originates here
)
SPI.init(baudrate=115200, polarity=0, phase=1)
#SENSOR = adafruit_max31865.MAX31865(SPI, CS)
# Note you can optionally provide the thermocouple RTD nominal, the reference
# resistance, and the number of wires for the sensor (2 the default, 3, or 4)
# with keyword args:
sensor = adafruit_max31865.MAX31865(spi, cs, rtd_nominal=100, ref_resistor=430.0, wires=3)
# Main loop to print the temperature every second.
while True:
# Read temperature.
TEMP = SENSOR.temperature
# Print the value.
print("Temperature: {0:0.3f}C".format(TEMP))
# Delay for a second.
time.sleep(1.0)
File "<stdin>", line 13, in <module>
ValueError: bad SCK pin
>>>
As to why use micro python in the first place if circuit python works - I need to measure the temperature and then calculate a PID value and then send this value to a SSR, but with circuit python I understand you can't run multithreaded operations (unlike micropython) therefore the following is happening
read temperature
calculate PID
tell SSR to turn on/off at given frequency
SSR then turns off whilst a new PID is calculated
If anyone can give me a hint on how to have the SSR still turn on/off uninterrupted whilst calculating a new frequency value in circuit python that would help too.
Many thanks for reading, any help will be really appreciated.
Regards
Jon