You have no recently viewed item.
lua on pixels without borders: nodemcu oled temp&humidity

LUA on Pixels Without Borders: NodeMCU OLED Temp&Humidity

OledIntroduction of the module

OLED displayIt refers to an organic electro-excitement luminous diode (OLED), which has auto-lighting, there is therefore no need for a source of backlighting, a high contrast, a thin thickness, a wide angle of view, a rapid reaction speed and other characteristics. It is considered the next generation plan.monitorEmerging application technologies.

The author uses OLED modules with a white, white, white bus busto showScreen, 128×64 resolution, commonly used OLED interfaces include I2C and SPI. The adapter card is drawn by yourself, which is fundamentally the same as the interface of the module purchased on Taobao. The module has a circuit of 5 V to 3.3 V, which can be compatible with external voltages of 3.3 V and 5V. I will not talk about the material part here. After buying the OLED module, customer service will provide information related to the module.

Note: When buying an OLED module, you must check if the module is supported by the U8G2 library. Only OELD screens supported by the U8G2 library can use this library.

Activate the I2C and OLED modules

In the previous article “Compilation of NodeMcu firmware of ESP8266”, he in fact introduced how to activate the different modules supported by Nodemcu. After activating the corresponding module, you must recompile the firmware and burn it on ESP8266 before you can use it. Generally, the corresponding modules are activated according to your own needs to reduce the size of the firmware.

1) To activate the I2C module, you must open User_Modules. H The Lua_use_Modules_i2c in the file is activated by default using the firmware that I compiled before.

The ESP8266 chip does not have an I2C hardware interface, so the module uses a software interface driver. It can be defined on any GPIO pin, including GPIO16. The module supports the main mode, each bus can have different speeds, up to 10 buses.
Speed ​​standard:

Slow speed: 100 kHz;

Fast: 400 kHz;

Fastplus: 1 MHz
You can also define any clock. The GPIO16 pin can be used as a SCL pin, but the selected bus will be limited to nothing more than fast speed.
The module does not support the broadband mode (3.5 MHz clock) and the 10 -bit addressing patterns.

2) To activate the OLED module, you must activate User_Modules. H The Lua_use_Modules_u8g2 and U8G2 modules in the file wrote all the common OLED screen drivers. The source code is open source and can be displayed on GitHub. The modules are as follows:

#define lua_use_modles_i2c #define lua_use_modules_u8g2i2c related interface

Since the U8G2 library is used, we only have to understand I2C here. Setup interface ().

i2c.setup (id , pinsda , pinscl , speed)

setting:

ID: 0 ~ 9, Bus number, NodeMcu supports 10 Bus I2C.

Pinsda: 1 ~ 12, IO port number of SDA

Pinscl: 1 ~ 12, SCL IO port number

Speed: I2C. Slow (100 kHz), i2c. Fast (400 kHz), I2C. Fastplus (1 MHz) or any clock frequency between 25,000 and 10,000,000hz. Fastplus mode generates an I2C clock speed of 600 kHz at the default CPU frequency of 80 MHz. To obtain an I2C clock speed of 1 MHz, the interface node must be used. SETCPUFREQ (node.CPU160MHz) Modify the frequency of the CPU to 160 MHz.

Return value:

Speed: Returns the speed defined in case of success; Returns 0 in case of failure.

If you want to know other interfaces, you can see the official NodeMcu document.

Initialization of the interface linked to the SSD1306 driver of the U8G2 library

Using the I2C interface, call the following code to initialize:

SLA = 0x3c - OLED I2C address - ID: ID DISP = U8G2 When I2C is initialized. Ssd1306_i2c_128x64_noname (id, SLA)

For OLED initialization of other types of pilots, see the official NodeMcu documentation.

U8G2.DISP: Drawstr (x , y , * Str)

X: coordinates of axis x

Y: coordinates of the Y axis

Str: the channel to display

U8G2.DISP: Sendbufff (void)

