LCD & serial comms

Serial communications to the PC

We’ve already come across the Serial communications to the PC by using printf, and looking at the output using the Serial Monitor in Atom/PlatformIO

Example repository s4.1 shows how an explicit serial connection can be made. In practice there is no difference to using the plain printfs, unless a second serial channel is needed to other devices.

What properties can you observe (these may vary from PC to PC and OS to OS)

  1. At what point is data displayed?
  2. Is the line buffered? (does the terminal wait for the CR/LF before displaying anything)
  3. What causes the scanf to read the number and the program to continue? (you may need a reference to check the behaviour of scanf)
  4. What is the effect of the ANSI Escape sequence arround the “Hello” in the first print?
  5. What other ANSI Escape sequence is supported by the terminal?
  6. Why can’t you see characters you type in the terminal.

Accelerometer and Magnetometer

The K64F board has an integral Accelerometer and Magnetometer (the FXOS8700Q)

To use the library for the chip the platformio.ini file needs to register the library dependencies.

lib_deps =
  hg+https://os.mbed.com/teams/components/code/MotionSensor/
  hg+https://os.mbed.com/teams/NXP/code/FXOS8700Q/

This is done in example s4.2, fork and clone this to see how the libraries are used.

  1. What units is the acceleration reported in?
  2. What units is the magnetometer data reported in?
  3. Which way in up for the accelerometer?

LCD

The Application Shield uses the C12832 LCD Module.

PlatformIO and MBed supply the C12832 library for using the LCD. This needs to also go in the platformio.ini file:

lib_deps =
  C12832
  hg+https://os.mbed.com/teams/components/code/MotionSensor/
  hg+https://os.mbed.com/teams/NXP/code/FXOS8700Q/

The LCD is connected to specific pins and so the initialisation is fixed

C12832 lcd(D11, D13, D12, D7, D10);

The display is black and white, some of the functions supported are:

void pixel(int x, int y,int colour)
void circle(int x, int y, int r, int colour);
void fillcircle(int x, int y, int r, int colour);
void line(int x0, int y0, int x1, int y1, int colour);
void rect(int x0, int y0, int x1, int y1, int colour);
void cls(void);
void character(int x, int y, int c);
void locate(int x, int y);

It also has printf and other standard-output functions.

See s4.3 for a simple example.

LCD and Sensor use

LCD basics

Begin by working through some exercises that cover the basics of working with the LCD.

Repository s4.4 is set up to use the LCD and the Accelerometer sensor.

Which way is up?

Use the Accelerometer Data to determine which way up the K64F is, and then display this on the LCD (and optionally PC)

Digital level

Use the sensor data to measure how far away from level the K64F is. Display this information on the LCD using suitable graphics (for inspiration see https://en.wikipedia.org/wiki/Spirit_level)

Digital compass

This may need some research before attempting it.

How is the magnetic field measured? How can the values be used to determine which way is north?

How can you work out which way the K64F is pointing and display this information as a digital compass?


© 2017   Dr Alun Moon
alun.moon@northumbria.ac.uk