NodeMCU - gpio programming - gpio

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
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.");
}
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.
Any way to get to use these gpio functions?

Quick way to start using NodeMCU is to use the Arduino IDE. You can use the sequence of steps as described in the link. Once you do this, you can use the examples in the IDE itself. As a start, you can use the example in File->Examples->Basics->Blink. This will blink the onboard LED

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 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.
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.
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.
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);
}
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.

There is no need to use the "gpio.h" header file. To oscillate one of the I/O pins you can use the arduino code for the simple Blinking of the Led and directly burn it into the NODEMCU Board.
There are two different methods to program the NODEMCU:
Arduino IDE
Burning some firmware which acts as the operating system and inside which we write our code files.
As long we use the Arduino IDE for programming we need not worry about the firmware since the Arduino code gets converted to *.bin format which is burnt on the NODEMCU and the firmware which we are talking about helps us to program in different languages like MicroPython , Lua.
Everything is taken care of by the Arduino IDE. It creates its own version of the firmware and burns it on the board.

Related

Play audio files in microcontroller (Arduino)

I try to make a Bluetooth speaker with a microcontroller (Arduino, teensy... I don't have a defined model, because I'm considering the frequency)
My question is if I want to put a SD, for reading music stored, the problem is there are library only for ".wav" files, but I want to extend for ".mp3", ".m4a", ".aac" and other.
Exist any library for this? and if is not, How I can do it?
I need to decode an audio files, convert the data in bytes and send it to the DAC.
An example code in C++ will help me a lot, I can created a new library for this.
I don't want use modules, I want to try to do my own circuit.
Edit:
I gonna use a third party microcontroller compatible with Arduino, because I need more capacity for audio.
PDT: I don't know if I had to post this in Arduino o electrict defined, so I put in general.
The Arduino does not have sufficient resources to do this. An MP3 decoder needs plenty of memory and floating point support. The AVR processors used for Arduinos have neither of these.
The only way you are going to do this with a Arduino is if you use a module.
Teensy base on ARM microcontroller (Cortex-M3 & M4) come with FPU, have capacity for play videos. Teensy is a board compatible with arduino. With DAC and SD slot. Adafruit have a library for play .mp3 on this board.
Well .mp3 is enough for me, but in the future I want to learn how to decode other audio file formats.

Use external C++ library with Johnny Five for Arduino based projects

I need to use the RFID-RC522 module in my Johnny Five project (it is an NFC reader).
There is an arduino Library that makes it easy to interface with that: https://github.com/miguelbalboa/rfid
Can i use this library through Johnny-Five? If yes, how?
Short answer: Yes.
Long answer: You'll need some work.
JohnnyFive uses Firmata to interact with Arduino. Firmata is a program you upload on the Arduino that will allow you to interface it easily with your computer using different languages such as Python, JS, C/C++ and so on.
Your problem is that you cannot have Firmata and a custom program using the RFID library on your Arduino at the same time.
So you have to choices:
port the RFID library to be used with johnny five. should not be too difficult and johnny five provides extensive documentation
are you sure your need johnny five? you could also implement a simple interface through serial with your Arduino and write a simple program to use the RFID library on the Arduino. You can then send the data from the Arduino to the computer and wait for serial inputs from the computer to the Arduino.
The second solution will be easier and simpler if you don't need Johnny five.
As you said you are new to Arduino Programming, I would advise you to start small with just Arduino code before moving to Arduino+JS.
Hope this helps :)

How can I list available input devices with haxe?

I would like to list all the input devices available when I launch an application, but I can't find a way to do that in the API.
How can I get a list of available keyboards, mice, gamepads, touch screens, accelerometers...
Haxe is a programming language that compiles to other languages. There are projects that use the compiled haxe code to deploy to different runtimes. For example the NME framework compiles to neko, html5, flash, mobile etc. So your question doesn't really make the strictest sense.
I doubt there is an api for getting a list of the available input devices in nme as generally it will be evident. You could however go through the api one input at a time to test if its available or working I guess.
Do you have a special need for this? generally people usually use compiler conditionals to determine these things eg;
#if mobile
//your touch input code
#elseif desktop
//your mouse / keyboard code
#end
There is exist Joystick API in OpenFL for gamepads.
Each event has an “device” property, which specifies which input device the event is coming from. In this way, you can support multiple joysticks or (probably) gamepads in one game.
http://www.joshuagranick.com/blog/?p=692

