Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIOT-CFG-04-001: Install and configure the Sense-Emu Sense HAT emulator for your platform #50

Open
labbenchstudios opened this issue Sep 7, 2020 · 2 comments
Labels
configuration Configuration and / or setup requirement
Milestone

Comments

@labbenchstudios
Copy link
Contributor

labbenchstudios commented Sep 7, 2020

Description

Review the README

  • Please see README.md for further information on, and use of, this content.
  • License for embedded documentation and source codes: PIOT-DOC-LIC

Estimated effort may vary greatly

  • The estimated level of effort for this exercise shown in the 'Estimate' section below is a very rough approximation. The actual level of effort may vary greatly depending on your development and test environment, experience with the requisite technologies, and many other factors.

Actions

  • Dependencies:
    • You may need to install and configure GTK and PyGObject for your platform
  • Emulator and Library Install:
    • Install and configure the Sense-Emu Sense HAT emulator for your platform.
    • Install and configure the pisense library for your environment.

Windows Notes

  • I've found that using Windows Subsystem for Linux was helpful for my own Windows 10 install. On Windows 10, I ran a Bash shell, and installed all components as per the Ubuntu guidelines. I then ran all emulator-specific integration tests from another Bash shell command line. On Windows, you'll need an X11 display server.
    • Depending on how you install the emulator on your platform (along with GTK), you may need to run the integration test from the command line. For instance, if you use Bash on Ubuntu on Windows, and used the Ubuntu / Debian instructions for installation, you won't be able to run the integration test from within Eclipse, as the libraries won't be installed for the calls to succeed.

