I am using Gobot with Arduino Uno D1 Wemos ESP8266.
$ gort scan serial
/dev/cu.Bluetooth-Incoming-Port /dev/cu.usbserial-1410
/dev/tty.Bluetooth-Incoming-Port /dev/tty.usbserial-1410
$ cat blink.go
package main
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
)
func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/tty.usbserial-1410")
led := gpio.NewLedDriver(firmataAdaptor, "13")
work := func() {
gobot.Every(1*time.Second, func() {
led.On()
time.Sleep(1 * time.Second)
led.Off()
})
}
robot := gobot.NewRobot("bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{led},
work,
)
robot.Start()
}
➜ go run blink.go
# command-line-arguments
ld: warning: building for macOS, but linking in object file
(/var/folders/qz/v87zx1dd6cb_27lkx7yxqqt40000gp/T/go-link-728857552/go.o) built for
2019/07/03 23:10:29 Initializing connections...
2019/07/03 23:10:29 Initializing connection Firmata-77170CB7B110D741 ...
2019/07/03 23:10:29 Initializing devices...
2019/07/03 23:10:29 Initializing device LED-4ABBCD5F1E6D2FE3 ...
2019/07/03 23:10:29 Robot bot initialized.
2019/07/03 23:10:29 Starting Robot bot ...
2019/07/03 23:10:29 Starting connections...
2019/07/03 23:10:29 Starting connection Firmata-77170CB7B110D741 on port /dev/tty.usbserial-1410...
2019/07/03 23:10:44 1 error occurred:
* unable to connect. Perhaps you need to flash your Arduino with Firmata?
Other programs from the examples in Arduino IDE work as expected. What am I doing wrong?
Related
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"?
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.
I am running into an issue with using Rust for embedded purposes where I can run and debug programs just fine, but if I try to flash programs such that they can run without being connected to my computer they do not work.
For reference, I am using an stm32f303 chip. This also seems to be a recent issue, since I haven't had a problem before.
Code being flashed (its just blinky):
#![feature(used)]
#![no_std]
extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_abort; // panicking behavior
extern crate stm32f30x_hal as hal;
use hal::prelude::*;
use hal::stm32f30x;
use hal::delay::Delay;
fn main() {
let cp = cortex_m::Peripherals::take().unwrap();
let dp = stm32f30x::Peripherals::take().unwrap();
let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);
let mut gpioc = dp.GPIOC.split(&mut rcc.ahb);
let mut led1 = gpioc
.pc13
.into_push_pull_output(&mut gpioc.moder, &mut gpioc.otyper);
let mut delay = Delay::new(cp.SYST, clocks);
loop {
led1.set_high();
delay.delay_ms(1_000_u16);
led1.set_low();
delay.delay_ms(1_000_u16);
}
}
// As we are not using interrupts, we just register a dummy catch all
// handler
#[link_section = ".vector_table.interrupts"]
#[used]
static INTERRUPTS: [extern "C" fn(); 240] = [default_handler; 240];
extern "C" fn default_handler() {
loop {}
}
Output of OpenOCD program command:
$ openocd -f interface/jlink.cfg -f target/stm32f3x.cfg -c "program target/thumbv7em-none-eabihf/debug/cortex-m-quickstart verify reset exit"
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
jtag_ntrst_delay: 100
none separate
cortex_m reset_config sysresetreq
Info : No device selected, using first device.
Info : J-Link EDU Mini V1 compiled Mar 16 2017 12:04:38
Info : Hardware version: 1.00
Info : VTarget = 3.178 V
Info : clock speed 1000 kHz
Info : JTAG tap: stm32f3x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Info : JTAG tap: stm32f3x.bs tap/device found: 0x06422041 (mfg: 0x020 (STMicroelectronics), part: 0x6422, ver: 0x0)
Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
adapter speed: 1000 kHz
Info : JTAG tap: stm32f3x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Info : JTAG tap: stm32f3x.bs tap/device found: 0x06422041 (mfg: 0x020 (STMicroelectronics), part: 0x6422, ver: 0x0)
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x1ffff1bc msp: 0x20001258
Info : Reduced speed from 8000 kHz to 4000 kHz (maximum).
adapter speed: 8000 kHz
** Programming Started **
auto erase enabled
Info : device id = 0x10036422
Info : flash size = 256kbytes
wrote 14336 bytes from file target/thumbv7em-none-eabihf/debug/cortex-m-quickstart in 0.688176s (20.344 KiB/s)
** Programming Finished **
** Verify Started **
verified 13028 bytes in 0.077558s (164.041 KiB/s)
** Verified OK **
** Resetting Target **
adapter speed: 1000 kHz
Info : JTAG tap: stm32f3x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Info : JTAG tap: stm32f3x.bs tap/device found: 0x06422041 (mfg: 0x020 (STMicroelectronics), part: 0x6422, ver: 0x0)
shutdown command invoked
As can be seen, there aren't any issues when flashing the program, however it doesn't run. Once again, everything is completely fine when using GDB, and the code runs without any issues.
Any help, advice, or even general ideas of what to do would be greatly appreciated!
[Update]
It looks like the issue is with my boot0 pin, which is pulled high instead of low. This means that when GDB isn't connected and setting the PC, the MCU tries to boot from system memory instead of main memory. This explains why it works when debugging but not on its own.
For anyone who may be following the instructions in the Embedded Rust Book, if you have been using semihosting to print messages from your program while debugging (I used cortex_m_semihosting::hprintln), be aware that it seems to cause the same symptoms as above. I spent hours trying to figure out why the program would not start when run 'by itself', but removing the semihosting crate and the hprintln call immediately fixed the problem.
I have two Arduino unos flashed with the standard StandardFirmata and i'm trying the multi board demo with a simple node project (johnny-five npm package). Both arduinos work when I try them separately. with the following code:
var five = require("johnny-five");
var boardOne = new five.Board({ id: "A", port: "/dev/cu.usbmodem1d1141" });
boardOne.on("ready", function(){
var led = new five.Led({
pin: 13,
board: this
});
led.on();
});
node index.js
1418288836782 Connected /dev/cu.usbmodem1d1141
1418288836784 Repl Initialized
>>
When trying the multi board example I get:
Device or Firmware Error A timeout occurred while connecting to the Board.
Please check that you've properly flashed the board with the correct firmware.
var five = require("johnny-five");
var ports = [
{ id: "A", port: "/dev/cu.usbmodem1d1141" },
{ id: "B", port: "/dev/cu.usbmodem1d1131" }
];
new five.Boards(ports).on("ready", function(){
var led = new five.Led({
pin: 13,
board: this[0]
});
led.on();
});
Update #1:
Out of curiosity I tried to switch around the usb cables and got some different results:
1) Only one arduino seems to connect:
1418318698635 Device(s) /dev/cu.usbmodem1a1231,/dev/cu.usbmodem1a1241
1418318698642 Device(s) /dev/cu.usbmodem1a1241
1418318701849 Connected /dev/cu.usbmodem1a1231
1418318701850 Board ID: A
or 2) I get an error:
.../johnny-five-master/node_modules/firmata/lib/firmata.js:246
board.pins[pin].analogChannel = currentValue;
^
TypeError: Cannot set property 'analogChannel' of undefined
at Object.SYSEX_RESPONSE.(anonymous function) [as 106]
(.../johnny-five-master/node_modules/firmata/lib/firmata.js:246:35)
Update #2:
I did the above test with cylon.js and got the same results. Still no clue how to fix this :(
One arduino works fine, multiple do nothing. (Maybe an osx related problem?)
Update #3:
I added some logs in the johnny-five code and it's definitely a connection problem(I think!?). The second Arduino never responds. I switched the order of the arduinos and get the same result (first one connects, the other fails to respond). The connection is asynchronous, so maybe it gets blocked somewhere. The lights on both arduinos definitely show some action is going on.
node index.js
err: undefined --- type: connect --- io: /dev/tty.usbmodem1d1111
err: undefined --- type: connect --- io: /dev/tty.usbmodem1d1121
err: undefined --- type: ready --- io: /dev/tty.usbmodem1d1111
1418467187527 Connected /dev/tty.usbmodem1d1111
1418467187527 Board ID: A
1418467284327 Device or Firmware Error A timeout occurred while connecting to the Board.
Please check that you've properly flashed the board with the correct firmware.
Thanks to #izar for posting this and then bringing the question to us in the Johnny-Five gitter channel. From there, Divan Visagie (from Johnny-Five core team) worked to triage the bug and was able to confirm via reproduction. This revealed a bug in Firmata.js, where the options passed to Serialport were being extended by that class. Since the defaults object was reused and Object.assign is not a "deep" operation, the changes were being made to a reference, not a copy. The result was that the second initialization was getting a set of "defaults" that were loaded up with the first instance's own data. The issue was fixed by changing Firmata to use fresh defaults for every instance. Here's the patch
My node.js cluster is able to start 2 worker processes and is working fine.
Here is the pseudo code.
But if I open the windows task manager to kill a node.js process, I expected that it'd be restarted. but it threw error (Error: channel closed).
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
logger.fatal('worker ' + worker.pid + ' died. Restarting again ...');
cluster.fork();
});
} else {
// Worker processes have a express server.
.........
.........
}
Error:
[2012-03-15 09:46:20.906] [INFO] console - Total CPUs : 2
[2012-03-15 09:46:22.182] [INFO] console - info - 'socket.io started'
[2012-03-15 09:46:22.240] [INFO] console - info - 'socket.io started'
[2012-03-15 12:20:04.973] [FATAL] choicebeat - worker 6928 died. Restarting agai
n ...
[2012-03-15 12:20:05.213] [ERROR] console - Exception in cluster master process:
channel closed
Error: channel closed
at ChildProcess.send (child_process.js:118:33)
at c:\HTML5\LIKEPREF\test\server\node_modules\socket.io-clusterhub\node_modu
les\clusterhub\lib\index.js:150:22
at Array.forEach (native)
at ChildProcess.onmessage (c:\HTML5\LIKEPREF\test\server\node_modules\socket
.io-clusterhub\node_modules\clusterhub\lib\index.js:149:15)
at ChildProcess.emit (events.js:88:20)
at Pipe.onread (child_process.js:102:16)
Looks like something wrong with socket.io-clusterhub. Is it a some kind of configuration error or a bug ?
The issue has been solved in latest clusterhub version 0.1.2
socket.io-clusterhub uses clusterhub internally, so if you update your socket.io-clusterhub, it should work.
Ref: https://github.com/fent/socket.io-clusterhub/issues/1#issuecomment-4538131