first commit

This commit is contained in:
pandacraft 2025-03-21 16:04:17 +01:00
commit a5a0434432
1126 changed files with 439481 additions and 0 deletions

View file

@ -0,0 +1,55 @@
## Calibrating the Grove High Temperature sensor
##### Attention:
This `README.md` is only for calibrating the probe and not the onboard sensor. So, this sensor comes with 2 thermometers:
1. One which is for measuring room temperatures - that's found on the sensor's board.
2. Another one which is for measuring temperatures between `-50 °C` and `+650 °C` - it's the long metal wire. **This is the one we're calibrating.**
## Step 1
Make the `GrovePi` continously read an analog port and print the values in the console. The analog port should be that of the `Grove High Temperature Sensor's`.
## Step 2
Put the sensor's long wire into a cup of boiling/hot water and take note of the value that's printed in the `Raspberry Pi`'s console. At the same time, use a professional thermometer and measure the temperature and write it down.
Do the same thing with cold water.
## Step 3
We will now have 4 values written down in a note:
* 2 values that were printed in the `Raspberry Pi`'s console - these values correspond with the following 2 values.
* 2 values where the measurement unit is in `Celsius Degrees` - measured with the professional thermometer.
Now, take the values that were measured with the professional thermometer and get them translated with the table provided in `thermocouple_table.json` file.
I.e: In `thermocouple_table.json` file, `90 °C` corresponds to `3.682`.
Now, lets assign the following values to each of these variables:
* `i1` = the translated value (from the table) we got when we measured the hot water w/ the **professional thermometer**.
* `i2` = the translated value (from the table) we got when we measured the cold water w/ the **professional thermometer**.
* `o1` = the value we got in our console when we measured the hot water w/ **our GrovePi**.
* `o2` = the value we got in our console when we measured the cold water w/ **our GrovePi**.
## Step 4
Let's calculate an `offset` and a `factor`. We will insert the calculated values in our table (`thermocouple_table.json` file).
First, lets calculated the `offset`.
* `offset` = `(o1 * i2 - i1 * o2) / (i2 - i1)`
And then, we get to calculate the `factor`. Use the `offset` value for calculating the `factor`.
* `factor` = `(o1 - offset) / i1`
## Step 5
Open up `thermocouple_table.json` file and update the following values:
* For `amp_offset` set the value we got for `offset` - it's preferable to have up to 6-7 digits in precision.
* For `amp_factor` set the value we got for `factor` - it's preferable to have up to 6-7 digits in precision.
Save the modifications.
## Step 6
Run the `high_temperature_example.py` program.
It's going to use the newly updated values.
------
###### `Note 1`: Calibrate the sensor when the values don't match with a professional thermometer by a long shot (i.e. 10 degrees). The sensor has already been calibrated, but who knows.
###### `Note 2`: The sensor's precision is around `+-3 Celsius Degrees`.

View file

