Skip to content

Commit 222ba3f

Browse files
authored
Merge pull request #263 from milesburton/add-dev-container
feat: Add dev container for library development
2 parents c4e76a5 + d5a1a36 commit 222ba3f

File tree

6 files changed

+272
-53
lines changed

6 files changed

+272
-53
lines changed

.devcontainer/Dockerfile

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM mcr.microsoft.com/vscode/devcontainers/cpp:debian
2+
3+
# Install required packages
4+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
5+
&& apt-get -y install --no-install-recommends \
6+
python3 \
7+
python3-pip \
8+
git \
9+
curl \
10+
&& apt-get clean \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Install arduino-cli
14+
RUN curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
15+
16+
# Set up arduino-cli config
17+
RUN arduino-cli config init
18+
19+
# Add arduino-cli to PATH
20+
ENV PATH="/usr/local/bin:${PATH}"
21+
22+
# Create workspace directory
23+
WORKDIR /workspace
24+
25+
# Copy arduino-cli configuration
26+
COPY arduino-cli.yaml /root/.arduino15/arduino-cli.yaml
27+
28+
# Install build essentials
29+
RUN apt-get update && apt-get install -y build-essential
30+
31+
# Install Arduino cores for ESP8266 and ESP32
32+
RUN arduino-cli core install esp8266:esp8266 esp32:esp32
33+
34+
# Install only required dependencies for DallasTemperature library
35+
RUN arduino-cli lib install \
36+
"OneWire" \
37+
"ArduinoUnit" # For testing
38+
39+
# Verify library installation
40+
RUN arduino-cli lib list
41+
42+
# Copy update script
43+
COPY update-libraries.sh /usr/local/bin/
44+
RUN chmod +x /usr/local/bin/update-libraries.sh
45+
46+
# Add aliases for build operations
47+
RUN echo 'alias arduino-build="./build.sh build"' >> /home/vscode/.bashrc && \
48+
echo 'alias arduino-test="./build.sh test"' >> /home/vscode/.bashrc && \
49+
echo 'alias arduino-build-test="./build.sh all"' >> /home/vscode/.bashrc

.devcontainer/arduino-cli.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
board_manager:
2+
additional_urls:
3+
- https://arduino.esp8266.com/stable/package_esp8266com_index.json
4+
- https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
5+
daemon:
6+
port: "50051"
7+
directories:
8+
data: /root/.arduino15
9+
downloads: /root/.arduino15/staging
10+
user: /root/Arduino
11+
library:
12+
enable_unsafe_install: true
13+
logging:
14+
file: ""
15+
format: text
16+
level: info
17+
metrics:
18+
addr: :9090
19+
enabled: true
20+
sketch:
21+
always_export_binaries: false

.devcontainer/devcontainer.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Arduino Library Development",
3+
"dockerFile": "Dockerfile",
4+
"customizations": {
5+
"vscode": {
6+
"extensions": [
7+
"vsciot-vscode.vscode-arduino",
8+
"ms-vscode.cpptools"
9+
]
10+
}
11+
},
12+
"postCreateCommand": "arduino-cli core install arduino:avr && arduino-cli lib install ArduinoUnit && /usr/local/bin/update-libraries.sh",
13+
"updateContentCommand": "/usr/local/bin/update-libraries.sh",
14+
"remoteUser": "vscode"
15+
}

.devcontainer/update-libraries.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
echo "Updating arduino-cli core and index..."
4+
arduino-cli core update-index
5+
arduino-cli update
6+
7+
echo "Updating installed libraries..."
8+
arduino-cli lib update-index
9+
arduino-cli lib upgrade
10+
11+
# Update Arduino cores
12+
echo "Updating ESP8266 and ESP32 cores..."
13+
arduino-cli core install esp8266:esp8266
14+
arduino-cli core install esp32:esp32
15+
16+
# List of libraries to ensure are installed/updated
17+
LIBRARIES=(
18+
"OneWire"
19+
"ArduinoUnit"
20+
)
21+
22+
echo "Checking and installing libraries..."
23+
for lib in "${LIBRARIES[@]}"; do
24+
echo "Processing library: $lib"
25+
if ! arduino-cli lib list | grep -q "$lib"; then
26+
echo "Installing $lib..."
27+
arduino-cli lib install "$lib"
28+
else
29+
echo "$lib is already installed"
30+
fi
31+
done
32+
33+
echo "Verifying all libraries are up to date..."
34+
arduino-cli lib list
35+
36+
echo "Library update complete!"

README.md

