## Sense HAT prakticky #### najpopulárnejšie rozšírenie pre Raspberry Pi [Miroslav "mirek" Biňas](https://bletvaska.github.io) / [**Namakaný webinár**](http://www.namakanyden.sk)
![Sense HAT](images/sense.hat.png) ## Čo je to Sense HAT?
## HAT (Hardware Attached on Top)
![Sense HAT Assembly](https://projects-static.raspberrypi.org/projects/rpi-sensehat-attach/a180c64ad52670ac0df6a15e334499b683e65708/en/images/animated_sense_hat.gif) Notes: * https://radu-matei.com/blog/rpi-sensehat-telemetry/ * https://projects.raspberrypi.org/en/projects/getting-started-with-the-sense-hat/2
Sense HAT je rozširujúca doska pre Raspberry Pi vytvorená špeciálne pre súťaž [Astro Pi](https://astro-pi.org).
## Komponenty Sense HAT-u * senzory: teplotný, vlhkosti, tlakový * IMU (Inertial Measurement Unit) * gyroskop * akcelerometer * magnetometer * joystick * 8x8 RGB LED matrix notes: * A gyroscope (for detecting which way up the board is) * An accelerometer (for detecting movement) * A magnetometer (for detecting magnetic fields)
## Koľko Sense HAT stojí? * [RPishop.cz](https://rpishop.cz/hat/126-raspberry-pi-sense-hat.html?SubmitCurrency=1&id_currency=2) - 37,89 € * [RLX.sk](https://rlx.sk/sk/raspberry-pi/4546-raspberrypi-sensehat-2483095-orientation-pressure-humidity-temperature-sensors-.html) - 35,28 €
## (Ani) Sense HAT nemám :-( * Desktop Sense HAT emulátor * Online Sense HAT emulátor
## [Sense HAT Emulator](https://sense-emu.readthedocs.io/) ![Dekstop Sense HAT Emu](images/sense.emu.png) * dá sa nainštalovať aj na ["bežný" OS](https://sense-emu.readthedocs.io/en/v1.1/install.html)
![Trinket Logo](images/logo-trinket.png)
## [Code the Sense HAT in Your Browser!](https://trinket.io/sense-hat) New from Trinket and the Raspberry Pi Foundation: Explore Your World with Sensors and Python
## Sense HAT prakticky * Hello world! * senzory teploty, vlhkosti a tlaku * kompas
## Hello world! ```python from sense_hat import SenseHat # from sense_emu import SenseHat sense = SenseHat() sense.show_message('Hello world!') ```
## Nastavenie jedného pixla ```python from sense_hat import SenseHat sense = SenseHat() sense.set_pixel(2, 2, (0, 0, 255)) sense.set_pixel(4, 2, (0, 0, 255)) sense.set_pixel(3, 4, (100, 0, 0)) sense.set_pixel(1, 5, (255, 0, 0)) sense.set_pixel(2, 6, (255, 0, 0)) sense.set_pixel(3, 6, (255, 0, 0)) sense.set_pixel(4, 6, (255, 0, 0)) sense.set_pixel(5, 5, (255, 0, 0)) ```
## Snímanie prostredia ```python from time import sleep from sense_emu import SenseHat sense = SenseHat() sense.clear() while True: pressure = sense.get_pressure() temp = sense.get_temperature() humidity = sense.get_humidity() print(f"{temp:.2f}°C {humidity:.2f}% {pressure:.2f}hPa") sleep(1) ```
![](images/orientation.png)
## Pitch, Roll and Yaw ```python from sense_emu import SenseHat sense = SenseHat() sense.clear() o = sense.get_orientation() pitch = o["pitch"] roll = o["roll"] yaw = o["yaw"] print(f"pitch {pitch} roll {roll} yaw {yaw}") ``` notes: * azimut? elevace? náklon?
## Zrýchlenie ```python from sense_hat import SenseHat sense = SenseHat() red = (255, 0, 0) while True: acceleration = sense.get_accelerometer_raw() x = acceleration['x'] y = acceleration['y'] z = acceleration['z'] x = abs(x) y = abs(y) z = abs(z) if x > 1 or y > 1 or z > 1: sense.show_letter("!", red) else: sense.clear() ```
## Použitie veselej paličky ```python from sense_hat import SenseHat def pushed_up(event): print(event) sense = SenseHat() sense.stick.direction_up = pushed_up while True: for event in sense.stick.get_events(): print(event.direction, event.action) ```
## Sense HAT ako kompas ```python from sense_hat import SenseHat sense = SenseHat() while True: heading = sense.get_compass() if heading < 45 or heading > 315: sense.show_letter('N') elif heading < 135: sense.show_letter('N') elif heading < 225: sense.show_letter('S') else: sense.show_letter('W') ```
## Sense HAT a IoT?
## Sense HAT a Node-RED * [node-red-node-pi-sense-hat](https://flows.nodered.org/node/node-red-node-pi-sense-hat) * [node-red-node-pi-sense-hat-simulator](https://flows.nodered.org/node/node-red-node-pi-sense-hat-simulator) * [node-red-contrib-sense-hat-scroll-message](https://flows.nodered.org/node/node-red-contrib-sense-hat-scroll-message)
## Otázky?
## Zdroje * [Sense HAT](https://pythonhosted.org/sense-hat/) - modul pre jazyk Python na ovládanie Sense HAT-u * [Sense HAT Emulator](https://sense-emu.readthedocs.io/) - softvérový emulátor pre Sense HAT * [Code the Sense HAT in Your Browser!](https://trinket.io/sense-hat) * [Raspberry Pi Projekty](https://projects.raspberrypi.org/en/projects?hardware%5B%5D=sense-hat) - projekty pre Sense HAT * [Getting started with the Sense HAT](https://projects.raspberrypi.org/en/projects/getting-started-with-the-sense-hat)
![qr code](https://api.qrserver.com/v1/create-qr-code/?data=https://bit.ly/3gxVern&size=300x300) (**https://bit.ly/3gxVern**)