macOS Notes

  • I recently tested the Sense-Emu emulator on a MacBook Pro M3 pro (Apple silicon) running macOS Sonoma 14.1. Using Homebrew (https://brew.sh/), here are the steps I followed:
    • NOTES:
      • Your system installation needs may vary. Please review the installations instructions at https://sense-emu.readthedocs.io
      • My installation was managed via terminal commands
      • Python and Pip versions are as follows:
        • Python version: 3.9.6
        • Pip version: 23.3.2
    • Install Sense-Emu
    • Install PyGObject libs
      • brew install pygobject3 gtk+3
    • Make sure your Python install is available in your PATH
      • I added $HOME/Library/Python3.9/bin to the PATH in my $HOME/.zshrc file
      • Re-source your .zshrc or open a new terminal after the PATH update
    • Install PyGObject for Python
      • pip3 install pygobject
    • Test the Sense-Emu GUI
      • sense_emu_gui

Pisense v0.2 Notes

  • Depending on your local version of Pillow and other library dependencies, you may experience some Python version deprecation warnings or errors when using pisense within the CDA. This may be the case specifically with Pisense 0.2 and Python 3.10.
    • NOTE: If you don't see the error below, and the SenseHatEmulatorQuickTest runs without any issues, you can ignore the following.
    • Here's some sample log output that reflects this error when running SenseHatEmulatorQuickTest:
======================================================================
ERROR: testCheckEmulator (SenseHatEmulatorQuickTest.SenseHatEmulatorQuickTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/mnt/d/piot/piot-cda-solutions/src/test/python/programmingtheiot/part02/integration/emulated/SenseHatEmulatorQuickTest.py", line 53, in testCheckEmulator
    self.sh.screen.scroll_text(self.HELLO_WORLD_A)
  File "/mnt/d/piot/piot-wsl-venv/lib/python3.10/site-packages/pisense/screen.py", line 469, in scroll_text
    frames = [image_to_rgb565(frame) for frame in frames]
  File "/mnt/d/piot/piot-wsl-venv/lib/python3.10/site-packages/pisense/screen.py", line 469, in <listcomp>
    frames = [image_to_rgb565(frame) for frame in frames]
  File "/mnt/d/piot/piot-wsl-venv/lib/python3.10/site-packages/pisense/anim.py", line 219, in scroll_text
    img = draw_text(text, font, size, foreground, background,
  File "/mnt/d/piot/piot-wsl-venv/lib/python3.10/site-packages/pisense/anim.py", line 168, in draw_text
    width, height = draw.textlength(text, f, spacing=1)
TypeError: ImageDraw.textlength() got an unexpected keyword argument 'spacing'

  • From what I understand, the ImageDraw library in 3.10 has deprecated the textsize function, although in my own testing, it appears you can use textbbox instead. Since the version of pisense I tested with relies on textsize, there are at least two potential ways to address this issue.
  • How to update pisense anim.py source code module:
    • In the pisense module anim.py, you can change line 167 as follows (you'll find this under {your python install location}/lib/python3.10/site-packages/pisense/anim.py):
line     code
-----   -----
167:   #width, height = draw.textsize(text, f, spacing=1)
168:    x, y, width, height = draw.textbbox((0,0), text, f)

Estimate

  • Small

Tests

NOTE: Depending on how you install the emulator on your platform (along with GTK), you may need to run the EDA integration tests from the command line vs from within your IDE.

  • For instance, if you use Bash on Ubuntu on Windows, and used the Ubuntu / Debian instructions for installation, you may have difficulty running the EDA integration tests from within Eclipse, as the libraries won't be installed for the calls to succeed. On Windows 11 with Visual Studio Code (VS Code), assuming WSL v2 is configured properly and VS Code is launched from WSL, you should be able to run VS Code in WSL mode and invoke the test from within WSL directly from the IDE.

  • Setup

    • Linux
      • NOTE 1: If you're using Windows 10 and WSL (based on Ubuntu), you'll need an actively running X11 server.
      • NOTE 2: If you're using Windows 11 and WSL 2 (based on Ubuntu), you should not need a separate X11 server, as Windows 11 and WSL 2 should support rendering of X11-baseed UI's automatically.
      • Open a terminal and execute the following:
export DISPLAY=:0
sense_emu_gui
  • The Sense-Emu emulator GUI should launch depicting a UI that looks similar to the Sense HAT
  • Integration tests (in ./src/test/python/programmingtheiot/part02/integration)
    • Run the unit test cases in ./emulated/SenseHatEmulatorQuickTest. All tests should pass.
cd ./src/test/python/programmingtheiot/part02/integration/emulated
python -m unittest SenseHatEmulatorQuickTest
  • The Sense-Emu GUI should scroll three messages across the screen in sequence:
    • A 'hello world' message.
    • A 'welcome' message.
    • A 'temperature is' message.
  • Command line output from the integration test will look similar to the following:
2020-09-06 21:44:54,331:SenseHatEmulatorQuickTest:INFO:Testing SenseHatEmulatorQuickTest class [using SenseHAT emulator]...
2020-09-06 21:44:54,354:PngImagePlugin:DEBUG:STREAM b'IHDR' 16 13
2020-09-06 21:44:54,355:PngImagePlugin:DEBUG:STREAM b'IDAT' 41 367
2020-09-06 21:44:54,356:Image:DEBUG:Error closing: 'NoneType' object has no attribute 'close'
.
----------------------------------------------------------------------
Ran 1 test in 33.707s

OK
@labbenchstudios labbenchstudios added the build Build / DevOps specific requirement label Sep 7, 2020
@labbenchstudios labbenchstudios added this to the Chapter 04 milestone Sep 7, 2020
@labbenchstudios labbenchstudios changed the title PIOT-EMU-04-000: Install and configure the SenseHAT emulator for your platform PIOT-CFG-04-000: Install and configure the SenseHAT emulator for your platform Oct 4, 2020
@labbenchstudios labbenchstudios added configuration Configuration and / or setup requirement and removed build Build / DevOps specific requirement labels Oct 27, 2020
@labbenchstudios labbenchstudios changed the title PIOT-CFG-04-000: Install and configure the SenseHAT emulator for your platform PIOT-CFG-04-001: Install and configure the SenseHAT emulator for your platform Nov 6, 2020
@labbenchstudios labbenchstudios changed the title PIOT-CFG-04-001: Install and configure the SenseHAT emulator for your platform PIOT-CFG-04-001: Install and configure the Sense-Emu Sense HAT emulator for your platform Dec 31, 2020
@Pradyumna369
Copy link

I installed gtk4 and got an error "Namespace Gdk not available for version 3.0" when testing sense_emu_gui. I believe gtk 3.0 version is to be present. Then I uninstalled gtk4 and installed gtk+3 and the sense emulator GUI got launched when running the test

@labbenchstudios
Copy link
Contributor Author

Good catch. Just updated: changed 'gtk4' to 'gtk+3'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Configuration and / or setup requirement
Projects
Status: Lab Module 04 - Emulators
Status: Lab Module 04 - Data Emulation
Development

No branches or pull requests

2 participants