Send the contents of the memory frame to the monitor and run this function before the OLED displays the game content.

OLED police settings

The police are defined in U8G2_Fonts in the app / include directory. H file, which fonts are necessary, simply add the corresponding police macros to U8G2_Font_Table_entry (font_wqy16_t_chineise3). Since the entire Chinese font library is large, the size of the firmware compiled will be large, which can cause a burning or ESP8266 failure cannot be started. The author will use the default police directly. Another technology is the design of U8G2 police, and there are also big guys who give online tutorials. If you are interested, you can search.

// Add an U8G2_Font_table_entry for each font you want to compile in the image // See https: //github.com/olikraus/u8g2/wiki/fntlll for a full list of // Available police. Place the prefix 'U8G2_' when you add them here. #Define u8g2_font_ table u8g2_font_table_entry (font_6×10_tf) u8g2_font_table_entry (Font_unnif_t_Symbols) ​​U8g2_Font_ Table

For fonts supported by U8G2, please refer to the official U8G2 website.

Light the OLED module

First of all, we must understand the relationship between ESP8266 and nodemcu pins, which are easy to confuse for many novices. The corresponding PIN relationship between ESP8266 and NODEMCU is as follows:

Corresponding relationships, such as the following table:

NODEMCU PINESP8266 PINT0GPIO16D1GPIO5D2GPIO4D3GPIO0D4GPIO2D5GPIO14 ……

The author’s OLED module has 4 lead pins (some IIC and SPI compatible modules can have 7 pins). The connection relationship between the OLED and NODEMCU module is as follows:

OLED NODEMCU module PINESP8266VCC (with voltage regulator 3.3 V) VCC (3.3 V or 5V) VCCGNGNGDDSCLD6GPIO12SDAD5GPIO14

Note:

The VCC of the single module ESP8266 is 3.3 V.

If the OLED module has res, DC and CS pins, you can control it in the program depending on the instructions or configure it directly on the equipment. For more details, please see the information on the OLED module.

If the OLED module does not have a 3.3 V voltage regulation, the VCC OLED is connected to the 3.3 V pin of the NODEMCU, because the 0.96 inch OLED screen is mainly a 3.3 V power supply, and the specification of the OLED screen must prevail.

Connection relationship between the DHT11 and NODEMCU module:

DHT11 PINNODEMCU PINESP8266VCC3.3VVCCGNDGNDDATAD4GPIO2

First connect the OLED and NODEMCU development card, then connect the USB to the computer and download the Lua Lit OLED code.

The code is as follows:

- Definition of the local SDA spindle = 5 - GPIO14 Local SCL = 6 - GPIO12 Local SLA = 0x3c - The address of the OLED is generally 0x3c - Init_oled () initialization function - - Bus IIC and OLED I2C initialization. Configuration (0, SDA, SCL, I2C.SLOW) DISP = U8G2. SSD1306_I2C_128x64_noname (0, SLA) - Set Font: Setfont (U8G2.Font_Unifut_T_Symbols) Disp: Setfontrefheightendtex -disp: Drawframe (0, 0, 128, 64) OLED_SHOW_MSG () -SET DISP content displays: Drawstr (0, 0, “1 Hello oled”) DISP: Drawstr (0, 16, “2234567890Abcdef”) DISP: Drawstr (0, 32, “3234567890ABCDE”) Draws 48, “4234567890Abcdef”) -SEND Contents at OLED DISP: Sendbuffer () End -main Function Function Function () INIT_OLED () OLED_SHOW_MSG () End -run Main program ()

Save the code on OLED. The LUA file is downloaded from the ESP8266 module via the Esplorer tool, update the ESPLORER file list and click OLED. Lua can see the information displayed on the OLED screen. As indicated in the figure below:

Real display effect:

Show the temperature and humidity dynamically on the OLED

The temperature and humidity module uses the DHT11 module. I wrote an article before using the DHT11 module. Used directly here

Share:

Leave your thought here

Your email address will not be published.