I only spent a little time deciding what hardware to use for this. Like many electronics/maker hobbyists, the idea of Bluetooth immediately triggered me to think of ESP32. And, also like many others, I have a little collection of ESP32 boards already laying around. It would certainly be possible for me to research and choose a cheaper/faster/smarter chipset that was dedicated to a Bluetooth mission, but I'm more interested in learning more about the ins and outs of the ESP32 ecosystem than devoting the effort to learning some other chipset's ecosystem. YMMV.
OK, but which ESP32 board should I use?
- I had a vague notion that BT would work more reliably if I had the original ESP32 dual-core setup. One core is mostly dedicated to protocols (BT and WiFi), and the other core does everything else. I could be mistaken for thinking this makes a difference for this project, of course, but I'm avoiding taking the chance with a newer single-core ESP32.
- I expect this thing will be powered all the time by a USB power supply, so power efficiency of the board is not a big concern.
- Likewise, I expect this thing will be tucked away out of sight most of the time, so aesthetics isn't a huge concern. On the other hand, tidiness does count for something, and I want everything to fit into some kind of enclosure with a minimum of fuss and bother about wiring external components to the processor board.
- Most of the time, the device will be sitting around silently doing its job and being unnoticed. There will be occasional configuration steps (at least for pairing, and maybe for some other things). A display would be nice for doing those configuration steps, and so would some buttons or maybe a rotary encoder. I have a few ESP32 boards with integral (monochrome) displays, and I also have a few separate displays (monochrome and color) that can be easily interfaced to an ESP32 board.
With these vague requirements in hand, I surveyed my existing inventory of parts, and I also went on an Internet window shopping expedition. Before too long, I settled on the popular TTGO T-Display board.
This board is available in a few "brands" (LilyGO, HiLetgo, and few mystery brands). I think it's a product of LilyGO, and the others are either rebranding or outright rip-offs. I'll probably never know for sure. These boards are available in April 2022 for around US$20 from the usual supply sources. Since I only plan to make one of these (or maybe two if magic smoke appears during development), that's a price I'm OK with. I don't know if it was or will be cheaper before or after the global supply chain disruption. It's available with either 4MB or 16MB of flash. I opted for 16MB because the price difference was negligible.
Besides the usual ESP32 features, this particular board has these nice things:
- Two conveniently located buttons wired to GPIOs. In the picture, you can see them on either side of the USB port. The button the side is the reset button.
- USB-C connector. Actually, I guess that's a very modest inconvenience when I consider how many mini and micro USB power supplies I have laying around.
- Integrated full color 1.14 inch TFT display with a resolution of 135x240 pixels, controlled by an ST7789V chip via SPI.
- Nice and compact, especially if it turns out I don't need to solder on the pin headers.
It has a few other features (like a battery connector) that are not interesting for this project. No wonder this board is popular. It seems well-designed for a lot of possible uses. One thing that might fake you out for a bit is that there is no GPIO-controlled LED on the board. If you try to run the usual blink application to see if the board is alive, it will remain without blinkenlights. There is an LED on the underside of the board, but it's related to power. When powered by USB, the little blue LED is always on. I don't think there's a way to turn that LED off except with a soldering iron or knife.
It's so popular that there are many different designs for 3D-printed enclosures on Thingaverse and similar places. LilyGO also provides a design. If you have access to a 3D printer, you can squeeze one of those out. I don't, so I uploaded the STL files to one of the several online sites that will get it printed and shipped to me. There is an original version of the board and later v1.1 revision. I don't know what the difference is, so I don't know if there is anything to worry about for the physical enclosure. I'm still waiting for mine to arrive, so it's fingers crossed until then. I probably would have opted for the LilyGO design, but I didn't come across it until after I had already ordered something else.
Every place that sells this board points to a copy of the same pin-out diagram, so it's pretty easy to find. If you are used to working with microprocessors, that and the bullet list of textual specs tells you most of what you are likely to care about. There are a few additional items that I figured out empirically. You might or might not need to know these, depending on what you are doing with the board and what libraries you are using.
- The pinout correctly states that GPIO 4 controls the backlight on the display. Unspoken is that HIGH is on and LOW is off. I found out by trying it that you can also do dimming by using PWM on GPIO 4.
- ESP32 has two SPI controllers for our use: HSPI and VSPI. (Apparently nobody knows why they are called that. :-)). The display is controlled by VSPI. (BTW, VSPI is described in Espressif documentation as the 4th SPI interface, so you might think the API constant for it would be 4 (if 1-based) or 3 (if 0-based). It's actually 2 because the first two (internal) SPI interfaces are somehow collapsed in the API.)
- The native resolution of the ST7789 chip is 240x320. To match that up with the physical display with 135x240 pixels, you need to specify x and y offset values. Which is x and which is y depends on the graphics library you are using, along with some other things you tell the graphics library. For the ST7789's 320 pixel direction, you specify an offset of 40 (because (320-240)/2 is 40). For the other direction, the offset is either 52 or 53, depending on how you feel about that half pixel. Depending on your graphics library, you may get truncation of that line of pixels or you may see it as a noise line of random junk.
EDIT: The cases. Because I am impatient and because I got a discount for being my first order, I had 2 different case designs printed. One of them definitely did not fit the board, which I imagine might be due to the board revision. The other one fit, more or less, but I didn't really care for the material I had chosen. I picked nylon with a dyed finish, and I just don't like the feel of it. I had a "free shipping" code, so I decided to risk some more money and had the LilyGO design, mentioned above, printed in TPU. Here's a picture of the board in that case:
The board fits perfectly and the flappy button things work well. The top looks a little rough. All of the other sides are pretty smooth, so maybe the textured top is by design. You can see that it covers a few pixels of the screen on the right-hand side. It doesn't matter for this project, but I might try to trim that edge of the window later. I did move the arrows that point to the buttons on the navigation screen (described in a later project log) a little bit to the left because of it.
The LilyGO case design has no room for a battery, and the bottom cover will not fit into place until you remove the battery connector from the board. The battery connector is soldered in place with some physical reinforcing points, but I was able to remove it cleanly with some side-cutters and fine pliers.
By the way, the service I used to get this printed was CraftCloud3D. If you want to try them, here is a referral code to get 10% off your first order: REFQXAB2XYW. (That's not an affiliate code. It's just a "refer a friend" code, Friend. I have no other connection with them.)