Inbedded

The Inside of an Embedded world !

BeagleBone Black and LCD = Fun

In my previous post I gave some instructions on how to rebuild the BeagleBone Black device-tree to allow for run-time override I also teased you with a little video of some activity on the Nokia 3330 LCD I attached to the BeagleBone. Today I’m back with some detailed information on:

  • The wiring of the BBB and the LCD
  • The device tree overlay file
  • Source code of the demo

Wiring the LCD to the BBB

I’ve been playing with Fritzing. It’s a nice tool that allows you to go from a prototype on a breadboard to a PCB in a seamless experience. I encourage you to give it a try. I used it to generate a schematic of the wiring between the LCD and the BBB. I used the BeagleBone Black symbol available here.

"BBB and Nokia 3330's LCD schematic"

The breadboard view:

"BBB and Nokia 3330's LCD connected using a breadboard"

The device tree overlay

Without waiting any longer here is the “beast”:

(cape-nokia-00A0.dts) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 *
 * Device tree overlay for a graphical LCD used on the Nokia 3330
 *
 * It is connected on SPI0 (SPI1 pins are used by HDMI cape on BBB)
 *
 * It uses two additional GPIO, 1 for reset and 1 for command / data switch
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

/dts-v1/;
/plugin/;

/*
 * Pin assignments
 *
 * LCD               Connector
 * 
 * 2 SPI CLK  <--   P9.22 SPI0_CLK
 * 3 SPI MOSI <--   P9.18 SPI0_D1
 * 4 D/C      <--   P9.15 GPIO
 * 5 SPI CE   <--   P9.17 SP0_CS0
 * 8 Reset    <--   P9.23 GPIO
 *
 */

/ {
	compatible = "ti,beaglebone", "ti,beaglebone-black";
	part-number = "BB-BONE-NOKIA-LCD";
	version = "00A0";

	fragment@0 {
		target = <&am33xx_pinmux>;
		__overlay__ {
		spi0_pinmux: spi0_pins  {
				pinctrl-single,pins = <
					0x150 0x30	/* spi0_sclk, INPUT_PULLUP  | MODE0 */
					0x154 0x30	/* spi0_d0,   INPUT_PULLUP  | MODE0 */
					0x158 0x10	/* spi0_d1,   OUTPUT_PULLUP | MODE0 */
					0x15C 0x10	/* spi0_cs0,  OUTPUT_PULLUP | MODE0 */
					>;
			};
		};
	};

	fragment@1 {
		target = <&spi0>;
		__overlay__ {
			status = "okay";
			pinctrl-names = "default";
			pinctrl-0 = <&spi0_pinmux>;
			nokia-lcd {
				compatible = "spidev";
				reg = <0>;
				spi-max-frequency = <16000000>;
				spi-cpol;
				spi-cpha;
			};
		};
	};

	fragment@2 {
		target = <&am33xx_pinmux>;
		__overlay__ {
		lcd_ctrl_pinmux: lcd_ctrl_pins {
				pinctrl-single,pins = <
					0x040 0x17 	/* gpio1_16  OUTPUT_PULLUP | MODE7 */
                                        0x044 0x17 	/* gpio1_17  OUTPUT_PULLUP | MODE7 */
					>;
			};
		};
	};

	
	fragment@3 {
		target = <&ocp>;
		__overlay__ {
		test_helper: helper {
				compatible = "bone-pinmux-helper";
				pinctrl-names = "default";
				pinctrl-0 = <&lcd_ctrl_pinmux>;
				status = "okay";
			};
		};
	};
};

As you can see the file is split in 4 segments.

  1. Defines the pinmux for the pins that are used by the spi0 port, note that the clock has to be an input to work !
  2. Overrides the spi0 driver properties and enable it by setting it’s status to “okay”. Inform the Kernel that the spidev driver must be used for that port. The reg property indicates that we use the chip select 0 for the LCD.
  3. Defines the pinmux for the gpio pins that are used to control the reset and the data/command pins
  4. Uses the bone-pinmux-helper driver to configure the GPIO pins as defined by lcd_ctrl_pinmux

There are a few concepts to grasp here:

Defining just a pinmux setting is not enough for the pins to be configured. You need a driver that uses the pinctrl framework for the pinmux to be configured. At the moment only a limited number of drivers make use of the pinctrl framework so if your driver doesn’t support it or if you just want to pinmux some GPIO pins you have to use the bone-pinmux-helper which handles the pinctrl for you.

It took me some time to get these rights so hopefully this should make your life easier.

Source code of the demo

I hacked together some code to control the LCD and draw some animation on the display. Use at your own risk. Get it HERE. Before running the demo you’ll have to execute the following commands once:

1
2
3
4
5
#/bin/sh
sudo echo "cape-nokia" > /sys/devices/bone_capemgr.9/slots
sudo echo "48" > /sys/class/gpio/export
sudo echo "49" > /sys/class/gpio/export
sudo echo "60" > /sys/class/gpio/export

They enable the device-tree overlay and export the gpio to sysfs. Note that there is an extra GPIO used for a buzzer that I beep everytime there is a collision on the screen. I’ll be pushing that to github at some point. [UPDATED: Now available on github]

You can see the result here:

Hope you’ll enjoy it.

Comments