ROBOTS
Building a web-based robot control interface
In part five of his series, Les Pounder shows us how to build a custom web interface for controlling your DIY robot.
Credit: https://anvil.works
Part Five!
Don’t miss next issue, subscribe on page 16!
OUR EXPERT
Les Pounder is associate editor at Tom’s Hardware and a freelance maker. He blogs about hacks and makes at http://bigl.es.
YOU NEED
All of the code for this project, circuit diagrams and images can be downloaded from our GitHub repository: https:// github.com/ lesp/Linux- Format- Robot/ archive/ refs/heads/main.zip
By the end of part four, we had successfully built our robot from a kit, tested the motors and looked at a number of sensors, then we learnt how to use a Bluetooth controller. All of the previous parts are building up to our robot becoming complete in the final sixth part.
For this section of the build, we are going to learn how to use a free web service called Anvil (https://anvil.works). The Anvil service is where we can develop web apps in pure Python. Using an uplink, we will connect our robot to a custom-created web interface and then use that interface to control our robot.
This might sound a little scary right now, and while Anvil does have a learning curve, fear not! Anvil is extremely easy to use once you understand how it works. With that in mind, let’s get started.
Hammer the Anvil
As Anvil is based in the cloud, we can access and create projects from any web-enabled device. As we’re using a Raspberry Pi 4 for the robot, open a Chromium browser and visit https://anvil.works/. Click on Pricing or Start Building to sign up for a free account.
Anvil works by creating ‘apps’. These are all webbased, and Anvil acts as an interface between us and our code. Anvil can be programmed to run code when a button is pressed, show an image captured on a remote device, store data in a database and many other services. Our need is simple: we want to press buttons and run code on our robot. To do this, Anvil has a clever uplink tool that securely links our robot to Anvil, where we can use buttons to send commands to the robot. To do this, we need to create a new blank app. Select Material Design 3 as the template and Anvil displays an interface that looks like Photoshop and an IDE blended together. By default, Anvil drops us into the Design tab, which is where we create a form that acts as the user interface for our app. We can change the view to Code, where we write the Python code, and Split, which splits the screen between design and code.