|
| 1 | +/********************************************************************* |
| 2 | +This file is a part of a library for NKK LCD 64x32 SmartDisplay |
| 3 | +
|
| 4 | +Copyright (c) 2021, IFH |
| 5 | +All rights reserved. |
| 6 | +
|
| 7 | +GNU General Public License, check license.txt for more information |
| 8 | +All text above must be included in any redistribution |
| 9 | +*********************************************************************/ |
| 10 | +/* |
| 11 | +NKK Smart Display LCD 64*32 test code using library NKK_SmartDisplayLCD |
| 12 | + |
| 13 | + example 02- NKK as a library, |
| 14 | + using Maple Mini hardware (http://docs.leaflabs.com/static.leaflabs.com/pub/leaflabs/maple-docs/0.0.12/hardware/maple-mini.html) |
| 15 | + and Arduino STM32 core (https://github.com/rogerclarkmelbourne/Arduino_STM32) |
| 16 | +
|
| 17 | + Status: works ok |
| 18 | +
|
| 19 | +
|
| 20 | +// hardware setup for Maple Mini |
| 21 | + //Use SPI_2 as it is 5v tolerant |
| 22 | + // Maple Mini SS (NCS) <--> PB12 D31 pin no 31 -> NKK SS (Signal is managed by NKK library to allow running several NKK devices with their own SS pins) |
| 23 | + // Maple Mini SCK (CLK) <--> PB13 D30 pin no 30 -> NKK SCK (Clock for serial communication, maximum 8 MHZ) |
| 24 | + // Maple Mini MISO (SPI) <--> PB14 D29 pin no 29 -> NKK SDO (This is not required for NKK devices - no data output back from the NKK device) |
| 25 | + // Maple Mini MOSI (SDO) <--> PB15 D28 pin no 15 -> NKK SDI |
| 26 | + |
| 27 | + //Please note that STM32F103CBT6 is 3.3v and NKK LCD 64x32 SmartDisplay is 5v. While direct connection without a level shifter works with that example, |
| 28 | + //such hardware setup is at your own risk. |
| 29 | +*/ |
| 30 | + |
| 31 | +#include <SPI.h> |
| 32 | +#include <NKKSmartDisplayLCD.h> |
| 33 | + |
| 34 | +//Setup SPI |
| 35 | +#define SPIDEVICE_CS 31 //note this is for the SPI setup only. Actual SS signal is managed by NKK library to allow running several NKK devices with their own SS pins. |
| 36 | +SPIClass SPI_2(2); //Create an instance of the SPI Class called SPI_2 that uses the 2nd SPI Port |
| 37 | + |
| 38 | +//Setup images |
| 39 | +//Note: for simplisity we do not use PROGMEM |
| 40 | + //"TEST 1" text with a corner white triangle * |
| 41 | + byte imgTest1[] = |
| 42 | + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,127,131,131,241,252,0,5,0,8,4,64,16,32,0,4,128,8,0,64,16,32,0,4,64,8,0,64,16,32,0,4,0,8,0,64,16,32,0,4,0,8,0,128,16,32,0,4,0,8,1,0,240,32,0,4,0,8,2,0,16,32,0,4,0,8,4,0,16,32,0,4,0,8,4,0,16,32,128,4,0,8,4,0,16,32,192,4,0,8,4,64,16,32,160,63,128,8,3,131,240,32,144,0,0,0,0,0,0,0,136,0,0,0,0,0,0,0,132,0,0,0,0,0,0,0,130,0,0,0,0,0,0,0,129,0,0,0,0,0,0,0,128,128,0,0,0,0,0,0,128,64,0,0,0,0,0,0,128,32,0,0,0,0,0,0,128,16,0,0,0,0,0,0,128,8,0,0,0,0,0,0,128,4,0,0,0,0,0,0,128,2,0,0,0,0,0,0,128,1,0,0,0,0,0,0,255,255,128,0,0,0,0,0 |
| 43 | + }; |
| 44 | + |
| 45 | + // Test GFX - landscape |
| 46 | + byte imgGFX1[] = |
| 47 | + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,241,131,131,127,0,0,0,32,16,64,4,8,0,0,0,32,16,64,0,8,224,125,17,32,16,64,0,8,16,4,10,32,16,64,0,8,16,4,4,32,16,128,0,8,144,61,4,32,240,0,1,8,16,5,4,32,16,0,2,8,16,5,10,32,16,0,4,8,224,4,17,32,16,0,4,8,0,0,0,32,16,0,4,8,0,0,128,32,16,64,4,8,0,0,192,32,240,131,3,8,0,0,160,0,0,0,0,0,0,0,144,0,0,0,0,0,0,0,136,0,0,0,0,0,0,0,132,0,0,0,0,0,0,0,130,0,0,0,0,0,0,0,129,0,0,0,0,0,0,128,128,0,0,0,0,0,0,64,129,0,0,0,0,0,0,32,130,0,0,0,0,0,0,16,132,0,0,0,0,0,0,8,136,0,0,0,0,0,0,4,144,0,0,0,0,0,0,2,160,0,0,0,0,0,0,1,192,0,0,0,0,0,128,255,255 |
| 48 | + }; |
| 49 | + |
| 50 | + // Test GFX - portrait |
| 51 | + byte imgGFX2[] = |
| 52 | + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,152,31,248,253,164,31,96,12,6,6,96,12,6,6,96,12,6,6,96,12,4,6,96,60,8,6,96,12,16,6,96,12,32,6,96,12,96,6,96,12,96,6,96,12,96,6,96,252,36,6,96,252,24,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,247,69,0,64,16,40,0,64,16,16,0,64,246,16,0,64,20,16,0,64,20,40,0,128,19,68,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,64,0,0,0,32,0,0,0,16,0,0,0,8,32,0,0,4,112,0,0,2,168,0,0,1,36,1,128,0,32,0,64,0,32,0,32,0,32,0,16,0,32,0,8,0,32,0,20,0,32,0,34,0,32,0,65,0,32,128,128,0,32,64,0,1,32,32,0,2,0,16,0,4,0,8,0,8,0,4,0,16,0,2,0,32,0,1,0,64,128,0,0,128 |
| 53 | + }; |
| 54 | + |
| 55 | + |
| 56 | +// Initialise NKK device |
| 57 | + //Landscape |
| 58 | + NKK_SmartDisplayLCD NKK = NKK_SmartDisplayLCD(64,32,0,SPIDEVICE_CS,1000000,&SPI_2); |
| 59 | + //Portrait,with 180 rotation |
| 60 | + //NKK_SmartDisplayLCD NKK = NKK_SmartDisplayLCD(32,64,1,SPIDEVICE_CS,1000000); |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +void setup() { |
| 65 | + pinMode(SPIDEVICE_CS, OUTPUT); |
| 66 | + |
| 67 | + //============================== |
| 68 | + Serial.begin(9600); |
| 69 | + //Serial.begin(115200); |
| 70 | + //The program will wait for serial to be ready up to 10 sec then it will continue anyway |
| 71 | + for (int i=1; i<=10; i++){ |
| 72 | + delay(1000); |
| 73 | + if (Serial){ |
| 74 | + break; |
| 75 | + } |
| 76 | + } |
| 77 | + Serial.println("Setup() started "); |
| 78 | + //=============================== |
| 79 | + |
| 80 | + |
| 81 | +//start SPI interface |
| 82 | + SPI_2.begin(); |
| 83 | + |
| 84 | +// start NKK device |
| 85 | + NKK.begin(); |
| 86 | + |
| 87 | +} |
| 88 | + |
| 89 | + |
| 90 | +void loop() { |
| 91 | + |
| 92 | + |
| 93 | + NKK.reset(); |
| 94 | + |
| 95 | +//test NKK colours |
| 96 | + NKK.setColourNKK(255); //White |
| 97 | + NKK.setBrightness(255); |
| 98 | + delay (1000); |
| 99 | + NKK.setColourNKK(195); //Red |
| 100 | + delay (1000); |
| 101 | + NKK.setColourNKK(51); //Green |
| 102 | + delay (1000); |
| 103 | + NKK.setColourNKK(15); //Blue |
| 104 | + delay (1000); |
| 105 | + NKK.setColourNKK(255); //White |
| 106 | + delay (1000); |
| 107 | + |
| 108 | +//test NKK image transfer |
| 109 | + for(uint16_t i=0; i<256; i++) |
| 110 | + { |
| 111 | + NKK.imageBufferNKK[i] = imgTest1[i]; |
| 112 | + } |
| 113 | + NKK.display_NKK(); |
| 114 | + delay (2000); |
| 115 | + |
| 116 | + |
| 117 | +//test RGB colour |
| 118 | + NKK.setColourRGB(255,255,0); // set Yellow |
| 119 | + //delay (1000); |
| 120 | + |
| 121 | +// test GFX image transfer |
| 122 | + for(uint16_t i=0; i<256; i++) |
| 123 | + { |
| 124 | + NKK.imageBufferGFX[i] = imgGFX1[i]; |
| 125 | + |
| 126 | + } |
| 127 | + NKK.display(); |
| 128 | + delay (2000); |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | +}// End of the Loop |
| 133 | + |
| 134 | + |
0 commit comments