valeriyvan/raspberrypisensehat
Features:
Instantiating
// Look over all frame buffer devices in `/dev/` for one of Sense Hat.
// Use default orientation `.up`
guard let senseHat = SenseHat() else {
fatalError("Can't initialise Raspberry Pi Sense Hat")
}Parameter orientation could be used for other orientations" SenseHat(orientation: .left). Parameter frameBufferDevice could be use for specific frame buffer device: SenseHat(frameBufferDevice: "/dev/fb0"). Both parameters could be used: SenseHat(frameBufferDevice: "/dev/fb0", orientation: .down).
Parameter orientation defines where top of the LED matrix will be. Here are example of the same character "1" shown with different orientations:
.up | .left | .right | .down --- | --- | --- | --- [1 up] | [1 left] | [1 right] | [1 down]
Set all LEDs of matrix to specific color
senseHat.set(color: .red) // sets all LEDs of matrix to red[Red]
senseHat.set(color: .black) // sets all LEDs of matrix to black, literally turns them off[Black]
Set specific LED of matrix to specific color
senseHat.set(color: .black) // clear
senseHat.set(x: 0, y: 0, color: .white) // set most top left LED to white using function syntax
senseHat[7, 7] = .green // set most bottom right LED to green using subscript syntax[White and green]
Coordinates x and y should belong to 0..<7 range.
Show character on LED matrix
senseHat.show(character: Character("A"), color: .blue)[A]
senseHat.show(character: Character("π"), color: .yellow, background: .blue)[pi]
Show string on LED matrix
senseHat.show(string: "Hello! ", secPerChar: 0.5, color: .yellow, background: .blue)[Hello!]
senseHat.orientation = .left
senseHat.show(string: "Απόλλων ", secPerChar: 0.5, color: .red, background: .darkGray)[Greek]
senseHat.orientation = .right
senseHat.show(string: "ここからそこまで ", secPerChar: 0.5, color: .white, background: .brown)[Hiragana]
senseHat.orientation = .down
senseHat.show(string: "Fußgängerübergänge ", secPerChar: 0.5, color: .white, background: .purple)[deutsch]
Reading humidity sensor
if let h = senseHat.humidity() {
let strH = String(format: "%.1lf", h.H_rH)
senseHat.show(string: "Humidity \(strH)% rH ", secPerChar: 0.5, color: .yellow, background: .black)
let strT = String(format: "%.1lf", h.T_DegC)
senseHat.show(string: "Temperature \(strT)ºC", secPerChar: 0.5, color: .yellow, background: .black)
} else {
print("Cannot read humidity sensor")
}[humidity]
Reading pressure sensor
if let p = senseHat.pressure() {
let strP = String(format: "%.1lf", p.P_hPa)
let strT = String(format: "%.1lf", p.T_DegC)
senseHat.show(string: "Pressure \(strP) hPa ", secPerChar: 0.5, color: .yellow, background: .black)
senseHat.show(string: "Temperature \(strT)ºC", secPerChar: 0.5, color: .yellow, background: .black)
} else {
print("Cannot read pressure sensor")
}[pressure]
Useful links
Unfortunately 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:
- Official page on raspberrypi.org Sense HAT;
- Astro Pi: Flight Hardware Tech Specs names all sensors of SenseHat with links on datasheets;
- Official documentation Documentation for Sense HAT;
- Official Python module sense-hat;
- Source of Python module sense-hat;
- Getting started with the Sense HAT;
- Rust library sensehat-screen where it's explained how RGB is packed in two bytes in so called
Rgb565; - Linux The Frame Buffer Device API used to access pixel buffer;
- Data sheet for LSM9DS1, this might be useful Reading from FIFO;
- Guide to install Swift on Raspberry Pi buildSwiftOnARM used to install prebuilt Swift 5.1.5 TODO: describe what I've done differently;
- 3D printing Astro Pi case.
<a href="https://www.buymeacoffee.com/valeriyvan" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
[Blinking]
Package Metadata
Repository: valeriyvan/raspberrypisensehat
Default branch: main
README: README.md