var app = require('http').createServer(handler);
var io = require('').listen(app);
var fs = require('fs');
var b = require('bonescript');

// options go here
io.set('log level', 2);   // reduce logging - set 1 for warn, 2 for info,3 
for debug
io.set('browser client minification', true);  // send minified client
io.set('browser client etag', true);  // apply etag caching logic basedon 
version number

console.log('Server running on: http://' + getIPAddress() + ':1000');
//pwm pin
var pwmPin1 = "P9_14";
var pwmPin2 = "P8_19";

//motor 1
var ain1Pin = "P9_13";
var ain2Pin = "P9_15";

//motor 2
var ain1Pin2 = "P8_10";
var ain2Pin2 = "P8_12";

// configure pins
b.pinMode(pwmPin1, b.OUTPUT);
b.pinMode(pwmPin2, b.OUTPUT);
b.pinMode(ain1Pin, b.OUTPUT);
b.pinMode(ain2Pin, b.OUTPUT);
b.pinMode(ain1Pin2, b.OUTPUT);
b.pinMode(ain2Pin2, b.OUTPUT);

function handler (req, res) {
  fs.readFile('Project 16.html',    // load html file
  function (err, data) {
    if (err) {
      return res.end('Error loading index.html');

io.sockets.on('connection', function (socket) {
  // listen to sockets and write analog values to PWM pins
   socket.on('pwmPin', function (data) {
      if (data.value >50){
          forwards((data/100 - 0.5) * 2);
      else {
          backwards ((0.5 - data/100) * 2);

function forwards(duty) {
    var value = duty;
   //Arm motors
    b.analogWrite(pwmPin1, value); 
    b.analogWrite(pwmPin2, value); 
   //Write values 
    b.digitalWrite(ain1Pin, 1);
    b.digitalWrite(ain2Pin, 0);
    b.digitalWrite(ain1Pin2, 1);
    b.digitalWrite(ain2Pin2, 0);

function backwards(duty) {
    var value = duty;
    //Arm motors
    b.analogWrite(pwmPin1, value); 
    b.analogWrite(pwmPin2, value);
    //Write values
    b.digitalWrite(ain1Pin, 0);
    b.digitalWrite(ain2Pin, 1);
    b.digitalWrite(ain1Pin2, 0);
    b.digitalWrite(ain2Pin2, 1);
// Get server IP address on LAN
function getIPAddress() {
  var interfaces = require('os').networkInterfaces();
  for (var devName in interfaces) {
    var iface = interfaces[devName];
    for (var i = 0; i < iface.length; i++) {
      var alias = iface[i];
      if ( === 'IPv4' && alias.address !== '' &&
        return alias.address;
  return '';

and here is the HTML software for this project...

<!DOCTYPE html>
    <meta charset="utf-8">
    <title>BBB and Geaux!</title>
    <script src="/"></script>
    var socket = io.connect();
    // Send data through socket
    function pwmPin(value){
      socket.emit('pwmPin', value);
<div data-role="page" id="page1">
    <div data-theme="a" data-role="header">
            BeagleBone Black
    <div data-role="content">
        <div data-role="fieldcontain">
            <label for="slider1">
            <input id="slider1" type="range" name="slider" value="50"
             min="0" max="100"
            data-highlight="false" data-theme="b" onChange="pwmPin(value);">

If there are some software debuggers out there that know how to work around 
my error codes, let a brother know. Thank you.


On Monday, October 17, 2016 at 10:13:20 PM UTC-5, Mala Dies wrote:
> Hello,
> I am working out of a book. It is called "30 Beaglebone Black Projects for 
> the Evil Genius." The author has a page online at 
> I am on Project16.js 
> and Project16.html. I have gotten scores of error codes. I have been 
> unsuccessful updating my Bonescript and languages on the BBGW.
> If there are any people out there working out of this specific book, 
> please join in. I can sure use some advice and further understanding.
> I know it is me that cannot make the software work with my current 
> configuration(s).
> Seth
> P.S. If you need additional info, please contact me. Thank you and Geaux 
> Cajuns!

For more options, visit
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To view this discussion on the web visit
For more options, visit

Reply via email to