The Reason

Sometimes projects align. I am involved in frozen produce (Moonshine Park Fish Company), track the local weather while sailing, and have an interest in monitoring energy usage in the home. All three center around logging data, data, and more data. For all of these projects it is time to figure out a way to capture, log, and display data.

Low-Power

The most pressing reason for the low-power requirement comes from the sailing application. While away-from-dock SV Quagmire has only one way to charge the batteries: running the engine. Running the engine on a sailboat is sacrilegious to sailing; they are loud, stinky, and consume dinosaurs. I have looked longingly at adding solar panels, wind and water generators, or some other quiet source of electrical power to the boat. But to date none have been fully incorporated into to the electrical system.

While running a laptop for an hour on the boat is a reasonable option for power consumption, having one running 24-7 to collect data is not. Options such as running Linux on a BeagleBoard had appeal, but it still required interfacing multiple sensors through the serial port and writing custom drivers. It also left the issue of displaying the results since I didn’t have a cheap screen that interfaced with the board.

ST7735 1.8" TFT DisplayArduino

This seemed like a reasonable project for this little processor. I could attach some Dallas-One-Wire sensors, a small screen, SD card, and if need-be bluetooth or zigbee to interface with a ‘real’ computer. I also figured this platform could be tweaked to run off batteries (low-power) and programmed reasonably fast.

The Display

I was looking for a display that wasn’t too big, color, and of a reasonable resolution. So the 1.8″ TFT Display display, with a SD card slot to boot, seemed like a good fit even if it requires good eye-sight.

Hooking it up and getting it to display properly was a breeze with Lady Ada’s tutorial.

Display Orientation – Problem 1

The library that the tutorial uses has the display setup for a vertical (portrait) orientation, not the horizontal (landscape) orientation I wanted. The tutorial library contains the function setRotation() which I tried.

Digging through the tutorial library code reveals that setRotation() controls the MADCLT variable in the display’s chip. Looking at the datasheet for the ST7735 display chip (image below) shows that MADCLT can be used to rotate the display: the third most significant bit of MADCLT flips the Row/Column Order.

ST7735 Documentation pg85

When the display is initialized with the initR() function (I used the 2011-08-15 version of the ST7735 library) MADCLT is set to 0xC8. I figured out from the documentation that I wanted 0x68 instead. Success, the text is rotated correctly.

Changing MADCLT on the ST7735 1.8" TFT Display

Display Resolution – Problem 2

Well, partial success. The information is correctly rotated, however, the screen resolution is now incorrect (text runs off the screen and the previous image is still visible on the side). Calling setRotation() did not flip the width and height resolution values. These must be changed in ST7735.h and are located in the following two lines:

  static const uint8_t width = 160;
  static const uint8_t height = 128;

Display Border – Problem 3

Needing to change CASET and RASET on the ST7735 1.8" TFT DisplayChanging the display’s resolution almost completely fixed the problem. However, a line 1 pixel wide is no longer updated. It is present on the left and bottom sides (yellow lines in the picture to the right). To fix this requires changing the CASET and RASET values in the ST7735. In the ST7735.cpp file under the setAddrWindow() function there are some integers added to the x and y values passed to CASET and RASET. These need to be flipped: the +1 needs to be moved to the x values and the +2 needs to be moved to the y values. The final function should read:

void ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
{
  writecommand(ST7735_CASET);  // column addr set
  writedata(0x00);
  writedata(x0+1);   // XSTART     (switch +2 to rotate screen)
  writedata(0x00);
  writedata(x1+1);   // XEND    (switch +2 to rotate screen)

  writecommand(ST7735_RASET);  // row addr set
  writedata(0x00);
  writedata(y0+2);    // YSTART    (switch +1 to rotate screen)
  writedata(0x00);
  writedata(y1+2);    // YEND    (switch +1 to rotate screen)

  writecommand(ST7735_RAMWR);  // write to RAM
}

Conclusions

I personally made these changes in the ST7735 library files since I only plan on using this display in the horizontal orientation. It may be wise to make these modifications through function calls although I did not seen an easy way to do this. Especially since width and height are defined as constants in the ST7735.h file.

 Arduino with 1.8" TFT ST7735 Logging Temperature Data

3 Responses to “Temperature Logging – Part 1”

  1. on 09 Dec 2012 at 1:13 pmpinnchus

    I still does not understand why you need to increment the first column by 2 in the setAddrWindow function.
    Do you? Can explain this?

    Regards,

  2. on 10 Dec 2012 at 7:31 pmJed

    It has been awhile since I last looked at this, but my recollection is the indices need the +1 and +2, depending on rotation orientation, to center what you are displaying on the screen correctly. I’m not sure if there is an unused buffer around the edge of the screen that doesn’t get displayed, or if it is from a coding ‘issue’ in the ST7735 library.

  3. on 14 Sep 2019 at 9:02 pmHariprashanth Elangovan

    Thanks the indices adjustment helped!

Trackback URI | Comments RSS

Leave a Reply