Serial Port programming using Visual Basic for Embedded Developers.Learn how to interface your microcontroller with PC using Visual Basic .net
seen from China
seen from Malaysia
seen from United States

seen from Malaysia

seen from Malaysia
seen from China
seen from Singapore
seen from Kazakhstan
seen from China
seen from United States
seen from Singapore
seen from China
seen from Lithuania

seen from Russia
seen from Greece

seen from Russia

seen from Greece
seen from China
seen from Germany

seen from United States
Serial Port programming using Visual Basic for Embedded Developers.Learn how to interface your microcontroller with PC using Visual Basic .net
permasalahan dengan usb serial port yang hanya bisa dipakai oleh satu aplikasi
Reading MHZ-19 sensor data in Node.js
Below is an example on how to read CO2 level readings from MHZ-19 NDIR sensor via serial port in Node.js
/** * MHZ-19 UART Monitor * @author skitsanos */ const winston = require('winston'); const Transport = require('winston-transport'); const fs = require('fs'); const SerialPort = require('serialport'); const port = new SerialPort('/dev/tty.usbserial', {baudRate: 9600, autoOpen: false}); class FileTransport extends Transport { constructor(opts) { super(opts); } log(info, callback) { fs.appendFile(process.cwd() + '/app.log', `${info.level} ${info.message}\n`, (err) => { if (err) { console.log(err.message); } }); callback(); } } const loggingFormat = winston.format.combine( winston.format.colorize(), winston.format.splat(), winston.format.printf(info => { return ` ${(new Date()).getTime()} ${info.level}: ${info.message}`; })); const log = winston.createLogger({ exitOnError: false, //level: 'debug', transports: [ new FileTransport( { format: loggingFormat, timestamp: true } ), new winston.transports.Console({ format: loggingFormat }) ] }); let app = { meta: require('./package'), commands: { READ_VALUE: Buffer.from([0xff, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79]) }, utils: { ord: (str) => { console.log(str); return str.charCodeAt(0); }, sleep: (ms) => new Promise(resolve => setTimeout(resolve, ms)) }, serial: { list: () => { SerialPort.list().then((arr_portInfo) => { arr_portInfo.map(el => { console.log(el); log.info('Found: ' + el.comName); }); }); }, open: () => { if (port !== undefined) { return new Promise((resolve, reject) => { port.open(err => { if (err) { return reject(err); } return resolve(); }); }); } else { log.error('Failed to open port. Not found?'); } }, close: () => { if (port !== undefined) { log.debug('Closing serial port'); port.close(); } else { log.error('Failed to open port. Not found?'); } }, write: (data) => { return new Promise((resolve, reject) => { if (port !== undefined) { log.debug('Writing to serial port...'); port.write(data, (err) => { if (err) { return reject(err); } return resolve(); }); } else { return reject({message: 'Failed to write. Not found?'}); } }); } } }; log.info(`${app.meta.name} ver. ${app.meta.version}`); app.serial.open().then(() => { log.debug('Port open'); port.on('readable', async () => { const buf = port.read(9); if (buf !== null && Buffer.byteLength(buf) === 9) { if (buf[0] === 0xff && buf[1] === 0x86) { const co2 = Number(buf[2].toString()) * 256 + Number(buf[3].toString()); log.info(`${co2}ppm`); } await app.utils.sleep(5000); app.serial.write(app.commands.READ_VALUE); } }); app.serial.write(app.commands.READ_VALUE).then(() => { }).catch(err => log.error(err.message)); }).catch(err => log.error(err.message));
#BTS เทพน้องโม #dmapsgworkshop2017 🍉 #p5js #arduino #video #serialport #connection
Home Automation using IoT #nirmana #nirmana_2k16 #SISTec_Team #SISTec_Students #SISTec_CSE #SISTer_ECE #college #me #offerlocation #internetofthings #iot #raspberrypi #mobile #msp430 #msp430g2553 #linux #opensource #router #led #wifi #web #charger #wire #internet #serialport (at Sagar Group of Institutions (SISTec))
Phase 2.1: Talking Sense over Serial
Following a series of copy-paste hacks scraped from various websites and forums, I was left frustrated and confused. Everything seemed to be set up properly, from baud rate through Node.js buffer code through the wiring.. yet I was still receiving nonsense messages into my audio interface.
After several days and rewrites, I was on the verge of giving up.. which is when most excellent breakthroughs happen. Here are the steps I took to effectively communicate Midi messages over the UART serial on the Raspberry Pi.
This is a revised workflow from my previous post regarding Raspberry Pi setup, but has an important addition that made all the difference.
First, I edited /boot/cmdline.txt on the Pi:
sudo nano /boot/cmdline.txt
replace contents with:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 bcm2708.uart_clock=3000000 elevator=deadline rootwait
This enables the AMA0 serial port on the Pi to be used by Node. The important change here vs. my previous attempt is initializing the uart_clock to 3000000. I honestly have no idea what this is for, but thanks to this guy and his writeup for giving me something to try!
Second, I added some lines to the end of /boot/config.txt :
sudo nano /boot/config.txt
Add lines to end:
# change uart clock to 2441406 for midi 31250 baud rate init_uart_clock=2441406 init_uart_baud=38400
This slows down the Pi serial baud rate to approximately 31250 if a serialport is opened at 38400 baud rate (one of the standard baud rates supported). Note that only after initializing the UART clock, this was successful.
Third, I modified write access to the AMA0 port to allow Node.js to use it
chown pi /dev/ttyAMA0
chmod a+rw /dev/ttyAMA0
Next up, talking midi with Node.js!
Phase 2: Talking Nonsense over Serial
This has been an involved process, and I still have not solved the core of the problem, but I've learned some stuff. Here goes.
I've set up a tiny Node.js app to test Midi output via a web interface. The front-end is a few buttons that send socket messages via Socket.io to the Node app.
Upon receiving these socket messages, the Node app will ideally translate the intended result as defined in client-side code to meaningful Midi messages out over serial.
Here are the issues I've run into:
I can get midi messages sent out from the Pi, but the messages received and logged by my MOTU audio interface are NOT what I intend.
I do not understand binary code, or converting binary, hex, and decimal numbers in a really meaningful way. I can definitely hack things together, but hacking with intent is the next big step.
I do not understand the low-level C++ code used in the Node serialport module enough to tell if the protocols being used are correct.
The process I'm using encodes a NoteOn message into the values specified by the Midi standard. For a Note On event, there are 3 bytes sent. The first byte specifies the command (note on) and the channel # (1-16), the second byte specifies the pitch (0-127) and the third byte specifies velocity (again 0-127).
I am writing these three values into a Node buffer and writing them out over serial.
What I see in Midi Ox (on my PC, screen cap below) are three separate midi messages, none of which is a note on, and all of which have the wrong channel number.
There is obviously some extra data getting inserted somewhere between Node and the serial port, I will continue to investigate.
Phase 1: Configure the Pi for Midi
I chose the Raspberry Pi as my primary communication mechanism for a couple reasons. First, I am already familiar with the device having used it on a couple hack projects this year.
Second, after attempting to use the Pi with an Arduino to relay web events over serial and output Midi messages from the Arduino, I discovered a translation issue with differing baud rates between the devices. At this point, I chose to pair down my attempts and use only the Raspberry Pi.
Setting up the Pi to send midi messages is a little involved, but not over complicated. I referenced an excellent post by Silicon Stuff to hack the serial baud rate close to 31250 (Midi spec).
First, I hooked the Midi cable up to the Pi.
Pin 1 (5v) goes through a 220 ohm resistor to Pin 5 of the Midi cable.
Pin 5 (Ground) goes to the ground Pin 2 of the Midi cable.
Pin 7 (TX - serial transmit) goes to Pin 4 of the Midi cable.
Second, I edited /boot/cmdline.txt on the Pi:
sudo nano /boot/cmdline.txt
replace contents with:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
This enables the AMA0 serial port on the Pi to be used by Node.
Third, I added some lines to the end of /boot/config.txt :
sudo nano /boot/config.txt
Add lines to end:
# change uart clock to 2441406 for midi 31250 baud rate init_uart_clock=2441406 init_uart_baud=38400
This slows down the Pi serial baud rate to approximately 31250 if a serialport is opened at 38400 baud rate (one of the standard baud rates supported).
Fourth, I modified write access to the AMA0 port to allow Node.js to use it
chown pi /dev/ttyAMA0
chmod a+rw /dev/ttyAMA0
Now, the Pi is able to communicate at the speed that Midi requires.