lcd_skin.rst 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. The LCD and touch-sensor skin
  2. =============================
  3. Soldering and using the LCD and touch-sensor skin.
  4. .. image:: img/skin_lcd_1.jpg
  5. :alt: pyboard with LCD skin
  6. :width: 250px
  7. .. image:: img/skin_lcd_2.jpg
  8. :alt: pyboard with LCD skin
  9. :width: 250px
  10. The following video shows how to solder the headers onto the LCD skin.
  11. At the end of the video, it shows you how to correctly connect the LCD skin to the pyboard.
  12. .. raw:: html
  13. <iframe style="margin-left:3em;" width="560" height="315" src="http://www.youtube.com/embed/PowCzdLYbFM?rel=0" frameborder="0" allowfullscreen></iframe>
  14. For circuit schematics and datasheets for the components on the skin see :ref:`hardware_index`.
  15. Using the LCD
  16. -------------
  17. To get started using the LCD, try the following at the MicroPython prompt.
  18. Make sure the LCD skin is attached to the pyboard as pictured at the top of this page. ::
  19. >>> import pyb
  20. >>> lcd = pyb.LCD('X')
  21. >>> lcd.light(True)
  22. >>> lcd.write('Hello uPy!\n')
  23. You can make a simple animation using the code::
  24. import pyb
  25. lcd = pyb.LCD('X')
  26. lcd.light(True)
  27. for x in range(-80, 128):
  28. lcd.fill(0)
  29. lcd.text('Hello uPy!', x, 10, 1)
  30. lcd.show()
  31. pyb.delay(25)
  32. Using the touch sensor
  33. ----------------------
  34. To read the touch-sensor data you need to use the I2C bus. The
  35. MPR121 capacitive touch sensor has address 90.
  36. To get started, try::
  37. >>> import pyb
  38. >>> i2c = pyb.I2C(1, pyb.I2C.MASTER)
  39. >>> i2c.mem_write(4, 90, 0x5e)
  40. >>> touch = i2c.mem_read(1, 90, 0)[0]
  41. The first line above makes an I2C object, and the second line
  42. enables the 4 touch sensors. The third line reads the touch
  43. status and the ``touch`` variable holds the state of the 4 touch
  44. buttons (A, B, X, Y).
  45. There is a simple driver `here <http://micropython.org/resources/examples/mpr121.py>`__
  46. which allows you to set the threshold and debounce parameters, and
  47. easily read the touch status and electrode voltage levels. Copy
  48. this script to your pyboard (either flash or SD card, in the top
  49. directory or ``lib/`` directory) and then try::
  50. >>> import pyb
  51. >>> import mpr121
  52. >>> m = mpr121.MPR121(pyb.I2C(1, pyb.I2C.MASTER))
  53. >>> for i in range(100):
  54. ... print(m.touch_status())
  55. ... pyb.delay(100)
  56. ...
  57. This will continuously print out the touch status of all electrodes.
  58. Try touching each one in turn.
  59. Note that if you put the LCD skin in the Y-position, then you need to
  60. initialise the I2C bus using::
  61. >>> m = mpr121.MPR121(pyb.I2C(2, pyb.I2C.MASTER))
  62. There is also a demo which uses the LCD and the touch sensors together,
  63. and can be found `here <http://micropython.org/resources/examples/lcddemo.py>`__.