+85-53
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,120 @@
1+
2+
# 🌡️ Arduino Temperature Control Library
3+
14
[![Arduino CI](https://github.com/milesburton/Arduino-Temperature-Control-Library/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
25
[![Arduino-lint](https://github.com/milesburton/Arduino-Temperature-Control-Library/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AS5600/actions/workflows/arduino-lint.yml)
36
[![JSON check](https://github.com/milesburton/Arduino-Temperature-Control-Library/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AS5600/actions/workflows/jsoncheck.yml)
47
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/milesburton/Arduino-Temperature-Control-Library/blob/master/LICENSE)
58
[![GitHub release](https://img.shields.io/github/release/milesburton/Arduino-Temperature-Control-Library.svg?maxAge=3600)](https://github.com/milesburton/Arduino-Temperature-Control-Library/releases)
69

10+
A robust and feature-complete Arduino library for Maxim Temperature Integrated Circuits.
11+
12+
## 📌 Supported Devices
713

8-
# Arduino Library for Maxim Temperature Integrated Circuits
14+
- DS18B20
15+
- DS18S20 (⚠️ Known issues with this series)
16+
- DS1822
17+
- DS1820
18+
- MAX31820
19+
- MAX31850
920

10-
## Usage
21+
## 🚀 Installation
1122

12-
This library supports the following devices :
23+
### Using Arduino IDE Library Manager (Recommended)
24+
1. Open Arduino IDE
25+
2. Go to Tools > Manage Libraries...
26+
3. Search for "DallasTemperature"
27+
4. Click Install
28+
5. Also install the required "OneWire" library by Paul Stoffregen using the same method
1329

30+
### Manual Installation
31+
1. Download the latest release from [GitHub releases](https://github.com/milesburton/Arduino-Temperature-Control-Library/releases)
32+
2. In Arduino IDE, go to Sketch > Include Library > Add .ZIP Library...
33+
3. Select the downloaded ZIP file
34+
4. Repeat steps 1-3 for the required "OneWire" library
1435

15-
* DS18B20
16-
* DS18S20 - Please note there appears to be an issue with this series.
17-
* DS1822
18-
* DS1820
19-
* MAX31820
20-
* MAX31850
36+
## 📝 Basic Usage
2137

38+
1. **Hardware Setup**
39+
- Connect a 4k7 kΩ pull-up resistor between the 1-Wire data line and 5V power. Note this applies to the Arduino platform, for ESP32 and 8266 you'll need to adjust the resistor value accordingly.
40+
- For DS18B20: Ground pins 1 and 3 (the centre pin is the data line)
41+
- For reliable readings, see pull-up requirements in the [DS18B20 datasheet](https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf) (page 7)
2242

23-
You will need a pull-up resistor of about 5 KOhm between the 1-Wire data line
24-
and your 5V power. If you are using the DS18B20, ground pins 1 and 3. The
25-
centre pin is the data line '1-wire'.
43+
2. **Code Example**
44+
```cpp
45+
#include <OneWire.h>
46+
#include <DallasTemperature.h>
2647

27-
In case of temperature conversion problems (result is `-85`), strong pull-up setup may be necessary. See section
28-
_Powering the DS18B20_ in
29-
[DS18B20 datasheet](https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf) (page 7)
30-
and use `DallasTemperature(OneWire*, uint8_t)` constructor.
48+
// Data wire is connected to GPIO 4
49+
#define ONE_WIRE_BUS 4
3150

32-
We have included a "REQUIRESNEW" and "REQUIRESALARMS" definition. If you
33-
want to slim down the code feel free to use either of these by including
51+
OneWire oneWire(ONE_WIRE_BUS);
52+
DallasTemperature sensors(&oneWire);
3453

54+
void setup(void) {
55+
Serial.begin(9600);
56+
sensors.begin();
57+
}
3558

59+
void loop(void) {
60+
sensors.requestTemperatures();
61+
float tempC = sensors.getTempCByIndex(0);
62+
Serial.print("Temperature: ");
63+
Serial.print(tempC);
64+
Serial.println("°C");
65+
delay(1000);
66+
}
67+
```
3668
37-
#define REQUIRESNEW
69+
## 🛠️ Advanced Features
3870
39-
or
71+
- Multiple sensors on the same bus
72+
- Temperature conversion by address (`getTempC(address)` and `getTempF(address)`)
73+
- Asynchronous mode (added in v3.7.0)
74+
- Configurable resolution
4075
41-
#define REQUIRESALARMS
76+
### Configuration Options
4277
78+
You can slim down the code by defining the following at the top of DallasTemperature.h:
4379
44-
at the top of DallasTemperature.h
80+
```cpp
81+
#define REQUIRESNEW // Use if you want to minimise code size
82+
#define REQUIRESALARMS // Use if you need alarm functionality
83+
```
4584

46-
Finally, please include OneWire from Paul Stoffregen in the library manager before you begin.
85+
## 📚 Additional Documentation
4786

48-
## Credits
87+
Visit our [Wiki](https://www.milesburton.com/w/index.php/Dallas_Temperature_Control_Library) for detailed documentation.
4988

50-
The OneWire code has been derived from
51-
http://www.arduino.cc/playground/Learning/OneWire.
52-
Miles Burton <[email protected]> originally developed this library.
53-
Tim Newsome <[email protected]> added support for multiple sensors on
54-
the same bus.
55-
Guil Barros [[email protected]] added getTempByAddress (v3.5)
56-
Note: these are implemented as getTempC(address) and getTempF(address)
57-
Rob Tillaart [[email protected]] added async modus (v3.7.0)
89+
## 🔧 Library Development
5890

91+
If you want to contribute to the library development:
5992

60-
## Website
93+
### Using Dev Container
94+
The project includes a development container configuration for VS Code that provides a consistent development environment.
6195

96+
1. **Prerequisites**
97+
- Visual Studio Code
98+
- Docker
99+
- VS Code Remote - Containers extension
62100

63-
Additional documentation may be found here
64-
https://www.milesburton.com/w/index.php/Dallas_Temperature_Control_Library
101+
2. **Development Commands**
102+
Within the dev container, use:
103+
- `arduino-build` - Compile the library and examples
104+
- `arduino-test` - Run the test suite
105+
- `arduino-build-test` - Complete build and test process
65106

66-
# License
107+
> Note: Currently compiling against arduino:avr:uno environment
67108
68-
MIT License
109+
## ✨ Credits
69110

70-
Copyright (c) [2025] [Miles Burton]
111+
- Original development by Miles Burton <[email protected]>
112+
- Multiple sensor support by Tim Newsome <[email protected]>
113+
- Address-based temperature reading by Guil Barros [[email protected]]
114+
- Async mode by Rob Tillaart [[email protected]]
71115

72-
Permission is hereby granted, free of charge, to any person obtaining a copy
73-
of this software and associated documentation files (the "Software"), to deal
74-
in the Software without restriction, including without limitation the rights
75-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
76-
copies of the Software, and to permit persons to whom the Software is
77-
furnished to do so, subject to the following conditions:
116+
## 📄 License
78117

79-
The above copyright notice and this permission notice shall be included in all
80-
copies or substantial portions of the Software.
118+
MIT License | Copyright (c) 2025 Miles Burton
81119

82-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
83-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
84-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
85-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
86-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
87-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
88-
SOFTWARE.
120+
Full license text available in [LICENSE](LICENSE) file.

build.sh

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
3+
# Set error handling
4+
set -e
5+
6+
# Function to display usage
7+
show_usage() {
8+
echo "Usage: ./build.sh [option]"
9+
echo "Options:"
10+
echo " build - Only compile library and examples"
11+
echo " test - Only compile and run tests"
12+
echo " all - Build everything and run tests (default)"
13+
}
14+
15+
# Function to compile for a specific board
16+
compile_for_board() {
17+
local fqbn=$1
18+
local sketch=$2
19+
echo "📦 Compiling $sketch for $fqbn..."
20+
arduino-cli compile --fqbn $fqbn "$sketch" --library .
21+
}
22+
23+
# Function to build library and examples
24+
build() {
25+
echo "🔨 Building library and examples..."
26+
27+
# Compile all examples
28+
echo "🔍 Compiling examples..."
29+
for example in examples/*/*.ino; do
30+
if [ -f "$example" ]; then
31+
echo "Building example: $example"
32+
compile_for_board "arduino:avr:uno" "$example"
33+
fi
34+
done
35+
}
36+
37+
# Function to run tests
38+
run_tests() {
39+
echo "🧪 Running tests..."
40+
for test in test/*/*.ino; do
41+
if [ -f "$test" ]; then
42+
echo "Running test: $test"
43+
compile_for_board "arduino:avr:uno" "$test"
44+
fi
45+
done
46+
}
47+
48+
# Main execution
49+
case "${1:-all}" in
50+
"build")
51+
build
52+
;;
53+
"test")
54+
run_tests
55+
;;
56+
"all")
57+
build
58+
run_tests
59+
;;
60+
*)
61+
show_usage
62+
exit 1
63+
;;
64+
esac
65+
66+
echo "✅ Process completed!"

0 commit comments

Comments
 (0)