ESP8266 nodemcu使用arduino编程点亮OLED测试

本文介绍如何使用Arduino IDE配置ESP8266 Nodemcu开发环境,通过U8G2库驱动OLED显示屏,并展示Hello World示例。文章详细讲解了开发环境搭建步骤,包括库安装、代码编写及上传过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

芯片了解


《Nodemcu指引PDF.pdf》

使用 ESP8266LUAloader 测试

串口收集信息
菜单栏有个connect

Not connected to comm port


FYI: LuaLoader version 0.91 is available for download!

?i??$$HB$$磝<琹繦$,权

Connected to COM6 at 9600 baud


NodeMCU custom build by frightanic.com
	branch: master
	commit: c8037568571edb5c568c2f8231e4f8ce0683b883
	SSL: false
	modules: cjson,file,gpio,net,node,pwm,tmr,uart,wifi
 build 	built on: 2016-03-14 02:10
 powered by Lua 5.1.4 on SDK 1.4.0
lua: cannot open init.lua
> 
WARNING! Comm port is disconnected

测试了pgio引脚和wifi连接正常。
之前在linux里正常连接过esp分享出来的wifi。

ESP8266 nodemcu使用arduino编程点亮OLED测试


参考资料:ESP8266 nodemcu驱动0.96OLED基于arduino资料

配置arduino for esp8266开发环境

参考资料:ESP8266 Arduino开发环境搭建的五个备选地址
	https://www.jianshu.com/p/7431582ea44c
	https://downloads.arduino.cc/arduino-1.8.13-windows.zip
打开arduino IDE (1.8.13),文件----首选项
附加开发板管理器网址填上地址
选取了如下链接的2.5.0最新版本
	https://github.com/esp8266/Arduino/releases/download/2.5.0/package_esp8266com_index.json

工具–管理库

	搜索8266,下载最新版本,速度还行,2分钟 能够安装好
	搜索U8G2屏幕驱动库,并安装最新版本

工具–开发板—开发板管理器

	开发板型号选择 NodeMCU 1.0
	取得开发板信息
	BN: 未知的开发板
	VID: 1A86
	PID: 7523
	SN: Upload any sketch to obtain it
	和linux匹配的
	"vid": 6790, 1A86
	"pid": 29987,7523

文件-示例菜单,选择的第三方U8G2logo

文件>>示例>>U8g2>>full_buffer 组里面的任意例子,选择的U8g2Logo

编程的全部语句
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /*clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); 
// All Boards without Reset of the Display  对应 OLED 的驱动协议、像素大小以及接线方式。
void setup(void) {
  u8g2.begin();
}

void loop(void) {
  u8g2.clearBuffer();					// clear the internal memory
  u8g2.setFont(u8g2_font_ncenB08_tr);	// choose a suitable font
  u8g2.drawStr(0,10,"Hello World!");	// write something to the internal memory
  u8g2.sendBuffer();					// transfer internal memory to the display
  delay(1000);  
}

接线

按一下图示连接 OLED 和 Nodemcu(esp8266)开发板;
OLED Nodemcu
GND-----------GND
VCC-----------3V3/5V
SCL-----------D1(GPIO5)
SDA-----------D2(GPIO4)

编译测试

点击勾图标(表示编译),提示
	项目使用了 279092 字节,占用了 (26%) 程序存储空间。最大为 1044464 字节。
	全局变量使用了28884字节,(35%)的动态内存,余留53036字节局部变量。最大为81920字节。
点击右箭头图标,上传

Uploading 283232 bytes from C:\Users\xiang\AppData\Local\Temp\arduino_build_891345/U8g2Logo.ino.bin to flash at 0x00000000
… [ 28% ]
… [ 57% ]
… [ 86% ]
… [ 100% ]
上传时蓝色灯一直闪,上传完成后屏幕不亮,灯间歇10秒左右闪。

串口115200,显示

 ets Jan  8 2013,rst cause:4, boot mode:(3,4)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v951aeffa
~ld

更换了另外一个helloWorld后,编译上传后,屏幕显示正常:白色Hello World!