Join The GUI Generation: QTCreator

More and more projects require a software component these days. With everything being networked, it is getting harder to avoid having to provide software for a desktop or phone environment as well as the code in your embedded device.

If you’ve done a lot of embedded systems work, you probably already know C and C++. If so, it is pretty easy to grab up a C compiler and write a command-line application that does what you want. The problem is that today’s users have varying degrees of fear about the command line ranging from discomfort to sheer terror. On a mobile device, they probably don’t even know how to get to a command line. I’ve been waiting for years for the WIMP (Windows/Icon/Mouse/Pointer) fad to fade away, but even I have to admit that it is probably here for the foreseeable future.

qtrigolSo what’s the alternative? There are actually quite a few. However, I wanted to talk about one that is free, has a wide range of deployment options, uses C++, and is easy to pick up: Qt. Specifically, creating programs with QtCreator (see right). Yes, there are other options, and you can develop Qt programs in a number of ways.

You might think Qt isn’t free. There was a time that it was free for open source projects, but not for commercial projects. However, recent licensing changes (as of version 4.5) have made it more like using gcc. You can elect to use the LGPL which means it is easy to use the Qt shared libraries with closed software. You might also think that a lot of strange constructs that “extend” C++ in unusual ways. The truth is, it does, but with QtCreator, you probably won’t need to know anything about that since the tool will set up most, if not all, of that for you.

Background

If you ever used Visual Basic or something similar, you will feel right at home with QtCreator. You can place buttons and text edit boxes and other widgets on a form and then back them up with code. Buttons create signals when you push them. There are lots of signals like text changed or widgets (controls) being created or destroyed.

To handle a signal, an object provides a slot. There is a meta-compiler that preprocesses your C++ code to get all the signal and slot stuff converted into regular C++. Here’s the good news: you don’t really care. In QtCreator you can write code to handle a button push and exactly how that happens isn’t really much of a worry.

QtCreator has kits that can target different platforms and — in general — the code is reasonably portable between platforms. If you do want to do mobile development for Android or iOS, be sure that you understand the limitations before you start so you can avoid future pitfalls.

You Need Class

Like many similar frameworks, Qt uses an application class (QtApplication) that represents a do-nothing application. Your job is to customize a subclass and have it do what you want. You add widgets and you can even add more screens, if you like. You can connect signals to existing slots or new slots.

There are many classes available, and the online documentation is quite good. Depending on which version of Qt you are using, you’ll need to find the right page (or ask QtCreator to find it for you). However, just to whet your appetite, here’s the Qt5 reference page. From there you can find classes for GUI widgets, strings, network sockets, database queries, and even serial ports.

I could do an entire tutorial on using QtCreator, but it would be a duplication of effort. There’s already a great getting started one provided. You’ll find there is plenty of documentation.

Portability

How do you enumerate serial ports? It depends on the platform, right? In Qt, the platform-specific part is hidden from you. For example, here’s a bit of code that fills in a combo box with the available serial port:

MainWindow::MainWindow(QWidget *parent) :
 QMainWindow(parent),
 ui(new Ui::MainWindow)
{
 ui->setupUi(this);
// initialize list of serial ports
 ports = QSerialPortInfo::availablePorts();
// fill in combo box
 for (int i=0; i<ports.length(); i++) 
 {
   ui->comport->addItem(ports[i].portName(), QVariant(i));
 }
}

The QSerialPortInfo object provides an array of serial port objects. The ui->comport is a combo box and the addItem method lets me put a display string and a data item in for each selection. In this case, the display is the portName of the port and the extra data is just the index in the array (as a variant, which could be different types of data, not just a number). When you select a port, the index lets the program look up the port to, for example, open it.

When the combo box changes, a currentIndexChanged signal will occur. Here’s the slot handler for that:

void MainWindow::on_comport_currentIndexChanged(int index)
{
 QString out;
 // get selected index
 int sel=ui->comport->currentData().toInt();
// build up HTML info string in out
 out="<h1>Serial Port Info</h1>";
 ui->output->clear();
 out += ports[sel].portName() + " " + ports[sel].description() + "
";
 out += ports[sel].systemLocation() + "
";
 if (ports[sel].hasVendorIdentifier() && ports[sel].hasProductIdentifier())
 out += ports[sel].manufacturer() + " ("+ QString::number(ports[sel].vendorIdentifier(),16) + ":" + QString::number(ports[sel].productIdentifier(),16) + ")";
 // and put it on the screen
 ui->output->setText(out);
}

In this case, the result is information about the serial port. You can see the resulting output, below. The QString is Qt’s string class and, obviously, the text display widget understands some HTML.

