Skip to content

Commit

Permalink
Merge pull request #256 from Tinyu-Zhao/master
Browse files Browse the repository at this point in the history
add some Example&explain
  • Loading branch information
Gitshaoxiang authored Aug 12, 2021
2 parents 462a4da + d7c0e42 commit 57765e7
Show file tree
Hide file tree
Showing 61 changed files with 2,555 additions and 2,048 deletions.
19 changes: 0 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ https://docs.m5stack.com/#/en/api

## 4. H/W Reference

#### Pinout

*We have several kinds of M5Cores, There is [their difference in schematic](https://github.com/m5stack/M5-Schematic/blob/master/Core/hardware_difference_between_cores.md).*

**LCD & TF Card**

*LCD Resolution: 320x240*
Expand All @@ -41,7 +37,6 @@ https://docs.m5stack.com/#/en/api
<tr><td>ESP32 Chip</td><td>GPIO23</td><td>GPIO19</td><td>GPIO18</td><td>GPIO14</td><td>GPIO27</td><td>GPIO33</td><td>GPIO32</td><td>GPIO4</td></tr>
<tr><td>ILI9341</td><td>MOSI/MISO</td><td>/</td><td>CLK</td><td>CS</td><td>DC</td><td>RST</td><td>BL</td><td> </td></tr>
<tr><td>TF Card</td><td>MOSI</td><td>MISO</td><td>CLK</td><td> </td><td> </td><td> </td><td> </td><td>CS</td></tr>

</table>

**Button & Speaker**
Expand Down Expand Up @@ -71,8 +66,6 @@ https://docs.m5stack.com/#/en/api
* [TFT_eSPI](https://github.com/Bodmer/TFT_eSPI) - TFT library for the ESP8266 and ESP32 that supports different driver chips


* [M5Widgets](https://github.com/Kongduino/M5Widgets) - Widgets for the M5Stack

* [M5StackSAM](https://github.com/tomsuch/M5StackSAM) - Simple Applications Menu Arduino Library for M5Stack

* [cfGUI](https://github.com/JF002/cfGUI) - A simple GUI library for M5Stack (ESP32)
Expand Down Expand Up @@ -123,18 +116,6 @@ https://docs.m5stack.com/#/en/api

* [M5Stack-Thermal-Camera](https://github.com/hkoffer/M5Stack-Thermal-Camera-) - M5Stack Thermal Camera with AMG8833 thermal sensor

* [M5Stack-3DPrintFiles](https://github.com/PartsandCircuits/M5Stack-3DPrintFiles) - Links to files for 3D printing custom case parts for the M5Stack

* [truetype2gfx](https://github.com/ropg/truetype2gfx) - Converting fonts from TrueType to Adafruit GFX

* [m5stack-onscreen-keyboard](https://github.com/yellowelise/m5stack-onscreen-keyboard) - Full size qwerty keyboard for M5Stack

#### Note:

* How to install USB driver for establishing serial port

https://docs.m5stack.com/#/en/related_documents/establish_serial_connection

* How to upgrade M5Stack Libary

https://docs.m5stack.com/#/en/related_documents/upgrade_m5stack_lib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma mark - Depend ESP8266Audio and ESP8266_Spiram libraries
/*
/*
cd ~/Arduino/libraries
git clone https://github.com/earlephilhower/ESP8266Audio
git clone https://github.com/Gianbacchio/ESP8266_Spiram
Expand All @@ -23,9 +23,9 @@ void setup()
{
M5.begin();
M5.Power.begin();
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_OFF);
delay(500);

M5.Lcd.setTextFont(2);
M5.Lcd.printf("Sample MP3 playback begins...\n");
Serial.printf("Sample MP3 playback begins...\n");
Expand Down
44 changes: 44 additions & 0 deletions examples/Advanced/Display/Display_Unicode/Display_Unicode.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/core/gray
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
*
* describe:Display_Unicode. Unicode显示
* date:2021/7/23
*******************************************************************************
-----PLEASE SEE THE README----
------请在使用前看README文件----*/
#include <M5Stack.h>
#include "CUF_24px.h"

void setup()
{
M5.begin(); //Init M5Stack. 初始化M5Stack
M5.Power.begin(); //Init power 初始化电源模块
M5.Lcd.setFreeFont(&unicode_24px); //Set the GFX font to use. 设置要使用的GFX字体
M5.Lcd.setTextDatum(TC_DATUM); //Set text alignment to center-up alignment. 设置文本对齐方式为居中向上对齐
}

void loop()
{
M5.Lcd.fillScreen(0);
M5.Lcd.drawString("Hello world", 160, 60, 1); //Hello world is displayed in font 1 on (1600.60).
M5.Lcd.drawString("你好 世界", 160, 90, 1); //在(160,60)处以字体1显示hello world
M5.Lcd.drawString("Здравствуй мир", 160, 120, 1);
M5.Lcd.drawString("こんにちは せかい", 160, 150, 1);
delay(3000);

M5.Lcd.fillScreen(0); //Fill the screen with black (used to clear the screen) is equivalent to clear (). 使屏幕充满黑色(用来清屏)等同于clear()
M5.Lcd.setCursor(0, 30); // Set the text cursor 0,30 position. 设置文本光标在(0,30)处
M5.Lcd.printf("☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓☔☕☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☸☹☺☻☼☽☾☿♀♁♂♃♄♅♆♇♈♉♊♋♌♍♎♏♐♑♒♓♔♕♖♗♘♙♚♛♜♝♞♟♠♡♢♣♤♥♦♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚇⚈⚉⚊⚋⚌⚍⚎⚏⚐⚑⚒⚓⚔⚕⚖⚗⚘⚙⚚⚛⚜⚝⚞⚟A⚠⚡⚢⚣⚤⚥⚦⚧⚨⚩⚪⚫⚬⚭⚮⚯B⚰⚱⚲⚳⚴⚵⚶⚷⚸⚹⚺⚻⚼⚽⚾⚿C⛀⛁⛂⛃⛄⛅⛆⛇⛈⛉⛊⛋⛌⛍⛎⛏D⛐⛑⛒⛓⛔⛕⛖⛗⛘⛙⛚⛛⛜⛝⛞⛟E⛠⛡⛢");
delay(3000);

M5.Lcd.fillScreen(0);
M5.Lcd.setCursor(0, 30);
M5.Lcd.printf("⛣⛤⛥⛦⛧⛨⛩⛪⛫⛬⛭⛮⛯F⛰⛱⛲⛳⛴⛵⛶⛷⛸⛹⛺⛻⛼⛽⛾⛿✀✁✂✃✄✅✆✇✈✉✊✋✌✍✎✏✐✑✒✓✔✕✖✗✘✙✚✛✜✝✞✟✠✡✢✣✤✥✦✧✨✩✪✫✬✭✮✯✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞❟❠❡❢❣❤❥❦❧❨❩❪❫❬❭❮❯❰❱❲❳❴❵❶❷❸❹❺❻❼❽❾❿➀➁➂➃➄➅➆➇➈➉➊➋➌➍➎➏➐➑➒➓➔➕➖➗➘➙➚➛➜➝➞➟A➠➡➢➣➤➥➦➧➨➩➪➫➬➭➮➯B➰➱➲➳➴➵➶➷➸➹➺➻➼➽➾➿");
delay(3000);
}
52 changes: 52 additions & 0 deletions examples/Advanced/Display/Display_Unicode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Please modify <m5stack path>/src/utility/In_eSPI_Setup.h, At the end of the file add "#define USE_M5_FONT_CREATOR"

if use PlatformIO, need add "board_build.partitions = no_ota.csv" in platformio.ini

if want get customize unicode, try use https://github.com/m5stack/FontCreator, create font file

if add "#define USE_M5_FONT_CREATOR" and want to use standard gfx font, need modify font file
#ifdef USE_M5_FONT_CREATOR
0, 0,
#endif
like:

``` cpp
const GFXfont FreeMono12pt7b PROGMEM = {
(uint8_t *)FreeMono12pt7bBitmaps,
(GFXglyph *)FreeMono12pt7bGlyphs,
0x20, 0x7E, 24,
#ifdef USE_M5_FONT_CREATOR
0, 0,
#endif
}
```
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
zh:
如果编译过程中出现错误,请在<m5stack path>/src/utility/In_eSPI_Setup.h 中最后一行添加#define USE_M5_FONT_CREATOR
如果你使用platformIO,需要在platformio.ini中添加board_build.partitions = no_ota.csv
如果你想自定义unicode,请尝试使用https://github.com/m5stack/FontCreator 去创建相关字体文件
如果添加了“#define USE_M5_FONT_CREATOR”,并且想使用标准的gfx字体,需要修改CUF_24px.h文件
```cpp
#ifdef USE_M5_FONT_CREATOR
#define _unicode_24px_H_
const GFXfont FreeMono12pt7b PROGMEM = {
(uint8_t *)FreeMono12pt7bBitmaps,
(GFXglyph *)FreeMono12pt7bGlyphs,
0x20, 0x7E, 24,
};
#endif
```



100 changes: 35 additions & 65 deletions examples/Advanced/Display/HZK16/HZK16.ino
Original file line number Diff line number Diff line change
@@ -1,76 +1,46 @@
/*
在 src.h 文件中 GbkStr 显示为乱码为正常现象
HZK16为GB2312中文编码格式字库, 需要显示中文建议使用notepad++或其它软件(Arduino IDE 为UTF-8)通过编码GB2312打开str.h
即可修改为个人想要输出中文字符
*/
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/core/gray
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
*
* describe:Character library. 字库
* date:2021/7/28
*******************************************************************************
-----PLEASE SEE THE README----
------请在使用前看README文件----*/

#include <M5Stack.h>
#include "display_ch.h"
#include "str.h"

DisplayCh displaych;
void setup() {

M5.begin();
M5.Power.begin();
displaych.loadHzk16();

displaych.setTextColor(WHITE, BLACK);

M5.begin(); //Init M5Stack. 初始化M5Stack
M5.Power.begin(); //Init power 初始化电源模块
displaych.loadHzk16(); //Load the Chinese character library (be sure to load before using the Chinese character library). 加载汉字库(务必在使用汉字库前加载)
displaych.setTextColor(WHITE, BLACK); //Set the text color to white and the text background color to black (mandatory). 设置文字颜色为白色,文字背景颜色为黑色(必加)
// Set text with red highlight color
displaych.setHighlightColor(RED);

// Set text size to 1
displaych.setTextSize(1);
displaych.setCursor(0,0,1);
displaych.writeHzk(AscStr);
// Print some ASCII text on the screen
delay(1000);
// Highlight the text
displaych.highlight(true);
displaych.setCursor(0,32);
displaych.writeHzk(AscStr);
delay(1000);
// Clear screen
//M5.Lcd.clear();
// Turn highlight off
displaych.highlight(false);
displaych.setCursor(0,70);
// print some GBK text on the screen
displaych.writeHzk(GbkStr);

delay(1000);
displaych.highlight(true);
displaych.setCursor(0,90);
displaych.writeHzk(GbkStr);

delay(1000);
displaych.fillScreen(BLACK);

// Set text size to 2
displaych.setTextSize(2);
displaych.setCursor(0,0);
displaych.highlight(false);
displaych.writeHzk(AscStr);
delay(1000);
displaych.highlight(true);
displaych.setCursor(0,70);
displaych.writeHzk(AscStr);
delay(1000);

//displaych.clear();
displaych.highlight(false);
displaych.setCursor(0,145);
displaych.writeHzk(GbkStr);
delay(1000);
displaych.highlight(true);
displaych.setCursor(0,195);
displaych.writeHzk(GbkStr);


displaych.setHighlightColor(RED); //Set the text highlight color to red. 设置文字高亮颜色为红色
displaych.setTextSize(1); //Set text size to 1. 设置字号大小为1 Set text size to 1(必加)
}

void loop() {
// put your main code here, to run repeatedly:

}
displaych.setCursor(0,0,1); //Set the cursor at (0,0) and the size to 1(mandatory). 将光标设置在(0,0)处,并设置字号为1(必加)
displaych.writeHzk(AscStr); //Display the contents of AscStr here (which can be changed in str.h). 在此处显示AscStr中的内容(可在str.h中更改)
delay(1000); //delay 1000ms. 延迟1000ms
displaych.setCursor(0,45);
displaych.writeHzk(GbkStr); //Display the contents of GbkStr here (which can be changed in str.h). 在此处显示GbkStr中的内容(可在str.h中更改)
delay(1000);
//Highlight the text. 高亮显示文本
displaych.highlight(true); //Turn on highlight. 开启高亮显示
displaych.setCursor(0,65);
displaych.writeHzk(GbkStr);
delay(1000);
displaych.fillScreen(BLACK); //Fill the screen with black color, equivalent to empty the screen. 填充屏幕颜色为黑色,等效于清空屏幕
displaych.highlight(false); //Turn off highlight. 关闭高亮显示
delay(500);
}
7 changes: 7 additions & 0 deletions examples/Advanced/Display/HZK16/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HZK16 is the GB2312 Chinese encoding format font, so it is normal that GbkStr is displayed as garbled in the src.h file
To display Chinese normally, notepad++ or other software (UTF-8 for Arduino IDE) should be used to open str.h with encoding GB2312
Modify the content in GbkStr to replace it with the character you want to display

HZK16为GB2312中文编码格式字库, 故在 src.h 文件中 GbkStr 显示为乱码为正常现象
若要正常显示中文应使用notepad++或其它软件(Arduino IDE 为UTF-8)使用编码GB2312打开str.h
修改GbkStr里的内容即可更换为想要显示的字符
4 changes: 2 additions & 2 deletions examples/Advanced/Display/HZK16/str.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _STR_H_
#define _STR_H_

char* AscStr="ASCII: \nABCDEFG1234567";
char* GbkStr="²É¾Õ¶«ÀéÏÂ";
char* AscStr="ASCII: ABCDEFG1234567";
char* GbkStr="Tao yuanming:²É¾Õ¶«ÀéÏ ¤³¤ó¤Ë¤Á¤Ï";

#endif
30 changes: 16 additions & 14 deletions examples/Advanced/Display/TFT_Ellipse/TFT_Ellipse.ino
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
/*
Ellipse drawing example
This sketch does not use any fonts.
*/
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/core/gray
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
*
* describe:Ellipse drawing. 椭圆绘制
* date:2021/7/26
*******************************************************************************/

#include <M5Stack.h>

void setup(void) {
M5.begin();
M5.Power.begin();
// M5.Lcd.setRotation(1);
M5.begin(); //Init M5Stack. 初始化M5Stack
M5.Power.begin(); //Init power 初始化电源模块
}

void loop() {

M5.Lcd.fillScreen(TFT_BLACK);

// Draw some random ellipses
// Draw some random ellipses. 绘制一些随机形状的椭圆
for (int i = 0; i < 40; i++)
{
int rx = random(60);
int ry = random(60);
int x = rx + random(320 - rx - rx);
int y = ry + random(240 - ry - ry);
M5.Lcd.fillEllipse(x, y, rx, ry, random(0xFFFF));
M5.Lcd.fillEllipse(x, y, rx, ry, random(0xFFFF)); //At (x, y), draw a filled ellipse with random width and height of rx, ry with random color random (0xFFFF). 在(x,y)处以随机颜色random(0xFFFF),绘制一个随机宽高为rx,ry的填充椭圆
}

delay(2000);
M5.Lcd.fillScreen(TFT_BLACK);
M5.Lcd.clear(); //清空屏幕

for (int i = 0; i < 40; i++)
{
int rx = random(60);
int ry = random(60);
int x = rx + random(320 - rx - rx);
int y = ry + random(240 - ry - ry);
M5.Lcd.drawEllipse(x, y, rx, ry, random(0xFFFF));
M5.Lcd.drawEllipse(x, y, rx, ry, random(0xFFFF));//At (x, y), draw an elliptical wire frame with a random width and height of rx, ry in a random color (0xFFFF). 在(x,y)处以随机颜色random(0xFFFF),绘制一个随机宽高为rx,ry的椭圆线框
}

delay(2000);
Expand Down
Loading

0 comments on commit 57765e7

Please sign in to comment.