{"id":13736021,"url":"https://github.com/PMunch/ratel","last_synced_at":"2025-05-08T12:31:48.300Z","repository":{"id":43751076,"uuid":"455858212","full_name":"PMunch/ratel","owner":"PMunch","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-16T19:18:55.000Z","size":357,"stargazers_count":127,"open_issues_count":4,"forks_count":4,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-09T16:18:35.417Z","etag":null,"topics":["hacktoberfest","nim"],"latest_commit_sha":null,"homepage":"","language":"Nim","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/PMunch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-05T12:02:50.000Z","updated_at":"2025-01-24T23:43:32.000Z","dependencies_parsed_at":"2023-01-20T04:33:42.964Z","dependency_job_id":null,"html_url":"https://github.com/PMunch/ratel","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/PMunch%2Fratel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PMunch%2Fratel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PMunch%2Fratel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PMunch%2Fratel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PMunch","download_url":"https://codeload.github.com/PMunch/ratel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253068611,"owners_count":21848840,"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":["hacktoberfest","nim"],"created_at":"2024-08-03T03:01:14.463Z","updated_at":"2025-05-08T12:31:47.825Z","avatar_url":"https://github.com/PMunch.png","language":"Nim","funding_links":[],"categories":["Hardware"],"sub_categories":["Embedded"],"readme":"# Ratel\n### Next-generation, zero-cost abstraction microconroller programming in Nim\n\n## Getting started\nGetting started with Ratel is fairly simply. First you need to have [Nim](https://nim-lang.org/) installed along with the toolchain for\nthe controller you want to compile for. This guide is written with the Arduino Uno in mind, so for that board this would be the AVR toolchain. If you\nhave written code for Arduino before chances are good you already have these tools installed. Once that is done you need to install\nRatel itself:\n\n```\nnimble install ratel\n```\n\nIf your board is not included in the official distribution you need to grab support for that as well. You should be able to search for all Ratel\nbased packages in the [package directory](https://nimble.directory/search?query=ratel). In order to compile and build for your board you\nwill also need the toolchain to compile C code and upload that to your board as well. The details of this should be found with the board support\nlibrary.\n\nOnce you have Ratel and your board support installed you need to set up your project. In this tutorial we'll be building for an Arduino Uno, but\nthis process is pretty much the same no matter the board. Simply create a `config.nims` file in your folder with the content:\n\n```nim\nimport boardConf\nboard \"unor3\"\n\n--avr.any.gcc.path: \"/usr/bin\"\n```\n\nThis does a couple of things, starting with including the `boardConf` module from Ratel. Then it calls `board` which tells\nRatel that the board we want to build for is the Arduino Uno rev. 3. This will automatically include a set of sane defaults for compiling for this\nmicro-controller, along with some procedures that we'll get back to later.\n\nThe last three lines are simply telling Nim where to find the specific compiler we need to use for the CPU/OS combination we're using.\nThese could also be placed in your [global configuration](https://nim-lang.org/docs/nimc.html#compiler-usage-configuration-files)\nas they will only be applied when compiling for these platforms.\n\n## Writing our code\nNow that our project is all set up we need to write some code, the sample from the front page is a good start. Simply save the following code in\na file with the `.nim` extension named the same as the folder it's in.\n\n```nim\nimport board\nimport board / [times, serial, progmem]\n\nSerial.init(9600.Hz)\nSerial.send p\"Hello world\\n\"\nLed.output()\n\nwhile true:\n  Led.high()\n  Serial.send p\"Led is on\\n\"\n  delayMs(1000)\n  Led.low()\n  Serial.send p\"Led is off\\n\"\n  delayMs(1000)\n```\n\nTo write your own code have a browse through the documentation and check out any Ratel modules in Nimble.\n\n## Compiling and uploading\nWith the project set up and the code written it is time to compile. When we imported the board configuration earlier we got some tasks for doing\nthis loaded into our configuration. To run these we use the `ratel` binary. So to build simply run:\n\n```\nratel build\n```\n\nIf you missed the sentence earlier about putting your file in a folder of the same name this will fail, but fret not, simply pass the file to\nbuild with the `-f` flag. This command should have created a binary file in the same folder with the same name as your file but without\nthe extension. In order to check how big the resulting binary is we can simply run:\n\n```\nratel size\n```\n\nOr if you're of the curious kind:\n\n```\nratel sizeDetails\n```\n\nThe size breakdown you get from this should be familiar to you if you have done any kind of programming with Arduino, it's the same one which is\nwritten out in the terminal before uploading. It should look something like this:\n\n```\nAVR Memory Usage\n----------------\nDevice: atmega328p\n\nProgram:     298 bytes (0.9% Full)\n(.text + .data + .bootloader)\n\nData:          0 bytes (0.0% Full)\n(.data + .bss + .noinit)\n```\n\nNow the final step of the process is to upload our code to the controller. You can of course do this manually with `avrdude` but Ratel\ncomes with a task for this as well:\n\n```\nratel upload --device=/dev/ttyACM0\n```\n\nFor me the board is connected to the USB port at `/dev/ttyACM0` but this might be different for you.\n\nAnd that should be it! Your board should now be flashing an LED and printing to the serial terminal. To view the output you can either use the\nserial terminal that comes with Arduino if you have that installed, or you can use a number of terminal applications. The easiest might even be to run\n`tail -f /dev/ttyACM0`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPMunch%2Fratel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPMunch%2Fratel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPMunch%2Fratel/lists"}