Hardware Reference
In-Depth Information
The temperature will be a real-time readout, but the light levels will be over
a period of time shown as a graph. To make things look nice, a background
image will display. The graph displays from left to right, and when the graph
reaches the far right side, the screen refreshes, and the graphs starts over again.
Hardware
The screen used in this example is the Adafruit ST7735 breakout board. Adafruit
sells an LCD screen by itself, but this is not what you want. A screen without
any additional hardware may be great for creating your own device after a pro-
totype has been made, but to create this sketch, you need the ST7735 breakout
board, a more complete version that is hosted on its own PCB, with pins that
can be placed onto a breadboard. As an added bonus: the breakout board also
has a micro-SD slot, which will come in handy for this project.
The breakout board must be hooked up to the SPI bus. It has two chip select
pins: one for the embedded SD-card controller, and one for the TFT screen itself.
The SD-card reader is also an SPI device, and therefore it will share the SPI bus
with the ST7735, but it needs its own chip select pin. The device also has a Lite
pin, allowing the Arduino to turn on the TFT backlight.
To get a temperature reading, use an LM35 temperature sensor connected to
A0, and to get a light level reading, use a photo-resistor on A1.
The assembly is shown in Figure 13-2. The SPI MISO and MOSI pins are
connected to the TFT breakout board's SPI pins, as well as the clock line. The
backlight pin is connected to the 5-volt rail, turning the TFT's backlight on
as soon as it is powered. The SD-controller chip select is connected to the
Arduino's D4 pin, and the TFT chip select is connected to D10. There are two
remaining pins—D/C, combined with the SPI pins, will be used to tell the TFT
screen if this is a command or data, and the Reset pin is also used to reset the
TFT screen if required.
Sketch
Now comes the fun part; it is time to put everything together. The sketch that
you will be using to start off with is shown in Listing 13-1.
Listing 13-1: TFT Sketch (fi lename: Chapter13.ino )
1 // Required headers
2 #include <SD.h>
3 #include <TFT.h>
4 #include <SPI.h>
5
6 // Pin definitions
7 #define TFT_CS 10
8 #define SD_CS 4
 
Search WWH ::




Custom Search