How can I generate and play back procedural sounds (square wave, etc.) in Lazarus/Free Pascal?

How can I play and synthesize custom waves in Lazarus/Free Pascal? The solution has to be realtime-friendly, as it is for a game engine. It should be also multi-platform, so it can be used on win32, Linux and Mac. FMOD/BASS are out (even if aplicable) as I don't want to pay fees if I will want to use it commercially.
There are solutions to that. My favourite library is Steinberg's ASIO. It is a very simple API, it's got wrappers for Linux, Windows, MAC and i guess some other platforms as well. It is a professional API for low-latency recording / playback. You usually need a soundcard that supports it, but recently some drivers emerged, using native platform API to emulate ASIO device (e.g. ASIO4ALL in windows).
ASIO's got a simple function in which buffers are swapped, where you can generate your wavefrom procedurally to be played back practically immediately (there are latencies in order of milliseconds). That's for the realtimeness.
The API as such is royalty free which means you can use it in a commercial project and don't have to pay anyone.
As for Pascal bindings, I believe you will have to do that yourself. But the whole initialization and operation of ASIO is <100 lines of C/C++ code (and you actually only need to control sound synthesis and maybe device selection - ony two functions that need to be exported by the wrapper) so that really should not be hard at all.

Running an audio synthesis/analysis language on an embedded device

What is the experience running programs written in an audio synthesis/analysis language such as ChucK, Pure Data, Csound, Supercollider, etc. in an embedded device such as an Arduino Mega, Beagle Board or a custom board with a microprocessor or DSP chip?
I would like to know which language and hardware you chose and why. What were the obstacles, etc.? My objective is to run programs that can be easily programmed by musicians/producers in a board that is not too expensive.
I received input from someone who is successfully running ChucK programs in a Beagle Board (Ubuntu Linux on a Beagle Board running ChucK), but his choice of language and hardware was made very lightly, his setup is not using the DSP in the Beagle Board and it seems like overkill to run a whole Linux install to process audio signals.
Any input is appreciated!
Update: I found Zengarden which is a Pd runtime implementation (as a standalone C++ library) and runs well on ARM based devices. For now, I'll go with the BeagleBoard and Zengarden but in a later stage of the project, I'll need to replace the BeagleBoard with something that costs less.
I'd love to hear more input from the community.
Thanks everyone for your comments and answers. For everybody else's reference, I ended up writing a JACK client in C++ that parses and interprets PureData patches and ran it on a BeagleBoard with Angstrom Linux and JACK server. Here's a video and a tutorial that I wrote: http://elsoftwarehamuerto.org/articulos/691/puredata-beagleboard/
First, I am not an audio programmer, so I'm not familiar with the actual demands of the signal processing necessary to achieve what you want to achieve.
But, it's difficult to contrast something like the Beagle Board and the Arduino Mega, since they're really in different leagues of base performance. The Beagle Board is a 1 GHz ARM vs the Arduino Mega's 16 MHz. That tells me that whatever processing you may be interested in doing may well be within the capabilities of the Beagle Board, but the Arduino Mega would have almost no chance without an attached DSP to do the actual work.
The next consideration, is whether any of the packages you were considering using actually target DSPs for their runtimes. At a glance they seem like high level sound processing languages. With the Beagle Board, you may well have the processing power to evaluate and compile the sound source code that these packages use and let them compile in to their targets, but on the Arduino Mega, that seems unlikely.
If all you're doing is working with a piece of hardware that will be running the artifacts created by the packages you mentioned, then the Arduino Mega may well be suitable as the "development" is done on a more powerful machine. But if you want to work with these packages as is, and use them as a development tool, then running them on a Linux port to something like the may simply be a better option.
Again, after casual looking about, the Arduino Mega is roughly half the price of the Beagle Board, but the Beagle Board may well let you work at a much higher level (generic Linux). Whether either will be powerful enough for your final vision, I can't say. But I would imagine you could get a lot farther, a lot faster, using the more powerful system -- at least in the short term.

Resources