NodeMCU-GPIO编程 [英] NodeMCU - gpio programming

查看:230
本文介绍了NodeMCU-GPIO编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NodeMCU板,V3引脚和Arduino IDE.我需要振荡其中一个输出引脚,然后深入挖掘,发现以下页面: https://github.com/nodemcu/nodemcu-firmware/blob/master/docs/en/modules/gpio.md

I'm using a NodeMCU board, V3 pinout, and the Arduino IDE. I need to oscillate one of the output pins, and digging around I found this page: https://github.com/nodemcu/nodemcu-firmware/blob/master/docs/en/modules/gpio.md

非常有用,尤其是gpio.serout()函数,但是我无法使其正常工作.这是我的代码:

Very useful, especially the gpio.serout() function, but I can't get it to work. This is my code:

#include <gpio.h>;
#define LED D5

void setup() {
  gpio.mode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  Serial.write("Starting blinking.");
  gpio.serout(LED, HIGH, 1000000, 10);
  Serial.write("Done.");
}

#include <gpio.h>;是编译器抛出错误'gpio' was not declared in this scope之后我的猜测,但错误仍然存​​在.文件gpio.h显然可以导入,或者对此有所抱怨.我所能找到的只是代码片段,如上面链接的手册页,没有完整的草图.

The #include <gpio.h>; is a guess of mine after the compiler threw the error 'gpio' was not declared in this scope but the error remains. The file gpio.h obviously imports fine, or it'd complain about that. All I can find is code snippets like the manual page linked to above, no complete sketches.

有什么方法可以使用这些gpio函数?

Any way to get to use these gpio functions?

推荐答案

尽管有几块板被命名为NodeMCU(或称为NodeMCU),但名称NodeMCU实际上是指以下几种板之一可以在基于ESP8266的芯片/开发板上安装可能的固件.

Although there are several boards that are either named NodeMCU (or referred to as NodeMCU), the name NodeMCU really refers to one of several possible firmwares that can be installed on an ESP8266-based chip/dev board.

NodeMCU是ESP8266的流行SDK,它为您提供Lua解释器和许多不同的模块,用于控制不同的功能和使用不同的通信协议.请参阅 NodeMCU文档,其中列出并记录了各种可用的扩展,包括您所使用的gpio模块在您的问题参考.有关Lua编程语言的信息,请参见 http://lua.org .

NodeMCU is a popular SDK for the ESP8266 which provides you with a Lua interpreter and a number of different modules for controlling different functions and using different communication protocols. See the NodeMCU Documentation which lists and documents the various available extensions, including the gpio module you reference in your question. See http://lua.org for information on the Lua programming language.

我非常喜欢Lua,并且发现使用NodeMCU SDK很有趣. 但是,还有其他选项可用于对这些板进行编程.

I very much like Lua, and I find using the NodeMCU SDK to be a lot of fun. However, there are other options for programming these boards.

一个很好的选择是使用兼容Arduino的SDK,该SDK允许您使用C进行编程.如果要使用Arduino IDE,则需要安装此SDK.请参阅 esp8266/Arduino github存储库以获取安装说明并下载SDK.

A very good alternative is to use an Arduino-compatible SDK that allows you to program in C. If you are going to use the Arduino IDE than you will need to install this SDK. See the esp8266/Arduino github repository for installation instructions and to download the SDK.

一旦安装了此SDK,您就可以使用digitalWrite函数,以与对任何其他Arduino进行编程的方式完全相同的方式控制板上的引脚.因此,对于您的示例,您可以执行以下操作:

Once this SDK is installed, you can control the pins on your board in exactly the same way as you would program any other Arduino, using the digitalWrite function. So for your example, you could do something like:

int pin = 12; // or whatever pin you want
for (int i = 0; i < 10000; i++) {
   digitalWrite(pin, HIGH);
   delay(10);
   digitalWrite(pin, LOW);
   delay(10);
}

您应该将其提取到函数中,而我写的内容不如gpio.serout函数灵活,但是它为您提供了一个起点.您可以看一下gpio模块(源代码),并在需要更复杂的内容时修改其对serout函数的实现.

You should extract that into a function, and what I have written isn't as flexible as the gpio.serout function, but it gives you a place to start. You can take a look at the gpio module (source code) and adapt its implementation of the serout function if you need something more complex.

这篇关于NodeMCU-GPIO编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