Linux Format

Linux home control

Are you looking to integrate your Raspberry Pi into your smart home? Nick Peers looks at how Wyliodrin can get you started.

-

Now it’s secure, you can go on and unify all of your smart-home devices.

Ah, the good old Internet of Things. It’s starting to coalesce into something less gimmicky and more useful, but how do you get started with integratin­g it into your own projects? If you’re planning on using your Raspberry Pi, the answer will likely involve coding of some kind, and in most cases, that coding will be done in Python.

This is all well and good, but if you’re new to programmin­g or your Pi is running headless, you’ll want a more userfriend­ly environmen­t to interact with it, which is where Wyliodrin comes in. It’s an open-source web platform that’s specifical­ly designed for programmin­g and monitoring embedded devices such as the Pi, Arduino and others. It’s visual friendly and comes with its own visual programmin­g language that’s a drag and drop visual interface that echoes Scratch. In this tutorial, we’re going to look at getting you set up with Wyliodrin. We’ll examine how to connect it to your Raspberry Pi, code in both Python and visual programmin­g and get you set on your way.

It’s open source, but there’s a tiered pricing plan. Free accounts limit you to two devices and three projects when using it through its web-based interface, but if you use its Chromium- based applicatio­n, WyliodrinS­TUDIO, you’ll find there are no limits on the number of projects you can set up offline. We’ll show you how.

First, you need to sign up for a free Wyliodrin account on your main PC (the following instructio­ns assume you’re running Ubuntu 16.04). If you’ve not already done so, install

Chromium, then open it and browse to www.wyliodrin.com and click ‘Sign up/in’. You can sign in using Facebook, Google or GitHub—just click the relevant link to do so. When the main screen appears, click ‘Add a device’ to begin.

Set up on the Pi

Next, confirm your Pi is selected as the Gadget type, give it a suitably descriptiv­e name and click ‘Next’. If you’re connecting via Ethernet, click ‘Submit’; otherwise tick ‘Use Wireless’ to enter your network’s SSID and password before moving on. From here you need to click the link to download the image (in ZIP format) to your Downloads folder. If you’d rather add Wyliodrin to an existing Raspbian installati­on, check out the box ( seeInstall­WyliodrinM­anually,topright).

While you wait, scroll down a bit further and click the ‘following file’ link to download a file called wyliodrin.json— for now save it under Downloads. Once downloaded, extract its contents, pop in a blank, formatted microSD card and open Disks. Locate your micro SD card and make a note of its device name, e.g /dev/sdb. Now open a Terminal window and enter the following two commands: $ cd Downloads $ sudo dd if=wyliodrin_raspberry_pi_2016_03_24.img of=/ dev/sdb

Replace wyliodrin_raspberry_pi_2016_03_24 with the name of the image if it’s different, and /dev/sdb with your card’s device name. Wait while the Raspbian image is copied to the card. Once complete, open Nautilus to your Downloads

folder, then copy the wyliodrin.json file to the boot volume that should have appeared in the left-hand pane before clicking the ‘Eject’ button next to boot to eject the microSD card safely. Next, insert the card into your Pi and switch that on. Wait for around two minutes, then check your account in

Chromium— if all is well, you’ll see the Pi is listed as online. Next, you need to add any required libraries to your Pi, which you can do remotely from your browser. Click the ‘Settings’ button next to the Online indicator and choose ‘Local Shell’. You’ll see a button marked eth0 ( 192.168.x.y), with

192.168.x.y revealing your Pi’s IP address. Click this and a new window will open, logged in with your Pi user credential­s.

This shell works like any other, so if you’re planning to add the libraries to e.g. support your Sense HAT , enter: $ sudo apt-get update $ sudo apt-get install sense-hat $ sudo reboot

Once rebooted, you’re ready to switch attention back to your main PC. You can administer and run projects directly from this web browser—click the tour prompt when it appears to quickly familiaris­e yourself with the interface. However, for the purposes of this tutorial we’re going to switch focus to the WyliodrinS­TUDIO applicatio­n. It’s a

Chromium extension that enables you to manage your projects offline—go to http://wyliodrin.github.io/

WyliodrinS­TUDIO and install it through the Chrome store. An app icon will appear under chrome://apps, click this to launch Wyliodrin. A shortcut icon will appear in the launcher, which you can lock for easy access going forward.

You’ll be shown a splash screen—click ‘Exit’ and then click the ‘Connect’ button in the top right-hand corner of the

Wyliodrin window. Your Pi should show up as an option, so click it to make the connection. Enter your Pi’s username ( pi) and password ( raspberry) and it should open the Pin Layout screen, revealing the wiring for your Pi’s 40-pin header.

You’ll see the main screen is split into five tabs: Applicatio­n, Dashboard, Schematics, Pin Layout and Shell. The Shell tab gives you remote access to your Pi. The Applicatio­n tab displays your project’s code, while Dashboard contains elements you can use to monitor your Pi remotely. Schematics works in conjunctio­n with an applicatio­n called

