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 printf
s, 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)
scanf
to read the number and the program to continue?
(you may need a reference to check the behaviour of scanf
)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.
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)
x
, y
horizontal and vertical positioncolour
1 set pixel, 0 erase pixelvoid circle(int x, int y, int r, int colour);
x0
,y0
centre of circler
radiuscolor
1 set pixel, 0 erase pixelvoid fillcircle(int x, int y, int r, int colour);
x0
,y0
centre of circler
radiuscolor
1 set pixel, 0 erase pixelvoid line(int x0, int y0, int x1, int y1, int colour);
x0
,y0
start pointx1
,y1
start pointcolor
1 set pixel, 0 erase pixelvoid rect(int x0, int y0, int x1, int y1, int colour);
x0
,y0
top left cornerx1
,y1
lower right cornercolor
1 set pixel, 0 erase pixelvoid fillrect(int x0, int y0, int x1, int y1, int colour);
x0
,y0
top left cornerx1
,y1
lower right cornercolor
1 set pixel, 0 erase pixelvoid cls(void);
void character(int x, int y, int c);
x
,y
position of character (top left of character)c
character to printvoid locate(int x, int y);
x
,y
position of character (top left of character)It also has printf
and other standard-output functions.
See s4.3 for a simple example.
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.
Use the Accelerometer Data to determine which way up the K64F is, and then display this on the LCD (and optionally PC)
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)
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?