{"id":19283795,"url":"https://github.com/commonkestrel/atmega","last_synced_at":"2026-05-14T01:33:09.132Z","repository":{"id":144553608,"uuid":"592826343","full_name":"commonkestrel/atmega","owner":"commonkestrel","description":"A fast, easy, recognizable interface for the ATmega328p","archived":false,"fork":false,"pushed_at":"2023-09-27T01:42:03.000Z","size":284,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-05T17:40:18.018Z","etag":null,"topics":["arduino","atmega328p","avr","avr-rust","embedded","rust","rust-no-std"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/commonkestrel.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":"2023-01-24T16:10:32.000Z","updated_at":"2024-01-04T05:53:58.000Z","dependencies_parsed_at":"2023-09-27T07:14:42.487Z","dependency_job_id":null,"html_url":"https://github.com/commonkestrel/atmega","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/commonkestrel%2Fatmega","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commonkestrel%2Fatmega/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commonkestrel%2Fatmega/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commonkestrel%2Fatmega/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/commonkestrel","download_url":"https://codeload.github.com/commonkestrel/atmega/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240390697,"owners_count":19793781,"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":["arduino","atmega328p","avr","avr-rust","embedded","rust","rust-no-std"],"created_at":"2024-11-09T21:35:08.943Z","updated_at":"2025-11-17T01:01:24.723Z","avatar_url":"https://github.com/commonkestrel.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# atmega\n\nA fast, easy, recognizable interface for the ATmega328p.\nProvides many of the features of the Arduino language already used, with the benifit of Rust's memory safety and language features.\nNot quite finished, but this works well enough to make simple programs.\n\n## Warning\nThis crate is still very much a work in progress,\nand some features are either unstable or do not work.\n\n### Why should you use this?\nIf you are looking for a high(ish) level, easy to use interface with the ATmega328p, this is the crate for you.\nThis crate aims to provide easy, high-level interfaces to low-level operations without abstracting too much of the control logic away.\nIt's main goal is to emulate the official Arduino language as closely as possible.\n\nHowever, if you want a lower-level interface to dozens of microcontrollers including the ATmega328p, [`ruduino`](https://github.com/avr-rust/ruduino) or [`embedded-hal`](https://github.com/rust-embedded/embedded-hal) are probably better options.\n\n## Setup\nRust has a wonderful toolchain for AVR targets, but we need to set it up first.\nAn easy way to set up an `atmega` project is [`cargo-generate`](https://github.com/cargo-generate/cargo-generate)\nA [`cargo-generate`](https://github.com/cargo-generate/cargo-generate) template is provided at [atmega-template](https://github.com/commonkestrel/atmega-template)\nAssuming you have nothing installed, run the following commands:\n```sh\ncargo install cargo-generate\ncargo generate --git https://github.com/commonkestrel/atmega-template --name $PROJECT_NAME\ncd $PROJECT_NAME\nrustup override set nightly\nrustup component add rust-src\ncargo install ravedude\n```\nThis should install [cargo-generate](https://github.com/cargo-generate/cargo-generate) and create a new project from the [template](https://github.com/commonkestrel/atmega-template). \nAVR Rust is only available in the nightly version, so we need to set the toolchain in our project directory to nightly.\nAfter this we install [`ravedude`](https://github.com/Rahix/avr-hal/tree/main/ravedude), a Rust wrapper around avrdude that provides easy access to the target's serial console, similar to the Arduino IDE serial port.\n\n## Examples\nLet's start with a classic: blinking an LED: \n\n[`atmega-template`](https://github.com/commonkestrel/atmega-template) includes a small blink example, which we're going to recreate here.\nThis program should go in `src/main.rs`, like usual.\n\nTo start add this:\n```rust\n#![no_std]\n#![no_main]\n```\nI know, it already looks scary, but stay with me.\nAll this does is tell the compiler to link to [`libcore`](https://doc.rust-lang.org/core/) instead of [`libstd`](https://doc.rust-lang.org/std/).\nWe need to do this because [`libstd`](https://doc.rust-lang.org/std/) requires certain C dependencies as well as an allocator, which AVR targets do not have.\n\nHowever, this does mean that certain data types, functions, and macros like `Vec`, `String`, and `format!` will be unavailable, since these require an allocator.\n\nAfter this, import the atmega prelude:\n```rust\nuse atmega::prelude::*;\n```\nThe atmega prelude includes important functions and macros, like `digital_write()`, `pin_mode()`, `delay()`, just like the functions in the Arduino language.\n\nNext we need to add a `setup` function and initialize the pin the LED will be connected to:\n```rust\nfn setup() {\n    pin_mode(Pin::D9, PinMode::OUTPUT);\n}\n```\nIn this example we are using pin D9 for the LED, and we initialize it to output.\n\nNow we need a loop. Since the `loop` keyword is already taken, `run()` is used instead.\n```rust\nfn run() {\n\n}\n```\nThis function will be called indefinetly in a loop, just like the `loop()` function in the Arduino language.\n\nNow we need to actually blink the LED.\nAdd this inside `run()`:\n```rust\ndigital_toggle(Pin::D9);\ndelay(1000);\n```\nThis toggles the output of pin D9 (which we initialized as output earlier), then delays 1000 milliseconds, or 1 second.\n\nFinally, add this near the top of your file: \n```rust\nrun!(setup, run);\n```\nThis is a utility macro and takes care of exporting a `main` function, initializing timers and registers, and running your code.\n\nAfter that, your `main.rs` should look like this: \n```rust\n#![no_std]\n#![no_main]\n\nuse atmega::prelude::*;\n\nrun!(setup, run);\n\nfn setup() {\n    pin_mode(Pin::D9, PinMode::OUTPUT);\n}\n\nfn run() {\n    digital_toggle(Pin::D9);\n    delay(1000);\n}\n```\n\nIf you created your project with [cargo-generate](https://github.com/cargo-generate/cargo-generate), connect your chip to a USB port run `cargo run`.\nYou should see you LED start to flash!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommonkestrel%2Fatmega","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommonkestrel%2Fatmega","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommonkestrel%2Fatmega/lists"}