2.HalfSweet (with temperature and humidity chip)
3.DUCK (without temperature and humidity chip )
~~~~~~~~~~~~~~~~~~~~~~~~~~ Split, you don’t need to look at it~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
8266How to read TXT files
Many people ask me how I can read novels on the ink screen.
Here I will only briefly talk about how to use 8266 to read TXT files in FLASH (UTF-8 only), without doing the ink screen test.
ASCIII encoding, UTF-8 encoding, Arduino 8266 development basics, file system basics
8266 module with serial port and FLASH, unlimited capacity.
First we need to understand the encoding knowledge and the encoding type used by the file. Only by knowing these can we process the file accordingly. Here we take UTF-8 (3 bytes) TXT text as an example.
A byte consists of 8 binary bits
ASCIII, range 0-127, that is, 00000000 to 01111111
ASCIII extension, range 128-255, that is, 1000000 to 11111111
UTF-8 encoding rules:
If it is a byte, then the first bit of this 8-bit byte is 0, which is all ASCIII, 0000 0000 to 0111 1111 (0-127)
If it is two bytes, then the first 4 bits of the first byte are 1100
If it is three bytes, then the first 4 bits of the first byte are 1110
From the Unicode character set, 0x4E00 represents the Chinese character one . The decimal value of 4E00 is 19968 and the binary value is 100 1110 0000 0000. According to the encoding rules of UTF-8, Chinese requires three bytes to be stored. The conversion result is 11100100 10111000 10000000.
Chinese is three bytes 1110XXXX XXXXXXXX XXXXXXXX, which starts with 1110 XXXX
ASCIII extension and other two bytes are 1100XXXX XXXXXXXX, which starts with 1100 XXXX
ASCIII is 0-127, >=0&&<=127
just judge it directly
So as long as you determine what the first byte read is, you can know whether it is Chinese or ASCIII.
So we use the file system to read the first byte of each character in the file, and then determine what type the byte is, Chinese? ASCIII extension or other two bytes? ASCIII?
The core code is as follows, and the complete sample code is attached at the end.
Serial.println("************ Single character output********* ");
String zf = ""; //Single character output
uint16_t zf_count = 0; //Statistical characters Number
txtFile = LittleFS.open("txt_test.txt", "r"); //Open txt file
if (txtFile != 1) Serial.println("txt_test.txt file does not exist");
while (txtFile.available ())//Start reading
{
zf_count++;
char c = txtFile.read();//Read a byte
byte a = B11100000;
byte b = c & a;
if (b == B11100000)//Chinese, etc. 3 byte characters
{
zf += c; //The first byte
zf += txtFile.read(); //The second byte
zf += txtFile.read(); //The third byte
}
else if (b == B11000000) //ascii extension or other 2-byte characters
{
zf += c; // first byte
zf += txtFile.read(); // second byte
}
else if (c >= 0 && c <= 127) //ascii characters
{
zf += c; //first byte
}
Serial.print("th" + String(zf_count) + "characters: ") ;
Serial.println(zf);
zf = "";
}
txtFile.close(); //Close the file
Expand
Let’s talk about the principle of displaying to the ink screen. Since the operation methods of each library are different, here we take the GXEPD2 library and U8g2_for_Adafruit_GFX as examples.
From the above code, we know how to deal with UTF-8 characters. We only need to add up each character, and then break the line after adding one line.
The specific number of lines that can be divided is determined by the width of the screen.
The number of words displayed in one line is determined by the length of the screen
For example, in 2.9-inch landscape mode, the length is 296 and the width is 128
If you use a 14*14 font, you can divide it into 128/14. Rounding is 9 lines, and each line is 296/14. Rounding is 21 Chinese characters.
If they are all in Chinese, you can change the line every 21 characters. Just use String[] to save it. When 9 lines are saved, it will start displaying.
If there are numbers, English, symbols and other characters other than 14 pixels, you have to make another judgment.
The specific operation method is to calculate the length of each character obtained and accumulate the length. If the upcoming character exceeds 296 after the accumulated length is added, then the line can be changed and the character will be placed on the next line.
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet