{"id":25747786,"url":"https://github.com/elixir-circuits/circuits_sim","last_synced_at":"2025-05-12T13:46:29.772Z","repository":{"id":157221557,"uuid":"618661850","full_name":"elixir-circuits/circuits_sim","owner":"elixir-circuits","description":"Elixir Circuits device simulator","archived":false,"fork":false,"pushed_at":"2025-03-08T21:58:24.000Z","size":137,"stargazers_count":18,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-09T09:04:45.364Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elixir-circuits.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2023-03-25T01:27:16.000Z","updated_at":"2025-03-08T21:58:26.000Z","dependencies_parsed_at":"2024-07-14T17:35:03.490Z","dependency_job_id":"1198f603-2842-4927-88fa-566216897667","html_url":"https://github.com/elixir-circuits/circuits_sim","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-circuits%2Fcircuits_sim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-circuits%2Fcircuits_sim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-circuits%2Fcircuits_sim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-circuits%2Fcircuits_sim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-circuits","download_url":"https://codeload.github.com/elixir-circuits/circuits_sim/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253750156,"owners_count":21958260,"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":[],"created_at":"2025-02-26T12:18:04.159Z","updated_at":"2025-05-12T13:46:29.762Z","avatar_url":"https://github.com/elixir-circuits.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CircuitsSim\n\n[![Hex version](https://img.shields.io/hexpm/v/circuits_sim.svg \"Hex version\")](https://hex.pm/packages/circuits_sim)\n[![API docs](https://img.shields.io/hexpm/v/circuits_sim.svg?label=hexdocs \"API docs\")](https://hexdocs.pm/circuits_sim/CircuitsSim.html)\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/elixir-circuits/circuits_sim/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/elixir-circuits/circuits_sim/tree/main)\n[![REUSE status](https://api.reuse.software/badge/github.com/elixir-circuits/circuits_sim)](https://api.reuse.software/info/github.com/elixir-circuits/circuits_sim)\n\nInteract with simulated hardware\n\n## Using\n\nCircuitsSim requires Elixir Circuits 2.0 libraries.\n\nYou may need to add `override: true` since not many libraries have been updated\nto allow Circuits 2.0 versions. Circuits 2.0 is mostly backwards compatible, so\nthis should be safe.\n\nCircuitsSim works by providing an alternative backend for interacting with\nhardware. This is setup via `config/config.exs`. In your project, you may only\nwant the simulated backends for `MIX_ENV=test` configurations, so you'll want to\nadd the following appropriately. For trying it out, it's fine to start with\nadding this to `config.exs`:\n\n```elixir\nconfig :circuits_i2c, default_backend: CircuitsSim.I2C.Backend\nconfig :circuits_spi, default_backend: CircuitsSim.SPI.Backend\nconfig :circuits_gpio, default_backend: CircuitsSim.GPIO.Backend\n```\n\nNote that you don't need to replace all backends. If you're only using I2C,\nthere's no need to bring in SPI and GPIO support.\n\n## Demo\n\nCircuitsSim takes a configuration for how to set up the simulated I2C buses and\ndevices. Here's an example configuration:\n\n```elixir\nconfig :circuits_sim,\n  config: [\n    {CircuitsSim.Device.MCP23008, bus_name: \"i2c-0\", address: 0x20},\n    {CircuitsSim.Device.AT24C02, bus_name: \"i2c-0\", address: 0x50},\n    {CircuitsSim.Device.ADS7138, bus_name: \"i2c-1\", address: 0x10},\n    {CircuitsSim.Device.MCP23008, bus_name: \"i2c-1\", address: 0x20},\n    {CircuitsSim.Device.MCP23008, bus_name: \"i2c-1\", address: 0x21},\n    {CircuitsSim.Device.TM1620, bus_name: \"spidev0.0\", render: :binary_clock},\n    {CircuitsSim.Device.GPIOLED, gpio_spec: 10},\n    {CircuitsSim.Device.GPIOButton, gpio_spec: 11}\n  ]\n```\n\nThis shows two simulated I2C buses, `\"i2c-0\"` and `\"i2c-1\"`, one SPI bus,\nand two GPIO.\nThe `\"i2c-0\"` bus has two devices, an MCP23008 GPIO expander and an AT24C02\nEEPROM.\n\nHere's how it looks when you run IEx:\n\n```shell\n$ iex -S mix\n\nInteractive Elixir (1.14.3) - press Ctrl+C to exit (type h() ENTER for help)\niex\u003e Circuits.I2C.detect_devices\nDevices on I2C bus \"i2c-1\":\n * 16  (0x10)\n * 32  (0x20)\n * 33  (0x21)\n\nDevices on I2C bus \"i2c-0\":\n * 32  (0x20)\n * 80  (0x50)\n\n5 devices detected on 2 I2C buses\n```\n\nYou can then read and write to the I2C devices similar to how you'd interact\nwith them for real. While they're obviously not real and have limitations, they\ncan be super helpful in mocking I2C devices or debugging I2C interactions\nwithout hardware in the loop.\n\n## Adding an I2C device\n\nMany I2C devices follow a simple pattern of exposing all operations as register\nreads and writes. If this is the case for your device, create a new module and\nimplement the `CircuitsSim.I2C.SimpleI2CDevice` protocol. See\n`CircuitsSim.Device.MCP23008` for an example.\n\nIf your device has a fancier interface, you'll need to implement the\n`CircuitsSim.I2C.I2CDevice` protocol which just passes the reads and writes\nthrough and doesn't handle conveniences like auto-incrementing register\naddresses on multi-byte reads and writes. See `CircuitsSim.Device.ADS7138` for\nan example.\n\n## Adding a SPI device\n\nSimulated SPI devices implement the `CircuitsSim.SPI.SPIDevice` protocols. See\n`CircuitsSim.Device.TM1620` for an example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-circuits%2Fcircuits_sim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-circuits%2Fcircuits_sim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-circuits%2Fcircuits_sim/lists"}