Skip to content

Commit

Permalink
feat: specify no. of channels
Browse files Browse the repository at this point in the history
  • Loading branch information
pilotak committed Oct 14, 2023
1 parent 97a9898 commit 057952a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# DS248x serial bridge

[![Framework Badge Arduino](https://img.shields.io/badge/framework-arduino-00979C.svg)](https://arduino.cc)
[![build](https://github.com/pilotak/ds248x-serial-bridge/actions/workflows/build.yml/badge.svg)](https://github.com/pilotak/ds248x-serial-bridge/actions/workflows/build.yml)

Simple FW for reading Dallas temperature sensors via DS248x with output as JSON

Output example
```
{"0x28FF5A1A31180210":23.06,"0x28FF9725311801EE":23.12}
{"0x28FF5A1A31180210": 23.06, "0x28FF9725311801EE":23.12}
```

> All credits for DS2482 library goes to https://github.com/cybergibbons/DS2482_OneWire/
2 changes: 2 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ board_hardware.oscillator = internal
board_hardware.bod = 4.3v
build_flags =
${common.build_flags}
'-D NO_CHANNELS=4'
lib_deps =
${common.lib_deps}

Expand All @@ -24,5 +25,6 @@ framework = arduino
monitor_speed = 115200
build_flags =
${common.build_flags}
'-D NO_CHANNELS=1'
lib_deps =
${common.lib_deps}
17 changes: 9 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ uint8_t data[9] = {0};

void (*resetFunc)(void) = 0;

void printAddress(uint8_t deviceAddress[]) {
void print(uint8_t deviceAddress[], float temp) {
Serial.print(F("\"0x"));

for (uint8_t i = 0; i < 8; i++) {
// zero pad the address
if (deviceAddress[i] < 16) {
Serial.print(F("0"));
}
Serial.print(deviceAddress[i], HEX);
}
Serial.print(F("\""));

Serial.print(F("\": "));
Serial.print(temp, 2);
}

void checkPresence() {
Expand All @@ -41,7 +44,7 @@ void loop() {
Serial.print("{");
bool first = true;

for (int i = 0; i < 1; i++) {
for (int i = 0; i < NO_CHANNELS; i++) {
oneWire.setChannel(i);

if (!oneWire.reset()) {
Expand Down Expand Up @@ -101,16 +104,14 @@ void loop() {
break;
}

// output data
// print data
if (!first) {
Serial.print(F(","));
Serial.print(F(", "));
}

first = false;

printAddress(rom);
Serial.print(F(":"));
Serial.print(((float)raw) / 16, 2);
print(rom, ((float)raw) / 16);
}

oneWire.reset_search();
Expand Down

0 comments on commit 057952a

Please sign in to comment.