Unknown Output Characters in Arduino - node.js

I am actually connecting my laptop and arduino using FPVDrone 3DR Radio Telemetry. My connection is
ARDUINO tx- FPV Air module rx
ARDUINO rx- FPV Air module tx
ARDUINO 5v- FPV Air module 5v
ARDUINO GND- FPV Air module GND
while my FPV ground module is connected to my laptop. I have an app running using node JS with the following script
const SerialPort = require('serialport');
const Readline = SerialPort.parsers.Readline;
const port = new SerialPort('COM3');
port.write('hello');
and my arduino code is
void setup() {
Serial.begin(57600);
}
void loop() {
if (Serial.available()) {
Serial.print((char) Serial.read());
delay(10);
}
}
i'm pretty sure they are communicating because my arduino is receiving some output, however the output is some characters i dont know,
arduino output
can someone please tell me what I should do so that i can receive the string "hello" to my arduino?

Try setting the baudrate in the node.js script
const port = new SerialPort(path, { baudRate: 57600 })
characters get messed up is the sending and receiving baudrates are different.

Are sure that the characters sent to the Arduino are ASCII code?
If you are sending integers and they are below 0x30, then they are non-printable characters and you will see gibberish.
Make sure that you send an ASCII symbol or use/make a terminal that can show the raw integers.

Related

Serial port information like manufacturer/description is unavailable on Windows but available on Linux, using node.js with serialport package

I wrote a node.js script that connects to an external device via an USB serial port. The external device uses a chip from FTDI that converts to and from USB signals. I programmed basic device information like manufacturer, description, serial number etc. to that chip with FT_Prog, assuming this information is provided when I read the port information in my node.js script (using serialport package).
However it seems that I cannot retrieve that information on my Windows system. When I read the serial port information I am connected to, the manufacturer always is FTDI, description is undefined. But when using a Linux system, that information is available.
This seems to be the same topic. But as far as I understand I should be able to get the information as soon as I programmed the chip with FT_Prog. But it's still not working.
So why is it, that I cannot retrieve this information on Windows, but on Linux?
Thanks in advance!
EDIT
The code I am using:
'use strict';
const serialPort = require('serialport');
searchFscPort();
function searchFscPort() {
serialPort.list().then(ports => {
for(let i = 0; i < ports.length; i++) {
if(ports[i].manufacturer == 'FTDI' || ports[i].manufacturer == 'ME') {
console.log('Path: ', ports[i].path);
console.log('Manufacturer: ', ports[i].manufacturer);
console.log('SN: ', ports[i].serialNumber);
console.log('lID: ', ports[i].locationId);
console.log('pID: ', ports[i].productId);
console.log('vID: ', ports[i].vendorId);
console.log('pnpID: ', ports[i].pnpId);
return;
}
}
});
}
Result on Windows:
path: COM4
manufacturer: FTDI
SN: 110
lID: undefined
pID: 6015
vID: 0403
pnpID: FTDIBUS\VID_0403+PID_6015+110A\0000
Result on Linux:
path: /dev/ttyUSB0
manufacturer: ME
SN: 110
lID: undefined
pID: 6015
vID: 0403
pnpID: usb-ME_FSC1_7_110-if00-port0
This is what I have programmed into the chip:
By the way, there seems to be no node.js property to get the "Manufacturer Desc"?

How to read Wiegand on Raspberry Pi 3 with Node?

I've tried numerous tutorials, and I can't get it to work.
Current situation:
- 12V Access control device that is connected like this i.e. Wiegand D0 to GPIO14 (pin 8/Tx) and D1 to GPIO15 (pin 10/Rx), with voltage dividers, shifting 5V to 3.3V.
- Raspberry Pi 3 with Raspbian Lite OS.
- Configured the GPIO serial port i.e. enabling uart and disabling the console.
I am using the onoff NPM package to read the signals, but I am not getting anything.
const Gpio = require('onoff').Gpio;
const d0 = new Gpio(8, 'in');
const d1 = new Gpio(10, 'in');
d0.watch((err, value) => {
if (err) {
throw err;
}
d0.readSync(value);
});
d1.watch((err, value) => {
if (err) {
throw err;
}
d1.readSync(value);
});
process.on('SIGINT', () => {
d0.unexport();
d1.unexport();
});
What am I doing wrong?
The NPM package you're trying to use can only detect changing logic levels on GPIO pins.
You should use Wiegand NPM instead.
And I think you have set the wrong pins on your code. Pins 8 and 10 are in fact GPIO14 and GPIO15. The library I linked uses GPIO17 and GPIO18 by default, which are located on pins 11 and 12 of the connector.
Having said that, there is no need to disable the UART to use pins 8 and 10 as digital GPIO.

gpio on raspi and nodejs with rpi-gpio

Im running raspi Model B Rev 2 512MB, I installed the module and succesfully opened a pin for writing on it. Succesfully made a LED blink.
Then I try to open a port for reading and I get and error
{ Error: EIO: i/o error, write errno: -5, code: 'EIO', syscall: 'write' }
This the relevant part of the code.
var gpio = require('rpi-gpio');
server.listen(8080, function() {
console.log('Servidor corriendo en http://localhost:8080');
gpio.setup(7, gpio.DIR_OUT, control);
gpio.setup(22, gpio.DIR_IN, gpio.EDGE_BOTH, control);
});
function control(err)
{
if(err)
console.log("Control function: " + err);
else
console.log('ok');
}
This is the pinout I see using gpio readall, I want to read from GPIO6, therefore I call to 22 (Physical port) I also tried 25 (BCM port) with the same result.
Any clue ??
the problem is that the syntax is slightly different, if you add the third parameter for the edge you cannot add the callback, changing this:
gpio.setup(22, gpio.DIR_IN, gpio.EDGE_BOTH, control);
to this
gpio.setup(22, gpio.DIR_IN, gpio.EDGE_BOTH);
solved the problem
PIN 6 is Ground, so you cannot use it. You can use PIN 5 for input. (PINs not GPIOs)
Pin diagram for reference:

