Skip to content

Commit f236339

Browse files
committed
0.1.0 DCT532
1 parent 5b71d47 commit f236339

File tree

18 files changed

+743
-0
lines changed

18 files changed

+743
-0
lines changed

libraries/DCT532/.arduino-ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
compile:
17+
# Choosing to run compilation tests on 2 different Arduino platforms
18+
platforms:
19+
- uno
20+
# - due
21+
# - zero
22+
# - leonardo
23+
- m4
24+
- esp32
25+
- esp8266
26+
# - mega2560
27+
- rpipico
28+
29+
libraries:
30+
- "printHelpers"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: RobTillaart
4+
custom: "https://www.paypal.me/robtillaart"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Arduino-lint
2+
3+
on: [push, pull_request]
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
timeout-minutes: 5
8+
steps:
9+
- uses: actions/checkout@v5
10+
- uses: arduino/arduino-lint-action@v2
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Arduino CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
runTest:
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 20
9+
10+
steps:
11+
- uses: actions/checkout@v5
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
paths:
9+
- '**.json'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 5
15+
steps:
16+
- uses: actions/checkout@v5
17+
- name: json-syntax-check
18+
uses: limitusus/json-syntax-check@v2
19+
with:
20+
pattern: "\\.json$"

libraries/DCT532/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Change Log DCT532
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
## [0.1.0] - 2025-09-23
9+
- extend and publish
10+
11+
## [0.1.0] - 2025-06-03
12+
- initial version
13+
14+
15+

libraries/DCT532/DCT532.cpp

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
//
2+
// FILE: DCT532.cpp
3+
// AUTHOR: Rob Tillaart
4+
// DATE: 2025-06-03
5+
// VERSION: 0.1.0
6+
// PURPOSE: Arduino library for DCT532
7+
// URL: https://github.com/RobTillaart/DCT532
8+
9+
10+
11+
#include "DCT532.h"
12+
13+
14+
DCT532::DCT532(uint8_t address, TwoWire *wire)
15+
{
16+
_address = address;
17+
_wire = wire;
18+
_error = DCT532_OK;
19+
_lastRead = 0;
20+
_pressure = 0;
21+
_temperature = 0;
22+
P = 0;
23+
T = 0;
24+
}
25+
26+
27+
bool DCT532::begin(float maxPressure, float minPressure)
28+
{
29+
// reset variables
30+
_error = DCT532_OK;
31+
_lastRead = 0;
32+
_pressure = 0;
33+
_temperature = 0;
34+
P = 0;
35+
T = 0;
36+
_minPressure = minPressure;
37+
_maxPressure = maxPressure;
38+
39+
if (! isConnected())
40+
{
41+
return false;
42+
}
43+
return true;
44+
}
45+
46+
47+
bool DCT532::isConnected()
48+
{
49+
_wire->beginTransmission(_address);
50+
return (_wire->endTransmission() == 0);
51+
}
52+
53+
54+
uint8_t DCT532::getAddress()
55+
{
56+
return _address;
57+
}
58+
59+
60+
/////////////////////////////////////////////
61+
//
62+
// READ SENSOR
63+
//
64+
int DCT532::readSensor()
65+
{
66+
if (_wire->requestFrom(_address, (uint8_t)4) != 4)
67+
{
68+
_error = DCT532_REQUEST_ERROR;
69+
return _error;
70+
}
71+
_lastRead = millis();
72+
73+
// read the raw pressure
74+
P = _wire->read() << 8;
75+
P |= _wire->read();
76+
P &= 0x3FFF; // mask unused bits.
77+
// read the raw temperature.
78+
T = _wire->read() << 8;
79+
T |= _wire->read();
80+
81+
// raw convert to float pressure
82+
// (P - 1638)/13106 * (Pmax - Pmin) - Pmin
83+
_pressure = ((P - 1638) * (_maxPressure - _minPressure));
84+
_pressure *= 7.630093e-5; // MUL faster than DIV
85+
_pressure -= _minPressure;
86+
87+
// raw convert to float temperature
88+
// ((T >> 5)/2048) * 165 - 40
89+
// >> 5 = 1/32 = 0.03125
90+
// 1 / 2048 = 4.8828125e-4
91+
_temperature = T * (0.03125 * 4.8828125e-4 * 165.0) - 40.0;
92+
_error = DCT532_OK;
93+
return _error;
94+
}
95+
96+
97+
float DCT532::getPressure()
98+
{
99+
return _pressure;
100+
}
101+
102+
103+
float DCT532::getTemperature()
104+
{
105+
return _temperature;
106+
}
107+
108+
109+
uint32_t DCT532::lastRead()
110+
{
111+
return _lastRead;
112+
}
113+
114+
115+
/////////////////////////////////////////////
116+
//
117+
// DEBUG
118+
//
119+
int DCT532::getLastError()
120+
{
121+
int e = _error;
122+
_error = 0;
123+
return e;
124+
}
125+
126+
127+
///////////////////////////////////////////////
128+
//
129+
// PRIVATE
130+
//
131+
132+
133+
// -- END OF FILE --
134+

libraries/DCT532/DCT532.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#pragma once
2+
//
3+
// FILE: DCT532.h
4+
// AUTHOR: Rob Tillaart
5+
// DATE: 2025-06-03
6+
// VERSION: 0.1.0
7+
// PURPOSE: Arduino library for
8+
// URL: https://github.com/RobTillaart/DCT532
9+
// https://forum.arduino.cc/t/i2c-industrial-pressure-sensor-dct-532-with-arduino-uno-advice-required/1385075/11
10+
//
11+
// TODO: need HW to develop /test
12+
13+
14+
#include "Arduino.h"
15+
#include "Wire.h"
16+
17+
18+
#define DCT532_LIB_VERSION (F("0.1.0"))
19+
20+
21+
// ERROR CODES
22+
// values <> 0 are errors.
23+
#define DCT532_OK 0
24+
#define DCT532_REQUEST_ERROR -1
25+
26+
27+
28+
class DCT532
29+
{
30+
public:
31+
DCT532(uint8_t address, TwoWire *wire = &Wire);
32+
33+
bool begin(float maxPressure, float minPressure = 0);
34+
bool isConnected();
35+
uint8_t getAddress();
36+
37+
// READ
38+
int readSensor(); // returns status
39+
float getPressure(); // Bar
40+
float getTemperature(); // Celsius
41+
uint32_t lastRead();
42+
43+
// DEBUG
44+
int getLastError();
45+
46+
private:
47+
uint8_t _address = 0x2A;
48+
TwoWire* _wire;
49+
50+
uint32_t _lastRead;
51+
float _pressure;
52+
float _temperature;
53+
// RAW data for develop,
54+
// TODO remove after confirmed working/
55+
uint16_t P;
56+
uint16_t T;
57+
58+
// calibrate sensor type.
59+
float _minPressure;
60+
float _maxPressure;
61+
62+
uint8_t _error;
63+
};
64+
65+
66+
// -- END OF FILE --
67+
68+
69+
70+
71+

libraries/DCT532/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025-2025 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)