Fritzing ( http://fritzing.org/home) for those designing and building hardware-based projects. You can see it in action by running some of the example scripts, e.g. the LED Blink shows you a Pi, plus breadboard, LED, resistor and two male/female jumper wires needed to complete the project. Above these you’ll see a series of buttons. There’s a play/stop button that runs your script through your Pi, and next to this is a File Explorer button that allows you to remotely browse your Pi’s storage. You can create new folders and upload files from your PC to here. Next to this is Package Manager, which basically lists all installed JavaScript and Python modules, and provides easy access to a selection of other libraries not yet installed—each one comes with a descriptio­n, and examples include Django, MySQLdb and NTLK (Natural Language Toolkit). There’s also a Task Manager for remotely killing processes, a network manager for viewing your current network settings and a handy disconnect button.

Your first project

In this project we’re going to use the Sense HAT in conjunctio­n with the Pi’s camera module to create a script that takes pictures whenever you move the Sense HAT’s joystick. This isn’t the most practical use of both HAT and camera, but it’s designed to show you what you can do.

We’ve already added the Sense HAT libraries, now we need to open a shell in WyliodrinS­TUDIO to install the Pi Camera’s Python libraries, plus enable the camera itself: $ sudo apt-get update $ sudo apt-get install python-picamera $ sudo raspi-config

Scroll down and select ‘6. Enable camera’, select Enable followed by Finish then reboot when prompted. You’ll need to re-connect to the Pi when you’re done.

We’re going to code this project in Python—there’s no direct support for the Sense HAT in Visual Programmin­g, so instead we’re going to cannibalis­e code from other sources. First, click the folder button at the top of the Wyliodrin window. Click ‘Create new Applicatio­n’, give it a suitable name and leave ‘Python’ selected as the language and click ‘Create’. The project will appear in the Projects window—click it to open it. You’ll see an example script is already present. Click the play button and you’ll see three lines appear in the console: python.main.py Hello Project exit with error 0

(The final line indicates the project has successful­ly concluded.) Now select all the code in the project window and hit ‘Delete’ to remove it. Now make your own project by typing the following lines of code to call the required Python libraries: from sense_hat import SenseHat from time import sleep import picamera The next few lines create variables we’ll use: sense = SenseHat() event = sense.stick.wait_for_event() camera = picamera.PiCamera() The following line waits until joystick movement is detected: event = sense.stick.wait_for_event() And these final lines of code take the photo: camera.start_preview() sleep(2) camera.capture('/home/pi/test.jpg')

As you type, you’ll notice Wyliodrin offers up autosugges­tions to speed up data entry—press Tab when a matching one appears to select it. Once it’s complete, verify your Pi is connected and click the play button. You should see python main.py appear in the console, indicating the script is now running. If you press or move the joystick on the back of your Sense HAT, the camera will launch into life—if your Pi is hooked up to a screen you’ll see the camera preview appear and two seconds later the image will be snapped. At this point

Project exit with error 0 should appear in the Wyliodrin console indicating the script has successful­ly completed.

Want to verify this? Click the File Manager button and navigate to the home/pi folder where you should see a

test.jpg file is now present. Click this and you’ll be prompted to download it to your own PC where you can review it. Congratula­tions, you’ve just completed your first project.

This isn’t something we’ve coded from scratch; instead we’ve plundered the relevant APIs ( https://pythonhost­ed.

org/sense-hat/api and http://picamera.readthedoc­s.io/ respective­ly) for code we’ve then adapted. And that’s the beauty of Python, its code is logical enough to make it easy to get started with programmin­g from scratch. Have a good read through and you’ll see ways in which you can improve or adapt the script further—e.g. set a specific resolution for the picture or capture video instead of a photo.

Visual programmin­g

Wyliodrin makes programmin­g in Python as straightfo­rward as can be, but there’s an even easier way to program called visual programmin­g, which works by dragging a series of code blocks into place, then tweaking their variables to put together a fully formed piece of Python without knowing any Python commands. Sadly, support for the Pi is limited to direct interactio­n with the GPIO pins (this doesn’t work with the Sense HAT because it communicat­es using the I2C protocol, which isn’t supported) as well as basic commands for the camera.

Neverthele­ss, the step-by-step guide ( right) reveals how visual programmin­g works by building a very simple project that will use the Pi camera to take a series of photos in succession. To start, click the Projects folder button and click ‘Create new applicatio­n’. Give your project a title, then click the Language drop-down menu. Scroll up to reveal Visual at the top. Select this to use visual programmin­g to create your new project and click ‘Create’. It’ll appear in the Projects window, so click its icon to open it in the Applicatio­n tab of WyliodrinS­TUDIO.

You’ll see a couple of blocks are in place—click ‘Show code’ on the right, and the Python code that these blocks represent will be shown. Click each block in turn and press ‘Delete’ to remove them. Now the screen is clear, follow the step-by-step guide ( again,seeright) to put the building blocks for your project in place. Once done, run the project and pose for those photos—use WyliodrinS­TUDIO’s File Explorer to download them from your Pi to your PC for reviewing.

 ??  ?? The main WyliodrinS­TUDIO interface contains a number of handy reference guides, such as this useful wiring diagram.
The main WyliodrinS­TUDIO interface contains a number of handy reference guides, such as this useful wiring diagram.
 ??  ??
 ??  ?? Our expert has got big plans for his rapidly growing collection of Raspberry Pis. He’s hoping that Wyliodrin could help him break through the final frontier of smart home tech. Nick Peers
Our expert has got big plans for his rapidly growing collection of Raspberry Pis. He’s hoping that Wyliodrin could help him break through the final frontier of smart home tech. Nick Peers
 ??  ?? Before you can get started coding, you need to link up your embedded device to your Wyliodrin account.
Before you can get started coding, you need to link up your embedded device to your Wyliodrin account.
 ??  ?? Wyliodrin
STUDIO features a built-in File Explorer tool, which allows you to browse and transfer files to and from your Pi.
Wyliodrin STUDIO features a built-in File Explorer tool, which allows you to browse and transfer files to and from your Pi.

Newspapers in English

Newspapers from Australia