IP Configuration
This commit is contained in:
24
lib/Arduino_MKRTHERM/README.adoc
Normal file
24
lib/Arduino_MKRTHERM/README.adoc
Normal file
@@ -0,0 +1,24 @@
|
||||
= MKRTHERM Library for Arduino =
|
||||
|
||||
Allows you to read the temperature sensors connected to your MKR THERM shield.
|
||||
|
||||
For more information about this library please visit us at https://www.arduino.cc/en/Reference/Arduino_MKRTHERM
|
||||
|
||||
|
||||
== License ==
|
||||
|
||||
Copyright (c) 2019 Arduino SA. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
43
lib/Arduino_MKRTHERM/examples/ReadSensor/ReadSensor.ino
Normal file
43
lib/Arduino_MKRTHERM/examples/ReadSensor/ReadSensor.ino
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
MKR THERM Shield - Read Sensors
|
||||
|
||||
This example reads the temperatures measured by the thermocouple
|
||||
connected to the MKR THERM shield and prints them to the Serial Monitor
|
||||
once a second.
|
||||
|
||||
The circuit:
|
||||
- Arduino MKR board
|
||||
- Arduino MKR THERM Shield attached
|
||||
- A K Type thermocouple temperature sensor connected to the shield
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Arduino_MKRTHERM.h>
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
while (!Serial);
|
||||
|
||||
if (!THERM.begin()) {
|
||||
Serial.println("Failed to initialize MKR THERM shield!");
|
||||
while (1);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Serial.print("Reference temperature ");
|
||||
Serial.print(THERM.readReferenceTemperature());
|
||||
Serial.println(" °C");
|
||||
|
||||
Serial.print("Temperature ");
|
||||
Serial.print(THERM.readTemperature());
|
||||
Serial.println(" °C");
|
||||
|
||||
Serial.println();
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
23
lib/Arduino_MKRTHERM/keywords.txt
Normal file
23
lib/Arduino_MKRTHERM/keywords.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For Arduino_MKRTHERM
|
||||
#######################################
|
||||
# Class
|
||||
#######################################
|
||||
|
||||
Arduino_MKRTHERM KEYWORD1
|
||||
MKRTHERM KEYWORD1
|
||||
THERM KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions
|
||||
#######################################
|
||||
|
||||
begin KEYWORD2
|
||||
end KEYWORD2
|
||||
|
||||
readTemperature KEYWORD2
|
||||
readReferenceTemperature KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants
|
||||
#######################################
|
||||
10
lib/Arduino_MKRTHERM/library.properties
Normal file
10
lib/Arduino_MKRTHERM/library.properties
Normal file
@@ -0,0 +1,10 @@
|
||||
name=Arduino_MKRTHERM
|
||||
version=1.0.0
|
||||
author=Arduino
|
||||
maintainer=Arduino <info@arduino.cc>
|
||||
sentence=Allows you to read the temperature sensors connected to your MKR THERM shield.
|
||||
paragraph=
|
||||
category=Sensors
|
||||
url=https://github.com/arduino-libraries/Arduino_MKRTHERM
|
||||
architectures=samd
|
||||
includes=Arduino_MKRTHERM.h
|
||||
25
lib/Arduino_MKRTHERM/src/Arduino_MKRTHERM.h
Normal file
25
lib/Arduino_MKRTHERM/src/Arduino_MKRTHERM.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
This file is part of the Arduino_MKRTHERM library.
|
||||
Copyright (c) 2019 Arduino SA. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _ARDUINO_MKRTHERM_H_
|
||||
#define _ARDUINO_MKRTHERM_H_
|
||||
|
||||
#include "MKRTHERM.h"
|
||||
|
||||
#endif
|
||||
126
lib/Arduino_MKRTHERM/src/MKRTHERM.cpp
Normal file
126
lib/Arduino_MKRTHERM/src/MKRTHERM.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
This file is part of the Arduino_MKRTHERM library.
|
||||
Copyright (c) 2019 Arduino SA. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "MKRTHERM.h"
|
||||
|
||||
THERMClass::THERMClass(int cs, SPIClass& spi) :
|
||||
_cs(cs),
|
||||
_spi(&spi),
|
||||
_spiSettings(4000000, MSBFIRST, SPI_MODE0)
|
||||
{
|
||||
}
|
||||
|
||||
int THERMClass::begin()
|
||||
{
|
||||
uint32_t rawword;
|
||||
|
||||
pinMode(_cs, OUTPUT);
|
||||
digitalWrite(_cs, HIGH);
|
||||
_spi->begin();
|
||||
|
||||
rawword = readSensor();
|
||||
if (rawword == 0xFFFFFF) {
|
||||
end();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void THERMClass::end()
|
||||
{
|
||||
pinMode(_cs, INPUT);
|
||||
digitalWrite(_cs, LOW);
|
||||
_spi->end();
|
||||
}
|
||||
|
||||
uint32_t THERMClass::readSensor()
|
||||
{
|
||||
uint32_t read = 0x00;
|
||||
|
||||
digitalWrite(_cs, LOW);
|
||||
delayMicroseconds(1);
|
||||
|
||||
_spi->beginTransaction(_spiSettings);
|
||||
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
read <<= 8;
|
||||
read |= _spi->transfer(0);
|
||||
}
|
||||
|
||||
_spi->endTransaction();
|
||||
|
||||
digitalWrite(_cs, HIGH);
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
float THERMClass::readTemperature()
|
||||
{
|
||||
uint32_t rawword;
|
||||
float celsius;
|
||||
|
||||
rawword = readSensor();
|
||||
|
||||
// Check for reading error
|
||||
if (rawword & 0x7) {
|
||||
return NAN;
|
||||
}
|
||||
// The temperature is stored in the last 14 word's bits
|
||||
// sendend by the Thermocouple-to-Digital Converter
|
||||
if (rawword & 0x80000000) {
|
||||
// Negative value, drop the lower 18 bits and explicitly extend sign bits.
|
||||
rawword = 0xFFFFC000 | ((rawword >> 18) & 0x00003FFFF);
|
||||
} else {
|
||||
// Positive value, just drop the lower 18 bits.
|
||||
rawword >>= 18;
|
||||
}
|
||||
// multiply for the LSB value
|
||||
celsius = rawword * 0.25f;
|
||||
|
||||
return celsius;
|
||||
}
|
||||
|
||||
float THERMClass::readReferenceTemperature()
|
||||
{
|
||||
uint32_t rawword;
|
||||
float ref;
|
||||
|
||||
rawword = readSensor();
|
||||
|
||||
// ignore first 4 FAULT bits
|
||||
rawword >>= 4;
|
||||
|
||||
// The cold junction reference temperature is stored in the first 11 word's bits
|
||||
// sendend by the Thermocouple-to-Digital Converter
|
||||
rawword = rawword & 0x7FF;
|
||||
// check sign bit and convert to negative value.
|
||||
if (rawword & 0x800) {
|
||||
ref = (0xF800 | (rawword & 0x7FF))*0.0625;
|
||||
} else {
|
||||
// multiply for the LSB value
|
||||
ref = rawword * 0.0625f;
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
THERMClass THERM;
|
||||
46
lib/Arduino_MKRTHERM/src/MKRTHERM.h
Normal file
46
lib/Arduino_MKRTHERM/src/MKRTHERM.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
This file is part of the Arduino_MKRTHERM library.
|
||||
Copyright (c) 2019 Arduino SA. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _MKRTHERM_H_
|
||||
#define _MKRTHERM_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
|
||||
class THERMClass {
|
||||
public:
|
||||
THERMClass(int cs = A4, SPIClass& spi = SPI);
|
||||
|
||||
int begin();
|
||||
void end();
|
||||
|
||||
float readTemperature();
|
||||
float readReferenceTemperature();
|
||||
|
||||
private:
|
||||
uint32_t readSensor();
|
||||
|
||||
int _cs;
|
||||
SPIClass* _spi;
|
||||
SPISettings _spiSettings;
|
||||
};
|
||||
|
||||
extern THERMClass THERM;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user