Community
cancel
Showing results for 
Search instead for 
Did you mean: 
JWill40
Beginner
921 Views

How to configure UART on Gen 1 to read data from Launch Pad using SerialPort.js ?

Jump to solution

I am trying to send serial information from a Texas Instruments Launch Pad (Arduino Compatible) to a Gen 1 Intel Galileo which is running Linux and Node.js with a SerialPort.js module included to read the received UART data. The transmit pin on the Launch Pad is connected to the Rx (Pin 0) of the Galileo. The Galileo is to act as a web server and the data to be sent is simply 3 bytes of data with a terminating "\n" at the end of each transmission to tell the server that it is the end of the data.

Here are two functions that I wrote for the Launch Pad that places the information in to the transmit buffer to be sent. Testing the output of the UART on the launch pad shows that the information is coming out correctly.

void uartCHAR(int txChar)

{

while (!(IFG2 & UCA0TXIFG)); //Wait for the transmit buffer to be ready

UCA0TXBUF = (char)txChar; //Put integer value in to UART transmit buffer in character format

}

void uartTransmit(int tx)

{

P1OUT |= REDLED; //Turn on Red LED

unsigned int byteSelect = 0xFF00; //Declare value used to isolate each byte

unsigned int byteHold = 0; //Declare varible to hold isolated byte

unsigned char sendByte = 0; //Declare a variable to hold the byte to be transmitted

int k; //Declare a variable to be used in the for loop

for (k = 1; k>=0 ; k--) //Cycle through the code twice

{

byteHold = byteSelect&tx; //Isoltate each section of 8 bits in the and store in byteHold

byteHold >>= (8*(k)); //Shift the data down to the lowest byte position

sendByte = byteHold;

uartCHAR(sendByte); //Pass sendByte in to the uartCHAR function

byteHold = 0;

byteSelect>>=8; //Shift the byte selector to the next section of 8 bits

}

P1OUT &= ~REDLED; //Turn off Red LED

uartCHAR('\n'); //Send symbol to indicate to the parser that the end of the message has arrived

}

Here is a bash script that I found to configure the UART before running the JavaScript code to turn on the server functions.

# !/bin/bash

# Initialize sysfs to use the uart on pins 0 and 1 as /dev/ttyS0:

echo -n "4" > /sys/class/gpio/export

echo -n "40" > /sys/class/gpio/export

echo -n "41" > /sys/class/gpio/export

echo -n "out" > /sys/class/gpio/gpio4/direction

echo -n "out" > /sys/class/gpio/gpio40/direction

echo -n "out" > /sys/class/gpio/gpio41/direction

echo -n "strong" > /sys/class/gpio/gpio40/drive

echo -n "strong" > /sys/class/gpio/gpio41/drive

echo -n "1" > /sys/class/gpio/gpio4/value

echo -n "0" > /sys/class/gpio/gpio40/value

echo -n "0" > /sys/class/gpio/gpio41/value

stty -F /dev/ttyS0 raw

stty -F /dev/ttyS0 9600

Here is the section of the JavaScript code using Node.js and SerialPort.js to listen for data on the UART.

var express = require('express');

var app = express();

var io = require('socket.io').listen(app.listen(4000));

var com = require("serialport");

app.get('/', function(request, response){response.sendfile(__dirname + "/home.html");});

app.use('/static', express.static(__dirname + '/public'));

var activeClients = 0;

io.sockets.on('connection', function(socket){clientConnect(socket);});

var serialPort = new com.SerialPort("/dev/ttyS0", {

baudRate: 9600,

dataBits: 8,

parity: 'none',

stopBits: 1,

flowControl: false,

parser: com.parsers.readline("\n")

});

serialPort.on('open',function() {

console.log('Port open ');

console.log(process.argv[0] + " " + " " + process.argv[1]);

serialPort.on('data', function(data) {

console.log("Data recieved: ");

console.log(data.toString());

io.sockets.emit('heartUpdate', {heartcrc:data});

emitHeartRate(data);

});

serialPort.on('close', function () {

console.log('Port close');

});

serialPort.on('error', function (...

1 Solution
idata
Community Manager
45 Views

Hello Skywatermelon,

 

 

Why don't you try using mraa? You can get it on the eglibc image by modifying the file /etc/opkg/iotdk.conf to contain the following lines:

 

 

src iotdk-all http://iotdk.intel.com/repos/2.0/iotdk/all http://iotdk.intel.com/repos/2.0/iotdk/all

 

src iotdk-i586 http://iotdk.intel.com/repos/2.0/iotdk/i586 http://iotdk.intel.com/repos/2.0/iotdk/i586

 

src iotdk-quark http://iotdk.intel.com/repos/2.0/iotdk/quark http://iotdk.intel.com/repos/2.0/iotdk/quark

 

src iotdk-x86 http://iotdk.intel.com/repos/2.0/iotdk/x86 http://iotdk.intel.com/repos/2.0/iotdk/x86

 

 

And then entering the commands:

 

 

opkg update

 

opkg install mraa

 

 

Once you've done that you will be able to use mraa in your code. You can check the following link to find a working serial example that you might be able to implement on your code:

 

 

https://github.com/MakersTeam/Galileo/blob/master/Serial_test.js https://github.com/MakersTeam/Galileo/blob/master/Serial_test.js

 

 

Let me know if it helps.

 

 

Peter.

View solution in original post

1 Reply
idata
Community Manager
46 Views

Hello Skywatermelon,

 

 

Why don't you try using mraa? You can get it on the eglibc image by modifying the file /etc/opkg/iotdk.conf to contain the following lines:

 

 

src iotdk-all http://iotdk.intel.com/repos/2.0/iotdk/all http://iotdk.intel.com/repos/2.0/iotdk/all

 

src iotdk-i586 http://iotdk.intel.com/repos/2.0/iotdk/i586 http://iotdk.intel.com/repos/2.0/iotdk/i586

 

src iotdk-quark http://iotdk.intel.com/repos/2.0/iotdk/quark http://iotdk.intel.com/repos/2.0/iotdk/quark

 

src iotdk-x86 http://iotdk.intel.com/repos/2.0/iotdk/x86 http://iotdk.intel.com/repos/2.0/iotdk/x86

 

 

And then entering the commands:

 

 

opkg update

 

opkg install mraa

 

 

Once you've done that you will be able to use mraa in your code. You can check the following link to find a working serial example that you might be able to implement on your code:

 

 

https://github.com/MakersTeam/Galileo/blob/master/Serial_test.js https://github.com/MakersTeam/Galileo/blob/master/Serial_test.js

 

 

Let me know if it helps.

 

 

Peter.

View solution in original post

Reply