Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest lininoIO #8

Open
rwaldron opened this issue Sep 16, 2016 · 1 comment
Open

Update to latest lininoIO #8

rwaldron opened this issue Sep 16, 2016 · 1 comment

Comments

@rwaldron
Copy link
Owner

https://github.com/linino/linino_distro/tree/lininoIO

@scenaristeur
Copy link

scenaristeur commented Jun 11, 2017

Hi ,
perhaps it could help :
I got blink.js and servosweeep.js working on my Arduino Yun :

root@arduino:~/johnny# uname -a
Linux arduino 3.3.8 #1 Thu Jun 2 12:28:33 CEST 2016 mips GNU/Linux
root@arduino:~/johnny# lininoio -v
DISTRIB_ID="Linino"
DISTRIB_REVISION="223d5a8"
BUILD_DATE="2016-06-01"

with this code :

var five = require("johnny-five");
var Nino = require("nino-io");
var board = new five.Board({
  io: new Nino({
    layout: "Arduino Yun"
  })
});

board.on("ready", function() {
  console.log("Ready");

  var led = new five.Led(13);

  led.blink(500);
});

i've just run, in ssh console ! : "lininoio start" and reboot. (more about lininoio on this page : http://wiki.linino.org/doku.php?id=wiki:upgradetolininoio )

and this code for servosweep works for me too :

var five = require("johnny-five");
var Nino = require("nino-io");

var board = new five.Board({
	io: new Nino({
		layout: "Arduino Yun"
	})
});

board.on("ready", function() {

  var servo = new five.Servo(9);

  // Sweep from 0-180 and repeat.
  servo.sweep();
});

For my tests, i used a servo attached to pin 9 and powered with 3.3V and not 5V (because it reboots my card) and this code :

var servo = require('./lib/servo');

servo.attach(); 

var angles = [0, 90, 45, 70, 180, 0];
for (var i=0; i<angles.length; i++){
	var a = angles[i];
	servo.write(a);
	servo.sleep(1000);
}

with that really really dirty dirty dirty test lib of my own, stored in a 'lib' directory :

//http://www.arduino.org/learning/tutorials/advanced-guides/how-to-pilot-gpio-on-lininoio-2

var exec = require('child_process').exec;

exports.write = function (angle){
	var duty = angle2duty_cycle(angle);
	console.log(duty);
	var cmdDuty = 'echo '+duty+'  > /sys/class/pwm/pwmchip0/D9/duty_cycle';
	var go = 'echo 1  > /sys/class/pwm/pwmchip0/D9/enable';
	var stop = 'echo 0  > /sys/class/pwm/pwmchip0/D9/enable';
	exec(cmdDuty, function(error, stdout, stderr) {
		//console.log('duty');
		//console.log(stdout);
		if(stderr){
			console.log(stderr);
		}
	});	
	exec(go, function(error, stdout, stderr) {
		//console.log('go');
		//console.log(stdout);
		if(stderr){
			console.log(stderr);
		}
	});
	this.sleep(500);
	exec(stop, function(error, stdout, stderr) {
		//console.log('stop');
		//console.log(stdout);
		if(stderr){
			console.log(stderr);
		}
	});
}

exports.attach = function(){
	var cmdExport = 'echo 1 > /sys/class/pwm/pwmchip0/export';
	var cmdPeriod = 'echo 20000000  > /sys/class/pwm/pwmchip0/D9/period';
	
	exec(cmdExport, function(error, stdout, stderr) {
		//console.log('export');
		//console.log(stdout);
		//console.log(stderr);
	});
	exec(cmdPeriod, function(error, stdout, stderr) {
		//console.log('period');
		// console.log(stdout);
		//console.log(stderr);
	});
}

function map_range(value, low1, high1, low2, high2) {
	return low2 + (high2 - low2) * (value - low1) / (high1 - low1);
}
function angle2duty_cycle(angle){
	return Math.round(map_range (angle, 0, 180, 560000, 2400000));
}
exports.sleep = function ( sleepDuration ){
    var now = new Date().getTime();
    while(new Date().getTime() < now + sleepDuration){ /* do nothing */ } 
}


/*
	echo 1 > /sys/class/pwm/pwmchip0/export
	echo 20000000  > /sys/class/pwm/pwmchip0/D9/period
	echo 560000  > /sys/class/pwm/pwmchip0/D9/duty_cycle
	echo 1  > /sys/class/pwm/pwmchip0/D9/enable
*/
//gestion YUN

but one advantage from my dirty lib comparing with the nino-io one is that the servo doesn't vibrate as if he was always working, this can be done with the 'stop' command that writes 0 in the enable file. (" echo 0 > /sys/class/pwm/pwmchip0/D9/enable ")

Hope this could help ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants