{"id":15290618,"url":"https://github.com/valeriyvan/raspberrypisensehat","last_synced_at":"2026-05-01T01:32:16.908Z","repository":{"id":55391704,"uuid":"308759169","full_name":"valeriyvan/RaspberryPiSenseHat","owner":"valeriyvan","description":"Swift package for Raspberry Pi Sense Hat","archived":false,"fork":false,"pushed_at":"2023-04-19T17:10:18.000Z","size":9326,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-01T15:04:21.214Z","etag":null,"topics":["diy","hacktoberfest","raspberry-pi","sense-hat","spm","swift","swiftpackage"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/valeriyvan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["valeriyvan"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2020-10-30T22:43:27.000Z","updated_at":"2022-05-01T20:45:50.000Z","dependencies_parsed_at":"2024-12-01T16:46:10.179Z","dependency_job_id":"e08475d8-95ef-4f5b-b01a-51b0efa537bb","html_url":"https://github.com/valeriyvan/RaspberryPiSenseHat","commit_stats":{"total_commits":169,"total_committers":2,"mean_commits":84.5,"dds":"0.017751479289940808","last_synced_commit":"20303c2ed304ae7be3b36b3da48da0bd7dfa06f4"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valeriyvan%2FRaspberryPiSenseHat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valeriyvan%2FRaspberryPiSenseHat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valeriyvan%2FRaspberryPiSenseHat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valeriyvan%2FRaspberryPiSenseHat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valeriyvan","download_url":"https://codeload.github.com/valeriyvan/RaspberryPiSenseHat/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245232913,"owners_count":20581703,"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":["diy","hacktoberfest","raspberry-pi","sense-hat","spm","swift","swiftpackage"],"created_at":"2024-09-30T16:08:48.424Z","updated_at":"2026-05-01T01:32:16.866Z","avatar_url":"https://github.com/valeriyvan.png","language":"Swift","funding_links":["https://github.com/sponsors/valeriyvan","https://www.buymeacoffee.com/valeriyvan"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\" style=\"padding-bottom:50px;\"\u003e\n\u003ca href=\"https://developer.apple.com/swift\"\u003e\u003cimg src=\"https://img.shields.io/badge/Swift-5.x-orange.svg?style=flat\"/\u003e\u003c/a\u003e \n\u003ca href=\"https://github.com/apple/swift-package-manager\"\u003e\u003cimg src=\"https://img.shields.io/badge/SPM-compatible-brightgreen.svg\"/\u003e\u003c/a\u003e \n\u003ca href=\"https://github.com/valeriyvan/RaspberryPiSenseHat\"\u003e\u003cimg src=\"https://img.shields.io/badge/Platforms-%20Linux-lightgrey.svg\"/\u003e\u003c/a\u003e \n\u003ca href=\"https://raw.githubusercontent.com/valeriyvan/RaspberryPiSenseHat/main/LICENSE\"\u003e\u003cimg src=\"http://img.shields.io/badge/License-MIT-blue.svg?style=flat\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# Swift package `SenseHat` for Raspberry Pi Sense Hat\n\n![Photo](https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/IMG_3366.jpeg \"Photo\")\n\nFeatures:\n* ✅ blink with LED - that what everyone starts from playing with Raspberry Pi;\n* ✅ get/set color to individual pixels;\n* ✅ set color to all pixels in one shot;\n* ✅ get/set all pixels in one shot (to/from Data);\n* ✅ show 8x8 characters on LCD matrix (supported ascii, extended latin, box drawings elements, block elements, Hiragana, Greek, sga);\n* ✅ show arbitrary text (8x8 font, horizontal scroll);\n* ✅ rotating of LED matrix 0º/90º/180º/270º;\n* ✅ set orientation of LED matrix 0º/90º/180º/270º and make all get/set primitives respect it;\n* ✅ read joystick;\n* ✅ read humidity and pressure sensors;\n* ✅ read gyroscope/accelerometer/magnitometer sensors;\n* ✅ snake game;\n* ✅ [life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) game;\n\nTODO:\n* improve gyroscope/accelerometer/magnetometer sensors reading;\n* add conversion of RGB color to Rgb565;\n* add Cyrillic font 8x8;\n* add 3x5 font;\n* replace C fonts with Swift ones;\n* show arbitrary image on LED matrix;\n* show preprocessed video;\n* menu to show readings from any of available sensors;\n* mode for rotating screen depending on gyro readings;\n* emulator of SenseHat LED matrix for Web;\n* Kalman filtering for accelerometer/gyro/magnetometer;\n* add analog clock demo app.\n\n# Usage\n\n## Instantiating\n\n``` Swift\n// Look over all frame buffer devices in `/dev/` for one of Sense Hat. \n// Use default orientation `.up`\nguard let senseHat = SenseHat() else {\n    fatalError(\"Can't initialise Raspberry Pi Sense Hat\")\n}\n```\nParameter `orientation` could be used for other orientations\" `SenseHat(orientation: .left)`.\nParameter `frameBufferDevice` could be use for specific frame buffer device: `SenseHat(frameBufferDevice: \"/dev/fb0\")`.\nBoth parameters could be used:  `SenseHat(frameBufferDevice: \"/dev/fb0\", orientation: .down)`.\n\nParameter orientation defines where top of the LED matrix will be. Here are example of the same character `\"1\"` shown with different orientations:\n\n`.up` | `.left` | `.right` | `.down`\n--- | --- | --- | ---\n![1 up]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/1up.png) | ![1 left]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/1left.png) | ![1 right]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/1right.png) | ![1 down]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/1down.png)\n\n## Set all LEDs of matrix to specific color \n\n``` Swift\nsenseHat.set(color: .red) // sets all LEDs of matrix to red\n```\n\n![Red]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/red.png \"Red\")\n\n``` Swift\nsenseHat.set(color: .black) // sets all LEDs of matrix to black, literally turns them off\n```\n\n![Black]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/black.png \"Black\")\n\n## Set specific LED of matrix to specific color\n``` Swift\nsenseHat.set(color: .black) // clear\nsenseHat.set(x: 0, y: 0, color: .white) // set most top left LED to white using function syntax\nsenseHat[7, 7] = .green // set most bottom right LED to green using subscript syntax\n```\n![White and green]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/white-green.png \"White and green\")\n\nCoordinates `x` and `y` should belong to `0..\u003c7` range.\n\n## Show character on LED matrix\n\n``` Swift\nsenseHat.show(character: Character(\"A\"), color: .blue)\n```\n\n![A]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/A.png \"A\")\n\n``` Swift\nsenseHat.show(character: Character(\"π\"), color: .yellow, background: .blue)\n```\n\n![pi]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/pi.png \"pi\")\n\n## Show string on LED matrix\n\n``` Swift\nsenseHat.show(string: \"Hello! \", secPerChar: 0.5, color: .yellow, background: .blue)\n```\n\n![Hello!]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/hello.gif \"Hello!\")\n\n``` Swift\nsenseHat.orientation = .left\nsenseHat.show(string: \"Απόλλων \", secPerChar: 0.5, color: .red, background: .darkGray)\n```\n\n![Greek]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/greek.gif \"Greek\")\n\n``` Swift\nsenseHat.orientation = .right\nsenseHat.show(string: \"ここからそこまで \", secPerChar: 0.5, color: .white, background: .brown)\n```\n\n![Hiragana]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/hiragana.gif \"Hiragana\")\n\n``` Swift\nsenseHat.orientation = .down\nsenseHat.show(string: \"Fußgängerübergänge \", secPerChar: 0.5, color: .white, background: .purple)\n```\n\n![deutsch]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/deutsch.gif \"deutsch\")\n\n## Reading humidity sensor\n\n``` Swift\nif let h = senseHat.humidity() {\n    let strH = String(format: \"%.1lf\", h.H_rH)\n    senseHat.show(string: \"Humidity \\(strH)% rH \", secPerChar: 0.5, color: .yellow, background: .black)\n    let strT = String(format: \"%.1lf\", h.T_DegC)\n    senseHat.show(string: \"Temperature \\(strT)ºC\", secPerChar: 0.5, color: .yellow, background: .black)\n} else {\n    print(\"Cannot read humidity sensor\")\n}\n```\n\n![humidity]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/humidity.gif \"humidity\")\n\n## Reading pressure sensor\n\n``` Swift\nif let p = senseHat.pressure() {\n    let strP = String(format: \"%.1lf\", p.P_hPa)\n    let strT = String(format: \"%.1lf\", p.T_DegC)\n    senseHat.show(string: \"Pressure \\(strP) hPa \", secPerChar: 0.5, color: .yellow, background: .black)\n    senseHat.show(string: \"Temperature \\(strT)ºC\", secPerChar: 0.5, color: .yellow, background: .black)\n} else {\n    print(\"Cannot read pressure sensor\")\n}\n```\n\n![pressure]( https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/pressure.gif \"pressure\")\n\n# Useful links\n\nUnfortunately Data sheet or Programmer's manual for Raspberry Pi Sense Hat doesn't exist or I have failed to find it. Here are some useful links:\n\n* Official page on raspberrypi.org [Sense HAT](https://www.raspberrypi.org/products/sense-hat/);\n* [Astro Pi: Flight Hardware Tech Specs](https://www.raspberrypi.org/blog/astro-pi-tech-specs/) names all sensors of SenseHat with links on datasheets;\n* Official documentation [Documentation for Sense HAT](https://www.raspberrypi.org/documentation/hardware/sense-hat/);\n* Official Python module [sense-hat](https://pythonhosted.org/sense-hat/);\n* Source of Python module [sense-hat](https://github.com/astro-pi/python-sense-hat);\n* [Getting started with the Sense HAT](https://projects.raspberrypi.org/en/projects/getting-started-with-the-sense-hat);\n* Rust library [sensehat-screen](https://docs.rs/sensehat-screen/) where it's explained how RGB is packed in two bytes in so called `Rgb565`;\n* Linux [The Frame Buffer Device API](https://www.kernel.org/doc/Documentation/fb/api.txt) used to access pixel buffer;\n* Data sheet for [LSM9DS1](https://www.st.com/resource/en/datasheet/lsm9ds1.pdf), this might be useful [Reading from FIFO](https://github.com/kriswiner/LSM9DS1/issues/5);\n* Guide to install Swift on Raspberry Pi [buildSwiftOnARM](https://github.com/uraimo/buildSwiftOnARM) used to install prebuilt Swift 5.1.5 TODO: describe what I've done differently;\n* [3D printing Astro Pi case](https://projects.raspberrypi.org/en/projects/astro-pi-flight-case).\n\n\u003ca href=\"https://www.buymeacoffee.com/valeriyvan\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 60px !important;width: 217px !important;\" \u003e\u003c/a\u003e\n\n![Blinking](https://github.com/valeriyvan/RaspberryPiSenseHat/blob/main/images/IMG_3369_480.mov \"Blinking\")\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaleriyvan%2Fraspberrypisensehat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaleriyvan%2Fraspberrypisensehat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaleriyvan%2Fraspberrypisensehat/lists"}