Welcome Guest, you are in: Login

Netduino Wiki

RSS RSS

Navigation





Search the wiki
»

PoweredBy

DFRobot LCD Shield

RSS
Modified on 2011/12/17 13:18 by Eric Falsken Categorized as Expansion Shields
Image

The DFRobot LCD Shield (wiki) uses only 7 digital I/O pins for the backlight and LCD display and 1 analog pin for the buttons. The board works great, except for the "select" button. (see below) Also please note that the buttons are wired to the analog pin, not to a digital pin. As such, you won't be able to specify an interrupt for them, requiring you to poll constantly for the current button state.

public static void Main() {
	var lcdshield = new DfRobotLcdShield();
	lcdshield.SetCursorPosition(0, 0);
	lcdshield.Write("DF ROBOT Shield");
	lcdshield.SetCursorPosition(0, 1);
	lcdshield.Write("v1.0   ready...");

	while (true) {
		lcdshield.SetCursorPosition(7, 1);
		string buttonName = DfRobotLcdShield.ButtonNames[(int)lcdshield.ButtonState];
		while (buttonName.Length < 9)
			buttonName += " ";
		lcdshield.Write(buttonName);

		Thread.Sleep(100);
	}
}

public class DfRobotLcdShield : MicroLiquidCrystal.Lcd {
	readonly OutputPort backlight;
	readonly AnalogInput analog;

	const int a_KEY_UP = 225;
	const int a_KEY_DOWN = 500;
	const int a_KEY_LEFT = 800;
	const int a_KEY_SELECT = 900;
	const int a_KEY_RIGHT = 50;
	const int a_KEY_NONE = 1000;

	public DfRobotLcdShield() : base (new GpioLcdTransferProvider(
			Pins.GPIO_PIN_D8,
			Pins.GPIO_PIN_D9,
			Pins.GPIO_PIN_D4,
			Pins.GPIO_PIN_D5,
			Pins.GPIO_PIN_D6,
			Pins.GPIO_PIN_D7)) {

		backlight  = new OutputPort(Pins.GPIO_PIN_D10, true);
		analog = new AnalogInput(Pins.GPIO_PIN_A0);

		this.Begin(16, 2);
		this.Clear();
	}

	public new bool Backlight {
		get { return backlight.Read(); }
		set { backlight.Write(value); }
	}

	public readonly static string[] ButtonNames = { "Right", "Up", "Down", "Left", "Select", "None" };

	public enum Buttons {
		Right,
		Up,
		Down,
		Left,
		Select,
		None
	}

	public Buttons ButtonState {
		get {
			int adc_key = analog.Read();
			Debug.Print("GPIO_A0 = " + adc_key.ToString());
			if (adc_key > a_KEY_NONE) return Buttons.None;
			if (adc_key < a_KEY_RIGHT) return Buttons.Right;
			if (adc_key < a_KEY_UP) return Buttons.Up;
			if (adc_key < a_KEY_DOWN) return Buttons.Down;
			if (adc_key < a_KEY_LEFT) return Buttons.Left;
			if (adc_key < a_KEY_SELECT) return Buttons.Select;
			return Buttons.None;
		}
	}
}



Select button

Because the shield uses a 5-stage voltage divider for the buttons, and because it uses 5v as the reference voltage, the Select button value exceeds the Netduino's analog-to-digital converter. You will not be able to tell the difference between Buttons.None and Buttons.Select.

You can work around this if you desolder or clip the 5v pin and jump it to the 3.3v pin. The LCD display works that low (according to the datasheet) and the 5-stage voltage divider for the buttons will still divide by the same ratios, allowing you to detect the Select button correctly. However the LCD contrast suffers and is barely visible even at zero resistance.

ScrewTurn Wiki version 3.0.4.560. Some of the icons created by FamFamFam.