Unable to read serial port with node-serialport on raspberry pi

I'm using a raspberry pi (the first model) running on Jessy (8), node v0.12.6 and serialport 2.0.6. I have connected the pin Rx on the pin Tx of the physical serial port.
It's working fine with cat /dev/ttyAMA0 and echo "Hello" > /dev/ttyAMA0
The writing on the serial port with node-serialport is fine. I am using the code bellow (and using cat to read this) (source: https://www.npmjs.com/package/serialport)
var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
var sp = new SerialPort("/dev/ttyAMA0", {
baudrate:9600,
databits: 8,
parity: 'none',
stopBits: 1,
flowControl: false,
parser: serialport.parsers.readline("\n"),
});
sp.on('open', function() {
console.log("sending");
sp.write("Hello");
});
I am now trying to read my serial port with node-serialport, but it doesn't work. When I am trying to read the serialport with node-serialport (and using echo to write on it), the data from echo are not writen in the terminal. The terminal only says "open". I am using this code, same source:
var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
var sp = new SerialPort("/dev/ttyAMA0", {
baudrate:9600,
databits: 8,
parity: 'none',
stopBits: 1,
flowControl: false,
parser: serialport.parsers.readline("\n"),
});
sp.on('open', function() {
console.log('open');
sp.on('data', function(data) {
console.log('data received: ' + data);
});
});
I don't understand what's happening here. Any help would be much appreciated!
Thanks a lot! :)
Nicolas
Problem solved, shell and kernel messages on the serial connection wasn't disabled with the raspi-config tool to prevent the kernel from using the serial port. (sudo raspi-config, Advanced-Options, Serial, No)
Thanks to fivdi : https://github.com/voodootikigod/node-serialport/issues/715
Nicolas

Raspi-io: Error: Unknown pin "null"

I'm using the johnn-five and raspi-io packages for node and I'm trying to read the events created on a PIR motion sensor, but everytime I run the application, an error is thrown.
console
pi#raspberrypi ~/poc $ sudo node app.js
1439476578608 Device(s) RaspberryPi-IO
1439476578749 Connected RaspberryPi-IO
1439476578825 Repl Initialized
>> /home/pi/poc/node_modules/raspi-io/lib/index.js:316
throw new Error("Unknown pin \"" + pin + "\"");
^
Error: Unknown pin "null"
at Raspi._defineProperty.value (/home/pi/poc/node_modules/raspi-io/lib/index.js:316:17)
at Raspi.pinMode (/home/pi/poc/node_modules/raspi-io/lib/index.js:327:47)
at Motion.Controllers.PIR.initialize.value (/home/pi/poc/node_modules/johnny-five/lib/motion.js:27:17)
at new Motion (/home/pi/poc/node_modules/johnny-five/lib/motion.js:180:10)
at Board.<anonymous> (/home/pi/poc/app.js:9:16)
at Board.emit (events.js:104:17)
at process._tickDomainCallback (node.js:381:11)
package.js
{
"name": "poc",
"version": "0.0.1",
"main": "app.js",
"private": true,
"dependencies": {
"johnny-five": "0.8.86",
"raspi-io": "3.3.4"
}
}
app.js
var raspi = require('raspi-io');
var five = require('johnny-five');
var board = new five.Board({
io: new raspi()
});
board.on('ready', function() {
var motion = new five.Motion({pin: 'PI-17'});
motion.on('calibrated', function() {
console.log('calibrated');
});
motion.on('motionstart', function() {
console.log('motionstart');
});
motion.on('motionend', function() {
console.log('motionend');
});
});
However, the following code DOES seem to work:
snipped from another poc
var raspi = require('raspi');
var gpio = require('raspi-gpio');
raspi.init(function() {
var input = new gpio.DigitalInput({
pin: 'P1-17'
});
var logInput = function() {
console.log('Input 17: ' + input.read());
setTimeout(logInput, 1000);
};
logInput();
});
The Raspberry is a Rev. 2 model B.
The Motion detector I'm using is this one.
The cables are connected as follows (physical pin, taken from this schema)
Motion Sensor -> Pi
1 GND -> 6 GND
2 VDD -> 1 +3/V3 OUT
3 OUT -> 11 GPIO17
Any help would be greatly appreciated.
After more searching I came across this image.
It provided me with more insight on the WiringPi Pin numbers, BCM GPIO naming and P1 naming.
The pin GPIO0 on Pin 0 (BCM 17) seems to be throwing the error.
I switched to using pin GPIO4 on Pin 4 (BCM 23).
It doesn't really make sense why the 0 doesn't work, but for now, the poc I'm working on can progress again.
Your issue wasn't with any of your code, or a naming issue. You unfortunately chose poorly for which pin to use. P1-17 isn't able to accept an input, as it is dedicated 3.3v out. Choose another pin, and you should be fine.
Any pin reserved for I2C or Serial can't be used for regular GPIO function within Johnny Five, along with the dedicated power and ground pins which can't be used for IO, ever. As long as you avoid these ports, you'll be fine. A good resource on Raspberry Pi pinouts is here.

Resources