Use external C++ library with Johnny Five for Arduino based projects - node.js

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 :)

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.

NodeMCU - gpio programming

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.

How to play MIDI input in Linux

I am sending serial data to my raspberry pi from my arduino then converting the serial data to MIDI using this program: link. Is there any program out there that will take the midi input from the converter program and send it out the pi's audio jack in real time?
I've been using fluidsynth as a softsynth. I haven't run any on the pi, though. There's also a lot of others like amsynth, hexter, xsynth-dssi etc and some of them might be more suitable than others.
You might try running apt-cache search with some suitable keywords and look for programs available on the pi.
TiMidity++ is a software MIDI sequencer and synthesizer that supports multiple audio and patch formats.

Natural language parsing for Arduino, where to start

For a school project I am looking into natural language programming and thinking how the concept may be applied to Arduino.
Think along the lines of a piece of software that would translate sentences like If the analog sensor on pin 9 reads more than 2 Volts, set the duty cycle of the the servo on pin 10 to 70%. or If the digital sensor on pin 4 reads high, light the onboard LED for 5 seconds. into Arduino code. I'm suspecting that doing this for basic Arduino use cases should be straightforward compared to more general applications.
Does such a thing exist for Arduino? Does it exist for any other popular high-level language, like Python or MATLAB? Could anyone recommend resources for an absolute beginner on the topic of natural language processing (more specifically, a non-CS, non-CS-background graduate student who knows his way around Python, C#, MATLAB and, obviously, Arduino)?
You can checkout nltk which is a library for Python.
Translate the sentence into commands using the above library and then use the commands to generate the Arduino code.
Another approach is to use firmdata which will allows you to send commands to Arduino through a serial port.

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