Repository navigation
ChangingDeviceTypeSupport
Start here if you want to add, remove or adjust the I2C sensors and other devices your Raft firmware recognises, without changing the Raft libraries. Each task gives the short answer and links to the full reference.
Background in one paragraph: each device type (for example an SHT40 humidity sensor) is described by a device type record, a JSON file in RaftCore's devtypes/records/. A project chooses which records are compiled in with a DeviceTypeSources.json file in its SysType folders. Records can also be added to a device without rebuilding, in a device type file pushed to the device. Board-specific choices such as poll rate and bus speed are set in the SysType, not in the record.
-
In a browser: the Device Types app lists every RaftCore record, for each release and for
main. Search by name, manufacturer, class or I2C address. See Raft Web Apps. -
In the repo:
devtypes/records/, one<Key>.jsonper device type. -
Which breakout board uses which record:
devtypes/breakouts/breakouts.csvlists STEMMA QT, Qwiic, Grove and similar boards and the record that supports each, andtests.csvwhat has been checked on real hardware. -
For your project:
raft devtypes list -s <SysType>shows what your build selects.
Put a DeviceTypeSources.json in systypes/Common/ or systypes/<SysType>/ (the SysType's file adds to Common's):
{
"sources": { "raftcore": { "bundled": true } },
"builtin": { "include": ["raftcore:@common", "raftcore:MCP9808"] }
}-
"raftcore:@common"(about 10 popular sensors) or"raftcore:@extended"(about 25) are ready-made sets."raftcore:*"is every record. - Add or remove single records by key:
"raftcore:<Key>"inincludeorexclude. - Or from the command line:
raft devtypes init,raft devtypes add <Key>,raft devtypes remove <Key>(with-s <SysType>). - Then rebuild. A key that doesn't exist stops the build with a message.
- Fewer records means a smaller build and fewer chances of a wrong match at a shared address, so select only what the product can have attached.
Projects with no DeviceTypeSources.json work as before: /devtypes/DeviceTypeRecords.json in DEV_TYPE_JSON_FILES (in features.cmake) means every RaftCore record. Don't use both methods.
Reference: Selecting Device Types.
-
Change a RaftCore record for one project: copy its file into a folder in your project, add that folder as a source (
"local": { "path": "devtypes" }), and include"local:*". Your copy replaces RaftCore's, with a build message. -
Add a new device type:
raft devtypes new <Key> --address 0xHHcreates a record file to fill in. Adding an I2C Device Type walks through writing one, and Device Type Record Format is the full format. - Share records between projects: put them in a git repo and add it as a git source; the commit used is pinned in a lock file. See Git sources.
-
Contribute it to RaftCore so every project can use it: a pull request adding
devtypes/records/<Key>.json, and a row in the breakout list if it's for a breakout board.
Add a policy in builtin: "policy": { "TrillRing": "disabled" }. The record stays in the build but isn't used to identify devices. See typePolicy.
Don't edit the record. Set it for the type in the SysType's DeviceManager typeSettings:
"typeSettings": {
"LSM6DS3": { "busHz": 400000, "busHzSlots": "1,2,3,4,7" },
"VL6180": { "intervalUs": 50000, "scanPriority": "low" }
}Settings: intervalUs, numSamples, busHz, busHzSlots, sampleRateHz, scanPriority. See DeviceManager Settings: typeSettings.
Use a device type file, loaded by the device at startup:
- In the browser: in the Device Types app, connect to the device (Bluetooth or USB serial, Chrome or Edge), pick the records, then build and push the file.
-
From a project: list the records under
typeFileinDeviceTypeSources.json, thenraft devtypes push <device>. -
Install it with the firmware: add
"fsImage": trueundertypeFile, and a fullraft flash(not--no-fs, not OTA) installs it.
A type file has a size limit (256 KB with PSRAM, 64 KB without). Records with custom decode code only decode on the device if the firmware has the code interpreter. See Runtime type files.
A few records affect other devices on the bus. For example, selecting the CaliPile makes the bus send an I2C general call on every slot. Wildcards and sets don't select these records. Name the record in include, and add its key to "acknowledge": ["CaliPile"] to accept the warning. See Records with a warning.
Several chips share some I2C addresses, and a few records have little or no ID check, so they claim whatever is at their address. For example, the MPRLS record claims any device at 0x18.
- Leave out records your product doesn't need (
exclude), so they can't claim the address. - If both records are needed, the one with the higher
identPriorityis tried first. Set it in your own copy of the record, or raise it in a pull request. - The Device Types app shows what the device found at each address, and catalogue records for addresses it couldn't identify. From a script,
devman/listdevslists the devices found and their types, anddevman/identinfoshows how one was identified.
See I2C Device Identification and Polling.
The GitHub Pages site is rebuilt automatically when a change to devtypes/ is merged to RaftCore main, and on each RaftCore release. Each release's records stay published. The Device Types app is built from the raftjs version pinned in the site's workflow. See Raft Web Apps.
Common Tasks
Getting Started
- Quick Start
- Architecture at a Glance
- Writing Your First SysMod
- Adding a Comms Channel
- Adding an I2C Device Type
Scaffolding & Building
- Raft CLI
- Web Apps (Device Types, Flasher)
- SysTypes
- Top-Level SysType
- Build Process
- WebUI Build Pipeline
- File System
- Partitions & Flash
- Local Dev Libraries
- Library Developer Guide
Architecture
Built-in SysMods
- NetworkManager
- WiFi Troubleshooting
- BLEManager
- WebServer
- MQTTManager
- SerialConsole
- CommandSerial
- CommandSocket
- CommandFile
- FileManager
- LogManager
- ESPOTAUpdate
- StatePublisher
- Remote Logging
- Data Source Registration
Comms & Protocols
- Stack Overview
- Comms Channels
- ProtocolExchange
- RICREST Protocol
- Real-Time Streams
- Adding REST Endpoints
- Built-in REST Endpoints
- File Download (OKTO)
- OTA Update Flow
Devices & Buses
- DeviceManager
- Device Manager REST API
- Device Factory & Classes
- Device Type Records
- Selecting Device Types
- Adding an I2C Device Type
- Device Data Publishing
- Data Logger
- I2C Bus
- I2C Device Scanning
- I2C ID & Polling
- MotorControl Overview
- MotorControl Config
- MotorControl Commands
- Camera
ROS 2
Helpers
Reference