qtserial

Not Just for GUIs

You can develop console applications using Qt, but then many of the provided classes don’t make sense. There’s even a Qt for Embedded (essentially Linux with no GUI). You can find guides for Raspberry Pi and BeagleBoard.

On the mobile side, you can target Android, iOS, and even Blackberry, along with others. Like anything, it probably won’t just be “push a button” and a ported application will fall out. But it still should cut down on development time and cost compared to rewriting a mobile app from scratch.

And the Winner Is…

I’m sure if you want some alternatives, our comment section is about to fill up with recommendations. Some of them are probably good. But it strikes me that not everyone has the same needs and background. The best tool for you might not work as well for me. I find Qt useful and productive.

Even if Qt isn’t your tool of choice, it still can be handy to have in your tool bag. You never know when you will need a quick and dirty cross-platform application.

Beautiful Raspberry Pi Laptop Inspired By Psion

In the four years since the first Raspberry Pi appeared, there have been many takes on a portable computer based on it. The choice of components is fairly straightforward, there is now a wide selection of suitable keyboards, displays, and battery packs to choose from. You might therefore think that there could be nothing new in the world of the portable Pi, indeed another one might be as mundane as just another PC build.

News reaches us from Japan this morning of [nokton35mm]’s “RasPSION” Pi laptop build (machine translation) inspired by the Psion portable computers of the late 1990s.

That hinge, in close-up
That hinge, in close-up

The RasPSION features the Raspberry Pi 7″ display as well as a Bluetooth keyboard, 5V battery pack and the Pi camera. What makes it special is its laser cut case, and in particular its pivoting hinge mechanism. This is the part that takes its inspiration from the Psion machines, and its operation can be seen in the video below the break.

He claims the finished laptop gives him about two hours of battery life, which is no mean feat given that it lacks the sophisticated power management you’ll find in a commercial laptop. We hope that in time we’ll see him posting the details of the build somewhere other than Twitter, as this is a laptop we’d love to know more about.

Continue reading “Beautiful Raspberry Pi Laptop Inspired By Psion”

A Pi Robot Without A Hat

Daughter boards for microcontroller systems, whether they are shields, hats, feathers, capes, or whatever, are a convenient way to add sensors and controllers. Well, most of the time they are until challenges arise trying to stack multiple boards. Then you find the board you want to be mid-stack doesn’t have stackable headers, the top LCD board blocks the RF from a lower board, and extra headers are needed to provide clearance for the cabling to the servos, motors, and inputs. Then you find some boards try to use the pins for different purposes. Software gets into the act when support libraries want to use the same timer or other resources for different purposes. It can become a mess.

The alternative is to unstack the stack and use external boards. I took this approach in 2013 for a robotics competition. The computer on the robots was an ITX system which precluded using daughter boards, and USB ports were my interface of choice. I used a servo controller and two motor controllers from Pololu. They are still available and I’m using them on a rebuild, this time using the Raspberry Pi as the brain. USB isn’t the only option, though. A quick search found boards at Adafruit, Robotshop, and Sparkfun that use I2C.

Continue reading “A Pi Robot Without A Hat”

A 150MHz 6502 Co-Processor

If you are familiar with ARM processors, you may know of their early history at the 1980s British home computer manufacturer Acorn. The first physical ARM system was a plug-in co-processor development board for Acorn’s BBC Micro, the machine that could be found in nearly every UK school of the day.

For an 8-bit home computer the BBC Micro had an unusually high specification. It came with parallel, serial and analog ports, built-in networking using Acorn’s proprietary Econet system, and the co-processor interface used by that ARM board, the Tube. There were several commercial co-processors for the Tube, including ones with a 6502,  a Z80 allowing CP/M to be run, and an 80186.

As with most of the 8-bit generation of home computers the BBC Micro continues to maintain a strong enthusiast following who have not stopped extending its capabilities in all directions. The Tube has been interfaced to the Raspberry Pi, for instance, on which an emulation of original co-processor hardware can be run.

bbc-tube-screenshotAnd thus we come to the subject of this article, [Hoglet] and [BigEd]’s 150MHz 6502 coprocessor for the BBC Micro. Which of course isn’t a 6502 at all, but a 6502 emulated in assembler on an ARM which is in a way the very distant descendant of the machine it’s hosted upon. There is something gloriously circular about the whole project, particularly as the Pi, like Acorn, the BBC Micro, and modern-day ARM, has its roots in Cambridge. How useful it is depends on your need to run 8-bit 1980s software in a tearing hurry, but they do report it runs Elite, which if you were there at the time we’re sure you will agree is the most important application to get running on a BBC Micro.

