Skip to content

Instantly share code, notes, and snippets.

@ryoshu
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryoshu/3438867682ac41c50dde to your computer and use it in GitHub Desktop.
Save ryoshu/3438867682ac41c50dde to your computer and use it in GitHub Desktop.
How to communicate Galileo <-> Arduino over Serial
- Set your system date if you haven't: date -s "2014-05-15 12:25:00"
- Configure opkg: http://alextgalileo.altervista.org/package-repo-configuration-instructions.html
- Install dev pacakges:
root@clanton:~# opkg install gcc --force-overwrite
root@clanton:~# opkg install gcc-symlinks make g++ g++-symlinks git
root@clanton:~# opkg install packagegroup-core-buildessential
- Connect pin 0 (RX) on the Galileo to pin 11 on the Arduino
- Connect pin 1 (TX) on the Galileo to pin 10 on the Arduino
- From here: http://www.malinov.com/Home/sergey-s-blog/intelgalileo-configuringtheserialportinlinux
You can do each command from the command line or run this bash script:
#!/bin/bash
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
- Connect pin 0 (RX) on the Galileo to pin 11 on the Arduino
- Connect pin 1 (TX) on the Galileo to pin 10 on the Arduino
- Arduino script
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
- Run Arduino script and open Serial monitor
- Install serialport module for node (this will fail if your date is not set properly): npm install serialport
- Node script:
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/ttyS0", {
baudrate: 9600
});
serialPort.on("open", function () {
console.log('open');
serialPort.on('data', function(data) {
console.log('data received: ' + data);
});
serialPort.write("This is serial data coming in from the Galileo!\n", function(err, results) {
console.log('err ' + err);
console.log('results ' + results);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment