image.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright (c) 2014 Adafruit Industries
  2. # Author: Tony DiCola
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. from PIL import Image
  22. import ST7735 as TFT
  23. import Adafruit_GPIO as GPIO
  24. import Adafruit_GPIO.SPI as SPI
  25. WIDTH = 128
  26. HEIGHT = 160
  27. SPEED_HZ = 4000000
  28. # Raspberry Pi configuration.
  29. #DC = 24
  30. #RST = 25
  31. DC = 24
  32. RST = 23
  33. SPI_PORT = 0
  34. SPI_DEVICE = 0
  35. # BeagleBone Black configuration.
  36. # DC = 'P9_15'
  37. # RST = 'P9_12'
  38. # SPI_PORT = 1
  39. # SPI_DEVICE = 0
  40. # Create TFT LCD display class.
  41. disp = TFT.ST7735(
  42. DC,
  43. rst=RST,
  44. spi=SPI.SpiDev(
  45. SPI_PORT,
  46. SPI_DEVICE,
  47. max_speed_hz=SPEED_HZ))
  48. # Initialize display.
  49. disp.begin()
  50. # Load an image.
  51. print('Loading image...')
  52. image = Image.open('cat.jpg')
  53. # Resize the image and rotate it so matches the display.
  54. image = image.rotate(90).resize((WIDTH, HEIGHT))
  55. # Draw the image on the display hardware.
  56. print('Drawing image')
  57. disp.display(image)