diff --git a/README.md b/README.md index 909bd3d..4e2231d 100644 --- a/README.md +++ b/README.md @@ -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/ \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 649f25a..5992863 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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} @@ -24,5 +25,6 @@ framework = arduino monitor_speed = 115200 build_flags = ${common.build_flags} + '-D NO_CHANNELS=1' lib_deps = ${common.lib_deps} diff --git a/src/main.cpp b/src/main.cpp index 627c480..a69276f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,8 +8,9 @@ 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) { @@ -17,7 +18,9 @@ void printAddress(uint8_t deviceAddress[]) { } Serial.print(deviceAddress[i], HEX); } - Serial.print(F("\"")); + + Serial.print(F("\": ")); + Serial.print(temp, 2); } void checkPresence() { @@ -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()) { @@ -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();