Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Do	you	want	to	build	a	
robot?
Anna	Gerber
Robot	Design
A	robot	is	an	autonomous	system	that	senses	
and	responds	to,	or	acts	upon	the	physical	world
Sensors
(Inputs	e.g.	ultrasonic	sensor)
Control
(Microcontroller	or	
Single-Board-Computer)
Actuators
(Outputs	e.g.	motors...
JS	Robotics
• http://johnny-five.io/
• https://www.espruino.com/
• https://tessel.io/
• https://docs.particle.io/reference...
Selecting	hardware
• Johnny-Five	supports	Arduino,	Raspberry	Pi,	Tessel,	Particle,	
BeagleBone,	and	more
Johnny-Five
• Open	Source	JavaScript	Robotics	
Framework	for	Node.js
https://github.com/rwaldron/johnny-five
• Communicate...
Set	up	Raspberry	Pi	Zero	W	(headless)
• Install	Raspbian:
• https://www.raspberrypi.org/documentation/installation/install...
Connect	to	the	Raspberry	Pi
• Rpi uses	mDNS so	connect	to	the	Pi	over	SSH:
• ssh pi@raspberrypi.local
• Default	password	i...
Raspberry	Pi	GPIO
• Solder	some	headers	on	to	the	Raspberry	
Pi	Zero	W	for	the	GPIO	pins
• Peripheral	components	(e.g.	sen...
Breadboard
• Use	to	prototype	circuits	without	soldering	by	
plugging	in	components	and	jumper	wires
• Numbered	rows	are	c...
Attach	an	LED	using	a	Breadboard
Writing	Johnny-Five	programs
1. Create	a	JavaScript	file	(e.g.	blink.js)	on	the	Pi
2. Edit	it	using	a	text	editor	
3. Requ...
Ready	event
• When	the	board	is	ready	for	our	code	to	start	interacting	with	it	and	
the	attached	sensors	and	actuators,	i...
LED
• Create	an	Led	instance
// attach LED on pin 7
const led = new five.Led('P1-7');
// call strobe function to blink onc...
LED	blink	program
const raspi = require('raspi-io');
const five = require('johnny-five');
const board = new five.Board({
i...
Inputs	- Sensors
• Environmental	conditions (e.g.	temperature,	humidity)
• Magnetic	(e.g.	hall	effect	sensor)
• Light	(e.g...
Inputs
PHOTO	RESISTOR
Resistance changes	depending	on	the	
amount	of ambient light
TILT	SWITCH
Detect	orientation
PUSH	BUT...
Outputs
• Light	&	Displays	(e.g.	LED,	LCD	screen)
• Sound	(e.g.	Piezo buzzer)
• Movement	(e.g.	Servo,	DC	Motor,	Solenoid)
...
Outputs
PIEZO	ELEMENT
A	pulse	of	current	will	cause	it	to	click.	A	stream	of	
pulses	will	cause	it	to	emit	a	tone.
RGB	LED...
Digital	vs Analog
• Digital
• discrete	values	(0	or	1)
• Examples:	tilt	sensor,	push	button
• Analog
• continuous	values
•...
REPL
• Read,	Eval,	Print	Loop
• A	console	for	real-time	interaction	with	the	code
• Expose	our	variables	to	the	REPL	to	en...
Controlling	the	LED	via	the	REPL
• At	the	REPL	prompt	type	commands	followed	by	enter
• Try:
• stop,	
• on,	
• off,	
• tog...
Buttons
const button	=	new	five.Button("P1-11");		
const led	=	new	five.Led("P1-7");		
button.on("down",	(value)	=>	{				
...
Servos
const myServo =	new	five.Servo("P1-35");
board.repl.inject({
servo:	myServo
});
myServo.sweep();
board.wait(5000,	(...
PWM
• Pulse	Width	Modulation
• Produce	analog	output	via	digital	pins
• Instead	of	on	or	off,	a	square	wave	is	sent	to	sim...
Piezo
const piezo	=	new	five.Piezo("P1-32");
let val = 0;
board.loop(200,	function()	{
if (val ^= 1) {
//	Play	note	a4	for...
Motors
const leftMotor = new five.Motor({
pins: {pwm: "P1-35", dir: "P1-13"},
invertPWM: true
});
const rightMotor = new f...
Node-RED
• Anna’s	blog:	http://crufti.com
• http://johnny-five.io/
• Node-ARDX	(examples	for	Arduino):	http://node-ardx.org
Read	mo...
Upcoming SlideShare
Loading in …5
×

Do you want to build a robot

208 views

Published on

From CampJS VIII, Melbourne 4 - 7 August 2017

This session will show you how to take your robotics and IoT dreams and make them reality through the magic of JavaScript, including:
selecting hardware and developing circuits,
overview of some of the different options for developing programs to read from sensors and control actuators for robotics and IoT projects using JS,
connecting your device and getting it talking with other devices and services

Published in: Technology
  • Be the first to comment

Do you want to build a robot

  1. 1. Do you want to build a robot? Anna Gerber
  2. 2. Robot Design A robot is an autonomous system that senses and responds to, or acts upon the physical world
  3. 3. Sensors (Inputs e.g. ultrasonic sensor) Control (Microcontroller or Single-Board-Computer) Actuators (Outputs e.g. motors) PowerChassis
  4. 4. JS Robotics • http://johnny-five.io/ • https://www.espruino.com/ • https://tessel.io/ • https://docs.particle.io/reference/javascript/ • https://cylonjs.com/ • http://jerryscript.net/ • http://mujs.com/ • http://duktape.org/
  5. 5. Selecting hardware • Johnny-Five supports Arduino, Raspberry Pi, Tessel, Particle, BeagleBone, and more
  6. 6. Johnny-Five • Open Source JavaScript Robotics Framework for Node.js https://github.com/rwaldron/johnny-five • Communicates with microcontrollers like Arduino using the Firmata protocol • Runs on-board devices that can run Node.js e.g. Raspberry Pi, BeagleBone Black, via I/O Plugins
  7. 7. Set up Raspberry Pi Zero W (headless) • Install Raspbian: • https://www.raspberrypi.org/documentation/installation/installing- images/README.md • Create a file named wpa_supplicant.conf on the microSD card: network={ ssid="campjs" psk="morecoffee" } • Add a file named ssh (contents don’t matter) on the root of the microSD card to enable SSH on boot
  8. 8. Connect to the Raspberry Pi • Rpi uses mDNS so connect to the Pi over SSH: • ssh pi@raspberrypi.local • Default password is raspberry • (Make sure you change this) • Raspbian comes with node.js installed but if you are using something else, install node • Then use npm to install the dependencies: • npm install serialport • npm install johnny-five raspi-io
  9. 9. Raspberry Pi GPIO • Solder some headers on to the Raspberry Pi Zero W for the GPIO pins • Peripheral components (e.g. sensors, actuators) attach via these pins • 3.3V logic • In Johnny-Five the pins are named "P[header]-[pin]” e.g. P1-7
  10. 10. Breadboard • Use to prototype circuits without soldering by plugging in components and jumper wires • Numbered rows are connected • Some have power rails along the sides
  11. 11. Attach an LED using a Breadboard
  12. 12. Writing Johnny-Five programs 1. Create a JavaScript file (e.g. blink.js) on the Pi 2. Edit it using a text editor 3. Require the johnny-five library and raspi-io libraries into and set up the board object using the IO/Plugin const raspi = require('raspi-io'); const five = require('johnny-five'); const board = new five.Board({ io: new raspi() });
  13. 13. Ready event • When the board is ready for our code to start interacting with it and the attached sensors and actuators, it will trigger a ready event board.on('ready', () => { // code for sensors, actuators goes here });
  14. 14. LED • Create an Led instance // attach LED on pin 7 const led = new five.Led('P1-7'); // call strobe function to blink once per second led.strobe(1000); • We can change the parameter to the strobe function to change the speed: This input value is provided in milliseconds
  15. 15. LED blink program const raspi = require('raspi-io'); const five = require('johnny-five'); const board = new five.Board({ io: new raspi() }); board.on('ready', () => { // LED attached to RPi pin 7 (GPIO4) const led = new five.Led('P1-7'); led.strobe(500); });
  16. 16. Inputs - Sensors • Environmental conditions (e.g. temperature, humidity) • Magnetic (e.g. hall effect sensor) • Light (e.g. photo resistor) • Sound (e.g. microphone, piezo) • Movement / position (e.g. accelerometer, tilt switch) • User Input (e.g. button)
  17. 17. Inputs PHOTO RESISTOR Resistance changes depending on the amount of ambient light TILT SWITCH Detect orientation PUSH BUTTON Also known as momentary switch PIEZO ELEMENT Detect vibrations or knocks TEMPERATURE SENSOR Read the ambient temperature
  18. 18. Outputs • Light & Displays (e.g. LED, LCD screen) • Sound (e.g. Piezo buzzer) • Movement (e.g. Servo, DC Motor, Solenoid) • Relays
  19. 19. Outputs PIEZO ELEMENT A pulse of current will cause it to click. A stream of pulses will cause it to emit a tone. RGB LED We are using Common Cathode RGB LEDs. The longer lead is the common lead which connects to ground. The three other leads are for Red, Green and Blue signal 9G HOBBY SERVO A box containing a motor with gears to make it positionable from 0 to 180 degrees.
  20. 20. Digital vs Analog • Digital • discrete values (0 or 1) • Examples: tilt sensor, push button • Analog • continuous values • typically values for analog sensors are constrained within a range e.g. 0 – 255, 0 – 1023 • Example: photo resistor • Some components support both digital and analog
  21. 21. REPL • Read, Eval, Print Loop • A console for real-time interaction with the code • Expose our variables to the REPL to enable interactive control: board.on('ready', () => { // LED attached to RPi pin 7 (GPIO4) const myLed = new five.Led('P1-7'); myLed.strobe(500); board.repl.inject({ led: myLed }); });
  22. 22. Controlling the LED via the REPL • At the REPL prompt type commands followed by enter • Try: • stop, • on, • off, • toggle, • strobe e.g: >> led.stop()
  23. 23. Buttons const button = new five.Button("P1-11"); const led = new five.Led("P1-7"); button.on("down", (value) => { led.on(); }); button.on(”up", (value) => { led.off(); }); http://johnny-five.io/api/button/
  24. 24. Servos const myServo = new five.Servo("P1-35"); board.repl.inject({ servo: myServo }); myServo.sweep(); board.wait(5000, () => { myServo.stop(); myServo.center(); });
  25. 25. PWM • Pulse Width Modulation • Produce analog output via digital pins • Instead of on or off, a square wave is sent to simulate voltages between 0V (off) and 5V (on) • Used to control motors, fade LEDs etc
  26. 26. Piezo const piezo = new five.Piezo("P1-32"); let val = 0; board.loop(200, function() { if (val ^= 1) { // Play note a4 for 1/5 second piezo.frequency(five.Piezo.Notes["a4"], 200); } });
  27. 27. Motors const leftMotor = new five.Motor({ pins: {pwm: "P1-35", dir: "P1-13"}, invertPWM: true }); const rightMotor = new five.Motor({ pins: {pwm: "P1-32", dir: "P1-15"}, invertPWM: true }); leftMotor.forward(150); rightMotor.forward(150); See Johnny-Five motor API http://johnny-five.io/api/motor/
  28. 28. Node-RED
  29. 29. • Anna’s blog: http://crufti.com • http://johnny-five.io/ • Node-ARDX (examples for Arduino): http://node-ardx.org Read more

×