CSUN ASME Arduino Integrations (Spring 2017)
npm install milana



OS X & Linux:
``sh`
npm install milana --save
Windows:
`sh`
edit autoexec.bat
Johnny-Five communicates with the Arduino microcontroller; for the Arduino to run Johnny-Five, the Arduino relies on a host computer to run the Johnny-Five library, using a Serial I/O protocol, named Firmata. Where, Firmata is utilized to run the hardware pins, using Bluetooth.
* go to the node.js website to download the latest node.js installer. If you are done with this step, go onto the next step below
* go to the computer's command line and run npm install milana. If you are done with this step, go onto the next step below
* connect the Arduino to the Mac computer via USB. Where, the USB provides both power, and a method to upload software to the Arduino board. If you see a green light start to flicker after plugging in the board, this is a good sign. If you are done with this step, go onto the next step below
* open the Arduino IDE. If you are done with this step, go onto the next step below
* go to the Mac's tool bar at the top of the computer's screen, click on "Tools", then scroll down to "Serial Port", and make sure that the "checkmark" is on the right option; if you're not sure, just do trial-and-error. If you have figured out the right option, go onto the next step below
* go to the tool bar at the top of the computer screen, click on "Tools", then scroll down to "Board", and make sure the correct type of Arduino is checked (i.e. Arduino Uno, etc..). If you're done with this step, go onto the next step below
* go to the tool bar at the top of the computer's screen, click on "File", then scroll down to "Examples", then scroll to "Firmata", then scroll down to "StandardFirmata", where a new window will open. Then "upload" the file by mousing to the top of that window, then pressing :arrow_right:. If you are done with this step, go onto the next step below
* on the bottom of the Arduino IDE window, you will see "Uploading..."; wait until it says "Done uploading". If you are done with this step, go onto the next step below
* congratulations! You have sucessfully downloaded the Firmata software onto the Arduino board
* run Milana by going onto the command line, then typing npm start
* to turn off the board, type "control-c", then "control-c" once more
* these commands are listed within the package.json file:
`sh`
npm start
:information_source: npm start uses Bash to run the app.js file, which is Milana's "entry point".
* while running the Milana application, feel free to run these commands within the REPL:
:triangular_flag_on_post: ledStatus.on(); ledStatus.off(); ledStatus.toggle(); ledStatus.strobe(500); ledStatus.blink(500); ledStatus.stop(); ledStatus.brightness(256)
:triangular_flag_on_post: sprintRelay.close(); sprintRelay.open()
:triangular_flag_on_post: liftRelay.close(); liftRelay.open()
:triangular_flag_on_post: throwRelay.close(); throwRelay.open();
:triangular_flag_on_post: sprintRelay.close(); sprintRelay.open();
* Node.js handles multi-threading in the background, while the user implements a single-threaded model, which translates to the benefits of a high throughput rate, based on I/O bound-tasks. Also, by choosing Node.js for its implementation enviroment, ASME-CSUN benefits from handling lower-resource requirements for concurrent I/O bound requests.
:small_orange_diamond: johnny-five
:small_orange_diamond: bluebird
:small_orange_diamond: xbox-controller
:small_orange_diamond: keypress
#### Dependency Illustrations
:ballot_box_with_check: johnny-five
> the package to run Node.js on the Arduino.
:ballot_box_with_check: bluebird
> a package to implement "promises" within the application; promises are objects for handling asynchronous responses. The returned value of a promise is an object, where promises provide functionality for .then(fn), where the passed function is called with the result if the given promise resolves. Also, a user who implements promises within their code may use the .catch(fn) functionality, where the passed function is called with the given error, if the promise is rejected.
* the result of a function, which is wrapped inside a promise, can be either another promise, or an actual value.
* if the result of a function is not a promise, the function will be wrapped as a resolved promise automatically.
* the benefits of promise-behavior is the allowance of promises to be chained together, easily, without having to unwrap resulting-promises.
:ballot_box_with_check: xbox-controller
> the behavior of the motors on the robot are mapped to the controlls to the Xbox controller.
:information_source: _useage of xbox-controller_
`javascript
var XboxController = require('xbox-controller');
var xbox = new XboxController;
xbox.on('b:release', function(key) {
console.log(key + ' release');
});
xbox.on('lefttrigger', function(position) {
console.log('lefttrigger', position);
});
xbox.on('righttrigger', function(position) {
console.log('righttrigger', position);
});
xbox.on('left:move', function(position) {
console.log('left:move', position);
});
xbox.on('right:move', function(position) {
console.log('right:move', position);
});
xbox.on('connected', function() {
console.log('Xbox controller connected');
});
xbox.on('not-found', function() {
console.log('Xbox controller could not be found');
});
`
:ballot_box_with_check: keypress
> make any Node.js ReadableStream emit "keypress" events (e.g. needed for xbox-controller).
:white_check_mark: Relays
:white_check_mark: Transistors
:white_check_mark: Actuators
:white_check_mark: DC Motors
:white_check_mark: Bluetooth Module
:white_check_mark: Xbox Controller
:white_check_mark: L293D H-Bridge
> __Relays__ are physical mechanisms that allow to connect a switch; relays are electronically-controlled physical switches. Where, relays leverage a small-amount of power to control a high-amount of power; relays have three pins that need a connection: a common pin, a normally-connected pin, and a normally-open pin; whenever you close that relay, that causes the switch from the normally-closed to the the normally-open, and connect those two. And, when the switch is being opened, it goes back to the other-point.
> __Transistors__ are physical mechanisms for a switch; instead of making a switch move like a relay, transistors make the switch move within silicone; transitors will be used to give-enough power to the relays.
> __Actuators__ have an electric motor that turns a threaded rod; attached to the threaded rob is a nut, which is also threaded. Where depending on the rotation of the motor, the threaded rod can move both up and down, or left and right.
> __DC Motors__ give the bot the property of motion.
> __Bluetooth Module__ has a latency of about 500 milliseconds, which is due to Bluetooth in-of-itself; this latency-factor may pose a problem with steering, while using the Xbox controller; the Bluetooth module connects the Arduino microcontroller to the host-computer, using a Serial I/O protocol, defined under Firmata.
> __Xbox Controller__ is node-module, which allows to the ability of using the Xbox contoller.
;
;
American Society of Mechanical Engineers, CSUN Chapter – Facebook - CSUN ASME
Distributed under the MIT license. See LICENSE` for more information.