{"id":20563375,"url":"https://github.com/pilotak/ds248x","last_synced_at":"2025-09-25T22:31:46.684Z","repository":{"id":91903289,"uuid":"158556836","full_name":"pilotak/DS248X","owner":"pilotak","description":"A OneWire library using the DS2482 or DS2484 (1-Wire Master) for mbed.","archived":false,"fork":false,"pushed_at":"2023-08-07T16:03:14.000Z","size":101,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-12T13:52:40.021Z","etag":null,"topics":["1-wire","ds18b20","ds18s20","ds2482-100","ds2482-800","ds2484","mbed","mbed-os","onewire"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pilotak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-21T14:03:00.000Z","updated_at":"2024-06-28T21:17:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"2611e39f-359e-4e11-9a27-c9a63d2c0e67","html_url":"https://github.com/pilotak/DS248X","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilotak%2FDS248X","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilotak%2FDS248X/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilotak%2FDS248X/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilotak%2FDS248X/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pilotak","download_url":"https://codeload.github.com/pilotak/DS248X/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234260192,"owners_count":18804355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["1-wire","ds18b20","ds18s20","ds2482-100","ds2482-800","ds2484","mbed","mbed-os","onewire"],"created_at":"2024-11-16T04:17:56.697Z","updated_at":"2025-09-25T22:31:41.454Z","avatar_url":"https://github.com/pilotak.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 1-Wire library\n[![Framework Badge mbed](https://img.shields.io/badge/framework-mbed-008fbe.svg)](https://os.mbed.com/)\n[![build](https://github.com/pilotak/DS248X/actions/workflows/build.yml/badge.svg)](https://github.com/pilotak/DS248X/actions/workflows/build.yml)\n\nSupports following ICs:\n- DS2484 *(single channel)*\n- DS2482-100 *(single channel)*\n- DS2482-800 *(8-channel)*\n\n## Basic example\n```cpp\n#include \"mbed.h\"\n#include \"DS248X.h\"\n\nDS248X oneWire(I2C_SDA, I2C_SCL);\n\nint main() {\n    if (!oneWire.init()) {\n        debug(\"Init failed\\n\");\n        return 0;\n    }\n\n    debug(\"At least one device on the bus: %u\\n\", oneWire.reset());\n\n    return 0;\n}\n```\n\n## Example searching the bus\n```cpp\n#include \"DS248X.h\"\n#include \"mbed.h\"\n\n\nDS248X oneWire(I2C_SDA, I2C_SCL);\n\nbool oneWireInit() {\n    if (!oneWire.init()) {\n        debug(\"Init failed\\n\");\n        return false;\n    }\n\n    if (!oneWire.setConfig(DS248X::ActivePullUp)) {\n        debug(\"Config failed\\n\");\n        return false;\n    }\n\n    return true;\n}\n\nvoid oneWireCb(char error) {\n    if (error \u0026 DS248X_CB_RESET_CONDITION) {\n        debug(\"1-Wire reset\\n\");\n\n    } else if (error \u0026 DS248X_CB_SHORT_CONDITION) {\n        debug(\"1-Wire short\\n\");\n\n    } else if (error \u0026 DS248X_CB_DEVICE_RESET_NEEDED) {\n        debug(\"Device reset needed\\n\");\n        oneWire.deviceReset();\n        oneWireInit();\n    }\n}\n\nint main() {\n    char rom[8];\n    uint8_t device_count = 0;\n\n    oneWire.attach(oneWireCb);\n\n    if (!oneWireInit()) {\n        return 0;\n    }\n\n    while (1) {\n        while (oneWire.search(rom)) {\n            device_count++;\n\n            debug(\"Found device: \");\n\n            for (size_t i = 0; i \u003c sizeof(rom); i++) {\n                debug(\"%02X\", rom[i]);\n            }\n\n            debug(\"\\n\");\n        }\n\n        oneWire.resetSearch();\n\n        debug(\"Total devices on the bus: %u\\n\\n\", device_count);\n        device_count = 0;\n\n        ThisThread::sleep_for(5s);\n    }\n}\n```\n\n## Example reading DS18B20 and passing I2C object\n```cpp\n#include \"DS248X.h\"\n#include \"mbed.h\"\n\nI2C i2c(I2C_SDA, I2C_SCL);\nDS248X oneWire;\n\nint main() {\n    char rom[8];\n    char data[9];\n\n    if (!oneWire.init(\u0026i2c)) {\n        debug(\"Init failed\\n\");\n        return 0;\n    }\n\n    if (!oneWire.setConfig(DS248X::ActivePullUp)) {\n        debug(\"Config failed\\n\");\n        return 0;\n    }\n\n    while (1) {\n        if (!oneWire.search(rom)) {\n            debug(\"No devices on the bus\\n\");\n            ThisThread::sleep_for(1s);\n            continue;\n        }\n\n        oneWire.resetSearch();\n\n        if (rom[0] != 0x10 \u0026\u0026 rom[0] != 0x28) {  // DS18S20 or DS18B20\n            debug(\"Not a temperature sensor\\n\");\n            continue;\n        }\n\n        debug(\"Temperature sensor found\\n\");\n\n        while (1) {\n            if (!oneWire.reset()) {\n                debug(\"Sensor is no longer on the bus\\n\");\n                break;\n            }\n\n            oneWire.select(rom);\n\n            // start conversion\n            data[0] = 0x44;\n            oneWire.writeBytes(data, 1, true);  // use SPU if in parasitic mode\n\n            // wait for conversion\n            ThisThread::sleep_for(750ms);  // default conversion (12bit) time is 750ms\n\n            oneWire.reset();\n            oneWire.select(rom);\n\n            // Read Scratchpad\n            data[0] = 0xBE;\n            oneWire.writeBytes(data, 1, true);  // use SPU if in parasitic mode\n            oneWire.readBytes(data, 9, true);   // use SPU if in parasitic mode\n\n            if (!oneWire.crc8(data, 9)) {\n                debug(\"Invalid CRC\\n\");\n                continue;\n            }\n\n            int16_t raw = (data[1] \u003c\u003c 8) | data[0];\n\n            for (auto i = 0; i \u003c 9; i++) {\n                printf(\"%02X \", data[i]);\n            }\n\n            printf(\"\\n\");\n\n            switch (rom[0]) {\n                case 0x10: {  // DS18S20\n                    raw = raw \u003c\u003c 3;\n\n                    if (data[7] == 0x10) {\n                        raw = (raw \u0026 0xFFF0) + 12 - data[6];\n                    }\n                } break;\n\n                case 0x28: {  // DS18B20\n\n                    char cfg = (data[4] \u0026 0x60);  // default is 12 bit resolution\n                                                  // 750ms conversion time\n\n                    if (cfg == 0x00) {  // 9 bit resolution, 93.75 ms\n                        raw \u0026= ~7;\n\n                    } else if (cfg == 0x20) {  // 10 bit res, 187.5 ms\n                        raw \u0026= ~3;\n\n                    } else if (cfg == 0x40) {  // 11 bit res, 375 ms\n                        raw \u0026= ~1;\n                    }\n                }\n\n                default:\n                    break;\n            }\n\n            printf(\"Temperature: %i *mC\\n\", ((int32_t)raw * 100) \u003e\u003e 4);\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilotak%2Fds248x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpilotak%2Fds248x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilotak%2Fds248x/lists"}