Giter Site home page Giter Site logo

st7735-rs's Introduction

st7735-rs

This is a library for displays using the ST7735 driver. Documentation is available here.

Display example

Currently, there is support for using hardware SPI as well as software SPI to communicate to the display. Note that using hardware SPI is much faster and recommended to be used if supported by the connecting device.

The driver also provides a simple graphics library which currently supports drawing the following shapes:

  • Rectangles (filled and border only)
  • Circles (filled and border only)
  • Lines (horizontal, vertical, and diagonal)
  • Text (characters)

Usage

To use the crate please add the following to your Cargo.toml:

[dependencies]
st7735 = "0.1.0"

Please refer to /examples for more examples.

extern crate st7735;
use st7735::color::{Color, DefaultColor};
use st7735::fonts::font57::Font57;
use st7735::Orientation;
use st7735::ST7734;
use linux_embedded_hal::spidev::{SpidevOptions, SpidevTransfer, SPI_MODE_0};
use linux_embedded_hal::Spidev;
use linux_embedded_hal::Delay;
use linux_embedded_hal::Pin;

let mut spi = Spidev::open("/dev/spidev0.0").expect("error initializing SPI");
let options = SpidevOptions::new()
    .bits_per_word(8)
    .max_speed_hz(20_000)
    .mode(SPI_MODE_0)
    .build();
spi.configure(&options).expect("error configuring SPI");

let mut display = ST7734::new_with_spi(spi, Pin::new(25), Delay);display.clear_screen();
display.set_orientation(&Orientation::Portrait);
let color_red = Color::from_default(DefaultColor::Red);
display.draw_horizontal_line(0, 128, 20, &color_red);
display.draw_horizontal_line(0, 128, 140, &color_red);
display.draw_rect(30, 30, 60, 70, &Color::from_default(DefaultColor::Blue));

Connecting the Display

I tested this create using a Raspberry Pi model A and a SainSmart 1.8" TFT LCD Display with the following wiring for SPI:

Raspberry Pi Display
GND (Pin 6) CS
GPIO 25 (Pin 22) RS/DC
GPIO 10 (Pin 19) SDA
GPIO 11 (Pin 23) SCL
GND (Pin 6) GND
5V (Pin 2) VCC

When using the software SPI with other pins or even in the hardware SPI case it might be necessary to explicitly give permission to access GPIOs on the Raspberry Pi:

echo "25" > /sys/class/gpio/export
sudo sh -c 'echo out > /sys/class/gpio/gpio25/direction'

Building

To build this crate on the target platform (for example a Raspberry Pi) you can simply run cargo build if cargo is installed.

To build this crate on a platform used for development that is not the target platform (for example macOS), I recommend using crosstool-ng which will install the necessary toolchains. To build the crate for a Raspberry Pi model A run:

cargo build --target=arm-unknown-linux-gnueabi

For more details about installing required tools and setting up everything to build this crate, I wrote a more elaborate blog post about setting up Rust for embedded system programming on macOS.

Roadmap

  • Support more shapes
  • Support rendering text instead of just one character
  • Support more fonts
  • Add support for reading SD card
  • Draw bitmaps

Resources

This crate is based on the series Add a TFT Display to the Raspberry Pi by Bruce E. Hall and the Adafruit-ST7735-Library .

Contributing

Contributions are always welcome! Feel free to fork the repository and create pull-requests.

License

MIT

st7735-rs's People

Contributors

scholtzan avatar

Stargazers

 avatar Jan Krejci avatar irumeria avatar Serg Alex avatar Patrick Arminio avatar h kuro avatar Prashis avatar Sergey Golovin avatar Anand.M.L avatar cz avatar Guilherme Amorim avatar Caio Tavares avatar 高庆丰 avatar transistor fet avatar Mathias Hertlein avatar Paul Sajna avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

sajattack

st7735-rs's Issues

#![no_std] and embedded-hal support

Hi there, thanks for your driver, it looks great! Just a suggestion to open it up for use on non-linux boards (ie microcontrollers) -- if you make your driver #![no_std], and replace the SpiDev with embedded_hal::blocking::spi::Write, it opens up a whole new world of devices that can use your crate. Docs here. There is also linux-embedded-hal, so you wouldn't lose linux support. Oh, one more thing, you could use embedded-graphics rather than have your own special routines for drawing shapes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.