Giter Site home page Giter Site logo

gustavo053 / ruby-esp32-arduino Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 8 KB

Studies of hardware devices and frameworks in an IoT environment for integration with the FIBER platform

Home Page: https://rubyeembarcados.netlify.app/

Ruby 100.00%
ruby arduino esp32 iot studies embbeded

ruby-esp32-arduino's Introduction

Ruby-connected-to-the-Arduino

Connection using the framework Arduino_Firmata

arduino_firmata

Firmata is a protocol to controll Arduino from software on PC. You can embed Arduino code into Ruby application. This library supports sharing an Arduino between multiple processes.

INSTALL

% gem install arduino_firmata

REQUIREMENTS

Ruby 1.8.7 or 1.9.2 or 1.9.3 or 2.0.0
testing with Arduino Diecimila, Duemillanove, UNO, Leonardo, Micro and Seeduino v2
Arduino Standard Firmata v2.2
    Arduino IDE -> [File] -> [Examples] -> [Firmata] -> [StandardFirmata]

ArduinoFirmata Command

% arduino_firmata --help % arduino_firmata --list % arduino_firmata digital_write 13, true % arduino_firmata analog_read 0 % arduino_firmata servo_write 9, 145

Sample Code

https://github.com/shokai/arduino_firmata/tree/master/samples
Tweet temperature just 9 lines.
Controll Arduino on Sinatra 20 lines.

Setup

Connect

require "rubygems" require "arduino_firmata"

arduino = ArduinoFirmata.connect # use default arduino arduino = ArduinoFirmata.connect "/dev/tty.usb-device-name" arduino = ArduinoFirmata.connect "/dev/tty.usb-device-name", :bps => 57600 arduino = ArduinoFirmata.connect "/dev/tty.usb-device-name", :nonblock_io => true

Board Version

puts "firmata version #{arduino.version}"

Close

arduino.close

I/O

Digital Write

on board Yellow LED

arduino.digital_write 13, true arduino.digital_write 13, false

Digital Read

arduino.pin_mode 7, ArduinoFirmata::INPUT puts arduino.digital_read 7 # => true/false

arduino.on :digital_read do |pin, status| # digital_read event if pin == 7 puts "digital pin #{pin} changed : #{status}" end end

Analog Write (PWM)

0.upto(255) do |i| arduino.analog_write 11, i # <= 0 ~ 255 sleep 0.01 end

Analog Read

puts arduino.analog_read 0 # => 0 ~ 1023

arduino.on :analog_read do |pin, value| # analog_read event if pin == 0 puts "analog pin #{pin} changed : #{value}" end end

Servo Motor

loop do angle = rand 180 puts "servo angle #{angle}" arduino.servo_write 9, angle sleep 1 end

VCC, GND and Digital 9 PIN -> Servo Motor

Sysex

http://firmata.org/wiki/V2.1ProtocolDetails#Sysex_Message_Format
https://github.com/shokai/arduino_firmata/tree/master/samples/sysex

Send

arduino.sysex 0x01, [13, 5, 2] # command, data_array

Receive Event

arduino.on :sysex do |command, data| puts "command : #{command}" puts "data : #{data.inspect}" # data_array end

Block Style

ArduinoFirmata.connect do puts "firmata version #{version}"

30.times do an = analog_read 0 analog_write 11, an sleep 0.01 end end

ruby-esp32-arduino's People

Contributors

gustavo053 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.