0.1.2 MAX6675

This commit is contained in:
rob tillaart 2022-11-16 13:14:42 +01:00
parent 1625643c25
commit f46f99898f
8 changed files with 82 additions and 60 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -9,3 +24,4 @@ compile:
- esp32
# - esp8266
# - mega2560
- rpipico

View File

@ -0,0 +1,19 @@
# Change Log MAX6675
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.2] - 2022-11-16
- add RP2040 in build-CI
- add changelog.md
## [0.1.1] - 2022-04-20
- updated documentation after tests with UNO.
- added examples
## [0.1.0] - 2022-01-11
- initial version.

View File

@ -1,15 +1,12 @@
//
// FILE: MAX6675.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.2
// PURPOSE: Arduino library for MAX6675 chip for K type thermocouple
// DATE: 2022-01-11
// URL: https://github.com/RobTillaart/MAX6675
//
// HISTORY:
// 0.1.0 2022-01-11 initial version.
// 0.1.1 2022-04-20 updated documentation after tests with UNO.
// added examples.
// HISTORY: see changelog.md
#include "MAX6675.h"
@ -46,19 +43,19 @@ void MAX6675::begin(const uint8_t clock, const uint8_t select, const uint8_t mis
if (_hwSPI)
{
#if defined(ESP32)
if (_useHSPI) // HSPI
if (_useHSPI) // HSPI
{
mySPI = new SPIClass(HSPI);
mySPI->end();
mySPI->begin(14, 12, 13, _select); // CLK=14 MISO=12 MOSI=13
mySPI->begin(14, 12, 13, _select); // CLK=14 MISO=12 MOSI=13
}
else // VSPI
else // VSPI
{
mySPI = new SPIClass(VSPI);
mySPI->end();
mySPI->begin(18, 19, 23, _select); // CLK=18 MISO=19 MOSI=23
mySPI->begin(18, 19, 23, _select); // CLK=18 MISO=19 MOSI=23
}
#else // generic hardware SPI
#else // generic hardware SPI
mySPI = &SPI;
mySPI->end();
mySPI->begin();
@ -99,14 +96,14 @@ void MAX6675::setGPIOpins(uint8_t clock, uint8_t miso, uint8_t mosi, uint8_t sel
uint8_t MAX6675::read()
{
// return value of _read() page 5 datasheet
// BITS DESCRIPTION
// ----------------------
// 00 three state ?
// 01 device ID ?
// 02 INPUT OPEN
// 03 - 14 TEMPERATURE (RAW)
// 15 SIGN
// return value of _read() page 5 datasheet
// BITS DESCRIPTION
// ------------------------------
// 00 three state ?
// 01 device ID ?
// 02 INPUT OPEN
// 03 - 14 TEMPERATURE (RAW)
// 15 SIGN
uint16_t value = _read();
// needs a pull up on MISO pin to work properly!
@ -123,10 +120,10 @@ uint8_t MAX6675::read()
value >>= 3;
// process temperature bits
// process temperature bits
_temperature = (value & 0x1FFF) * 0.25;
// dummy negative flag set ?
// if (value & 0x2000)
// dummy negative flag set ?
// if (value & 0x2000)
return _status;
}
@ -134,7 +131,7 @@ uint8_t MAX6675::read()
uint32_t MAX6675::_read(void)
{
_rawData = 0;
// DATA TRANSFER
// DATA TRANSFER
if (_hwSPI)
{
mySPI->beginTransaction(_spi_settings);
@ -145,10 +142,10 @@ uint32_t MAX6675::_read(void)
digitalWrite(_select, HIGH);
mySPI->endTransaction();
}
else // Software SPI
else // Software SPI
{
// split _swSPIdelay in equal dLow and dHigh
// dLow should be longer one when _swSPIdelay = odd.
// split _swSPIdelay in equal dLow and dHigh
// dLow should be longer one when _swSPIdelay = odd.
uint16_t dHigh = _swSPIdelay/2;
uint16_t dLow = _swSPIdelay - dHigh;
digitalWrite(_select, LOW);
@ -156,10 +153,10 @@ uint32_t MAX6675::_read(void)
{
_rawData <<= 1;
digitalWrite(_clock, LOW);
if (dLow > 0) delayMicroseconds(dLow); // DUE might need 1 us
if (dLow > 0) delayMicroseconds(dLow); // DUE might need 1 us
if ( digitalRead(_miso) ) _rawData++;
digitalWrite(_clock, HIGH);
if (dHigh > 0) delayMicroseconds(dHigh); // DUE
if (dHigh > 0) delayMicroseconds(dHigh); // DUE
}
digitalWrite(_select, HIGH);
}

View File

@ -2,33 +2,33 @@
//
// FILE: MAX6675.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.2
// PURPOSE: Arduino library for MAX6675 chip for K type thermocouple
// DATE: 2022-01-12
// URL: https://github.com/RobTillaart/MAX6675
// TODO Breakout board
// TODO Breakout board
//
// +---------+
// Vin | o |
// 3V3 | o |
// GND | o O | Thermocouple
// D0 | o O | Thermocouple
// CS | o |
// CLK | o |
// +---------+
// +---------+
// Vin | o |
// 3V3 | o |
// GND | o O | Thermocouple
// D0 | o O | Thermocouple
// CS | o |
// CLK | o |
// +---------+
#include "Arduino.h"
#include "SPI.h"
#define MAX6675_LIB_VERSION (F("0.1.1"))
#define MAX6675_LIB_VERSION (F("0.1.2"))
#define MAX6675_NO_TEMPERATURE -999
// STATE constants returned by read()
// TODO check
// STATE constants returned by read()
// TODO check
#define STATUS_OK 0x00
#define STATUS_ERROR 0x04
#define STATUS_NOREAD 0x80
@ -53,13 +53,13 @@ public:
// SW SPI
void begin(uint8_t clock, uint8_t select, uint8_t miso);
// returns state - bit field: 0 = STATUS_OK
// returns state - bit field: 0 = STATUS_OK
uint8_t read();
float getTemperature(void) { return _temperature + _offset; };
uint8_t getStatus(void) const { return _status; };
// use offset to calibrate the TC.
// use offset to calibrate the TC.
void setOffset(const float t) { _offset = t; };
float getOffset() const { return _offset; };
@ -80,7 +80,7 @@ public:
bool usesHSPI() { return _useHSPI; };
bool usesVSPI() { return !_useHSPI; };
// to overrule ESP32 default hardware pins
// to overrule ESP32 default hardware pins
void setGPIOpins(uint8_t clock, uint8_t miso, uint8_t mosi, uint8_t select);
#endif

View File

@ -14,7 +14,8 @@ The library is based upon (stripped and adapted version of) the https://github.c
Currently the library is experimental, so use with care.
Hardware has finally arrived (April 2022) and I had time to do my first round of tests with an UNO @ 16 MHz. The library works and it reads temperatures well, both with HW SPI and SW SPI.
Hardware has finally arrived (April 2022) and I had time to do my first round of tests with an UNO @ 16 MHz.
The library works and it reads temperatures well, both with HW SPI and SW SPI.
## Description

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/MAX6675"
},
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=MAX6675
version=0.1.1
version=0.1.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for MAX6675 chip for K type thermocouple.

View File

@ -46,18 +46,6 @@ unittest_teardown()
{
}
/*
unittest(test_new_operator)
{
assertEqualINF(exp(800));
assertEqualINF(0.0/0.0);
assertEqualINF(42);
assertEqualNAN(INFINITY - INFINITY);
assertEqualNAN(0.0/0.0);
assertEqualNAN(42);
}
*/
unittest(test_constants)
{
@ -65,7 +53,7 @@ unittest(test_constants)
assertEqual(0x04, STATUS_ERROR);
assertEqual(0x80, STATUS_NOREAD);
assertEqual(0x81, STATUS_NO_COMMUNICATION);
assertEqual(-999, MAX6675_NO_TEMPERATURE);
}
@ -137,4 +125,5 @@ unittest(test_SPIspeed_SWSPIdelay)
unittest_main()
// --------
// -- END OF FILE --