@ -0,0 +1,120 @@
# Released under the MIT license (http://choosealicense.com/licenses/mit/).
# For more information see https://github.com/DexterInd/GrovePi/blob/master/LICENSE
import grovepi
import math
import json
import numpy as np
from scipy.interpolate import interp1d
# Library written for Python 3!
# take a look in the datasheet
# http://www.mouser.com/catalog/specsheets/Seeed_111020002.pdf
# class for the K-Type temperature sensor (w/ long probe/sonde)
class HighTemperatureSensor:
# initialize the object with the appropriate sensor pins on the GrovePi and configuration JSON
def __init__(self, _temperature_pin, _thermocouple_pin, _json_path = None):
if(_json_path is None):
_json_path = 'thermocouple_table.json'
try:
with open(_json_path) as table_file:
table = json.load(table_file)
self.__interpolateTable(table)
self.__amp_av = table["amp_factor"]
self.__vol_offset = table["amp_offset"]
except:
self.sensor_table = None
self.__amp_av = 1
self.__vol_offset = 1
self.voltage_to_degrees_table = None
# save the variables inside the object
self.temperature_pin = _temperature_pin
self.thermocouple_pin = _thermocouple_pin
# set the pins as INPUT
# this sensor outputs analog values so you can
# use one of the 3 analog ports on the GrovePi
grovepi.pinMode(self.temperature_pin, "INPUT")
grovepi.pinMode(self.thermocouple_pin, "INPUT")
# function for retrieving the room temperature_pin
# if values exceed what's written in the datasheet
# then it throws a ValueError exception
def getRoomTemperature(self):
# ratio for translating from 3.3V to 5.0V (what we read is in the range of 0 -> 3.3V)
voltage_ratio = 5.0 / 3.3
# and multiply what we read by that ratio
# and read it for about 12 times -> this way we get smoother readings
# the reason we average it is because the table we provided isn't big enough
# and as a consequence you'd get values like (20 degrees, 24 degrees and so on)
analog_sum = 0
for step in range(12):
analog_sum += grovepi.analogRead(self.temperature_pin)
pass
analog_value = (analog_sum / 12) * voltage_ratio
# see the datasheet for more information
try:
calculated_resistance = (1023 - analog_value) * 10000 / analog_value
calculated_temperature = 1 / (math.log(calculated_resistance / 10000) / 3975 + 1 / 298.15) - 273.15
# if the values exceed a certain threshold
# then raise a ValueError exception
if not (calculated_temperature >= -50.0 and calculated_temperature <= 145.0):
raise ValueError('temperature out of range')
# and return what we got calculated
return calculated_temperature
except ZeroDivisionError:
return 0
# function for retrieving the temperature at the tip of the probe / sonde
# only the temperature of the tip of the probe is measured
# the rest of the K-Type sensor is for reaching the hot environment you want to measure
# so you don't get burned
def getProbeTemperature(self):
if not self.voltage_to_degrees_table is None:
probe_tip_voltage = self.__getThermocoupleVoltage()
degrees_from_table = self.voltage_to_degrees_table(probe_tip_voltage)
return float(degrees_from_table)
else:
return None
# private function which can't be accessed from the outside
# this is an imperitave solution - it was found through experiments
# basically it calculates the voltage of the K-type sensor
# before it gets into the amplifier - so the voltage is between -6.48 mV to 54.9 mV
def __getThermocoupleVoltage(self):
analog_value = grovepi.analogRead(self.thermocouple_pin);
probe_tip_voltage = (analog_value - self.__vol_offset) / self.__amp_av
return probe_tip_voltage
# function for interpolating values from [table] array
def __interpolateTable(self, table):
degrees_keys_list = list(table["degrees_table"].keys())
degrees_list = [int(x) for x in degrees_keys_list]
voltages_list = []
for degrees in degrees_keys_list:
voltage_corespondent = table["degrees_table"][degrees]
voltages_list.append(voltage_corespondent)
self.voltage_to_degrees_table = interp1d(voltages_list, degrees_list)

View file

@ -0,0 +1,83 @@
#!/usr/bin/env python3
# -*- coding: utf8 -*-
#
# The GrovePi connects the Raspberry Pi and Grove sensors. You can learn more about GrovePi here: http://www.dexterindustries.com/GrovePi
#
# Have a question about this example? Ask on the forums here: http://forum.dexterindustries.com/c/grovepi
#
'''
## License
The MIT License (MIT)
GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Raspberry Pi.
Copyright (C) 2017 Dexter Industries
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''
import grove_hightemperature_sensor as grovepi # our library
from time import sleep # and for the sleep function
import sys # we need this for the exception throwing stuff
# Don't forget to run it with Python 3 !!
# Don't forget to run it with Python 3 !!
# Don't forget to run it with Python 3 !!
def Main():
room_temperature_pin = 15 # this is equal to A1
probe_temperature_pin = 14 # this is equal to A0
# so you have to connect the sensor to A0 port
# instatiate a HighTemperatureSensor object
sensor = grovepi.HighTemperatureSensor(room_temperature_pin, probe_temperature_pin)
# and do this indefinitely
while True:
# read the room temperature
room_temperature = sensor.getRoomTemperature()
# and also what's important to us: the temperature at the tip of the K-Type sensor
probe_temperature = sensor.getProbeTemperature()
# print it in a fashionable way
print('[room temperature: {:5.2f}°C][probe temperature: {:5.2f}°C]'.format(room_temperature, probe_temperature))
# and wait for 250 ms before taking another measurement - so we don't overflow the terminal
sleep(0.25)
if __name__ == "__main__":
try:
Main()
# in case CTRL-C / CTRL-D keys are pressed (or anything else that might interrupt)
except KeyboardInterrupt:
print('[Keyboard interrupted]')
sys.exit(0)
# in case there's an IO error aka I2C
except IOError:
print('[IO Error]')
sys.exit(0)
# in case we have a math error (like division by 0 - can happen depending on the read values)
# or if the values exceed a certain threshold
# experiment and you'll see
except ValueError as e:
print('[{}]'.format(str(e)))
sys.exit(0)

File diff suppressed because it is too large Load diff