We’ve featured the Tube interface before when we talked about an FPGA co-processor with a PDP/11 mode that was definitely never sold by Acorn. And we’ve also featured an effort to reverse engineer the primordial ARM from that first BBC Micro-based co-processor board.

BBC Micro image: Stuart Brady, Public Domain, via Wikimedia Commons.

Raspberry Pi Zero Becomes Mighty Miniature Minecraft Machine

In a clever bit of  miniaturization, [JediJeremy] has nearly completed a gyro-mouse controller for a Raspberry Pi Zero! Ultimately this will be a wearable Linux-watch but along the way he had some fun with the interface.

Using the MPU6040 gyroscope/accelerometer card from a quadcopter, [JediJeremy] spent a week writing the driver to allow it to function as a mouse. Strapping an Adafruit 1.5″ PAL/NTSC LCD screen and its driver board to the Zero with rubber bands makes this one of the smallest functional computer and screen combos we’ve seen. Simply tilt the whole thing about to direct the cursor.

It presently lacks any keyboard input, and [JediJeremy] has only added a single button for clicking, but look at this thing! It’s so tiny! In his own words: “I think this is the first computer that I can accidentally spill into my coffee, rather than vice versa.”

Continue reading “Raspberry Pi Zero Becomes Mighty Miniature Minecraft Machine”

Raspberry Pi Gets Turned On

The Raspberry Pi and other similar Linux-based single board computers simplify many projects. However, one issue with Linux is that it doesn’t like being turned off abruptly. Things have gotten better, and you can certainly configure things to minimize the risk, but–in general–shutting a Linux system down while it is running will eventually lead to file system corruption.

If your project has an interface, you can always provide a shutdown option, but that doesn’t help if your application is headless. You can provide a shutdown button, but that leaves the problem of turning the device back on.

[Ivan] solved this problem with–what else–an Arduino (see the video below). Simplistically, the Arduino reads a button and uses a FET to turn off the power to the Pi. The reason for the Arduino, is that the tiny processor (which draws less than a Pi and doesn’t mind being shut down abruptly) can log into the Pi and properly shut it down. The real advantage, though, is that you could use other Arduino inputs to determine when to turn the Pi on and off.

Continue reading “Raspberry Pi Gets Turned On”

Hackaday Prize Entry: A Raspberry Pi Project

There’s no piece of technology that has been more useful, more influential on the next generation of sysadmins and engineers, and more polarizing than the Raspberry Pi. For $35 (or just $5), you get a complete single board computer, capable of running Linux, and powerful enough to do useful work. For the 2016 Hackaday Prize, [Arsenijs] has created the perfect Raspberry Pi project. It’s everything you expect a Pi-powered project to be, and more.

While the Raspberry Pi, and the community surrounding the Raspberry Pi, get a lot of flak for the relatively simple approach to most projects which are effectively just casemods, critics of these projects forget the historical context of tiny personal computers. Back in the early ‘aughts, when Mini ITX motherboards were just being released, websites popped up that would feature Mini ITX casemods and nothing else. While computers stuffed into an NES, an old radio, or the AMD logo are rather banal projects today, I assure you they were just as pedestrian 15 years ago as well. Still, the creators of these Mini ITX case mods became the hardware hackers of today. It all started with simple builds, a Dremel, and some Bondo.

[Arsenijs] takes his Raspberry Pi project a bit further than a simple casemod, drawing influence from a Raspberry Pi smartphone, a Raspberry Pi security system, a Portable Raspberry Pi, and a Raspberry Pi wrist computer. These are all excellent projects in their own right, but [Arsenijs] is putting his own special twist on the project: he’s using a Raspberry Pi, and a few Raspberry Pi accessories.

While this project is first and foremost a Raspberry Pi project, [Arsenijs] isn’t limiting himself to the platform with the Broadcom chip. The team behind this Raspberry Pi project was busy porting the project to Odroid when the Banana Pi came out. This changed everything, a refactor was required, and then the Orange Pi was announced. Keeping up with technology is hard, and is a big factor in why this Raspberry Pi project hasn’t delivered yet. You can say a lot of things about the Raspberry Pi foundation, but at least their boards make a good attempt at forward compatibility.

Already [Arsenijs]’ Raspberry Pi project is one of the more popular projects on Hackaday.io, and is in the running for being one of the most popular projects in this year’s Hackaday Prize. Whether that popularity will translate into a minor win for this year’s Hackaday Prize remains to be seen, but it seems for [Arsenijs] that doesn’t matter; he’s already on the bleeding edge of Raspberry Pi projects.

The HackadayPrize2016 is Sponsored by: