TabletPhone As Arduino Screen and A 2 Oscilloscope
TabletPhone As Arduino Screen and A 2 Oscilloscope
by arpruss
While one can buy a cheap 320x240 LCD touch send commands from the Android app to control the
screen for an Arduino-based project, it can be more Arduino sketch. The Arduino library is largely board-
convenient--especially for prototyping and testing a independent: it should work with any board that
sketch--to use a tablet or phone as both a touch provides a USB serial port object named Serial or
screen and a power source for a project. You can with an ESP8266 over WiFi or with Bluetooth (pair
have a much higher resolution and better looking your board first).
display on your Android device (e.g., all your lines will
be anti-aliased). As a proof of concept application, I ported the bare-
bones STM32-O-Scope project to use VectorDisplay
The Android-based screen could be connected via in place of the ILI9341 display. The result is a (rough
USB Serial, Bluetooth or WiFi (e.g., ESP8266). around the edges) portable, battery-powered 1.7MS/s
oscilloscope that requires nothing more than a $2
To that end I wrote VectorDisplay (source here), an STM32F103C board (using the libmaple-based
Android app that pairs with an Arduino library that Arduino core), two wires, a USB OTG cable and an
implements a large subset of the Adafruit GFX Android device. Of course, all you get with this is a
interface. You can write code that can then be easily range from 0 to about 3.3V.
ported to use a standalone screen, or keep using the
sketch with an Android-based display. And you can
I assume you have an Arduino IDE set up for your Unzip into a folder inside your Arduino/libraries
favorite board and that your favorite board has a USB folder.
serial interface.
Download VectorDisplay from Google Play and install
Go to Sketch | Include library | Manage libraries. it on your Android device. You may need to enable
Put "VectorDisplay" in the search area and click on installation from unknown sources on your Android
"Install" once it's found. device. The Android app uses the UsbSerial library
and the starting point was one of the example apps
Download the library zip from here. for the library.
Connect your board (in upload mode if need be) to your computer and go to File | Examples | VectorDisplay |
circles in your Arduino IDE. Click on the upload button (right arrow).
Start the VectorDisplay app on your Android device. Plug your board into the Android device via USB OTG cable.
(If your board has a USB micro port, make sure your USB OTG host side goes to the Android device). You should
now get a permission query for VectorDisplay. Press OK.
If all goes well, VectorDisplay will now show two buttons on the left side of the screen: Circle and Color. Pressing
Circle draws a random circle on the screen and Color changes the color to a random color before the next circle.
If you look at the circles sketch in the IDE, you will see that the serial vector display is declared with:
SerialDisplayClass Display;
Display.begin();
Then command buttons are requested with Display.addButton(). Then loop() calls Display.readMessage() to
look for commands being sent via the command buttons.
By default, the coordinate system for the display is 240x320. However, lines and text are all drawn using the full
resolution of your Android device screen, with antialiasing for good appearance. That's why the app is called
VectorDisplay.
The API in the library is in the VectorDisplay.h file. You need to first initialize a Display object. For USB use, do
that with:
SerialDisplayClass Display;
There are two sets of methods available in the SerialDisplayClass object: one set uses 32-bit color (including
alpha) and commands that are pretty close to the USB serial protocol that my VectorDisplay app uses, and the
other set is a subset of the standard Adafruit GFX library methods, using 16-bit color. For the most part you can
freely mix the two sets of commands, with the exception that if you use the Adafruit compatible methods, you
should use the 16-bit color commands whose names end with 565 instead of the 32-bit ones.
You can set the coordinate system with Display.coordinates(width,height). The default is width=240 and
height=320. If you want to emulate a display with non-square pixels, you can use
Display.pixelAspectRatio(ratio).
A few of the methods, including pixelAspectRatio(), take a FixedPoint32 argument. This is a 32-bit integer
representing a floating point number, where 65536 represents 1.0. To convert a floating point number x to
FixedPoint32, do: (FixedPoint32)(65536. * x) (or just TO_FP32(x)).
In addition to being able to send commands from Android buttons, screen touch events are also sent to the MCU.
For WiFi use, see the circles_esp8266 example. You'll need to press the USB button in the app to switch to WiFi
mode.
SerialDisplayClass Display(MyBluetoothSerial);
...
MyBluetoothSerial.begin(115200);
Display.begin();
and then proceed just as in the USB serial case, where MyBluetoothSerial is whatever Stream object (e.g.,
Serial2) is connected to your Bluetooth adapter.
For the quick and dirty oscilloscope, you will need a PC13.
blue or black (easier to deal with) pill STM32F103C8
board, which you can get on Aliexpress for under $2. Connect one wire--ground probe--to the board's
I describe how to prepare the board for use with the ground and another wire to the board's B0 pin. Plug
Arduino environment for it and install sketches here. the board into an Android device with VectorDisplay
running, and you have a portable, battery powered
Download this sketch on the board, which is a oscilloscope.
modified version of Pingumacpenguin's STM32-O-
Scope sketch. Edit the #define BOARD_LED line to In the photo I have the oscilloscope hooked up to a
match your board. I am using a black pill whose LED phototransistor. The trace on the screen is from a TV
is PB12. The blue pills (and some black pills that has infrared remote control.
the same pinout as the blue pill) have the LED at