0

I am trying to create a simple ruby app to work with an Arduino. My problem is that the Ruby Gems are not being found. This is my script code - it is from a tutorial i found:

#!/usr/bin/ruby -rubygems

require 'rubygems'
require 'serialport'
require 'gmail'

#plug in your username and password here
gmail = Gmail.connect("username", "password")

#count the number of unread messages
prev_unread = gmail.inbox.count(:unread)

#this *will* be different for you
#You need to find out what port your arduino is on
#and also what the corresponding file is on /dev
#You can do this by looking at the bottom right of the Arduino
#environment which tells you what the path.
port_file = '/dev/tty.usbmodem1421'

#this must be same as the baud rate set on the Arduino
#with Serial.begin
baud_rate = 9600

data_bits = 8
stop_bits = 1
parity = SerialPort::NONE

#create a SerialPort object using each of the bits of information
port = SerialPort.new(port_file, baud_rate, data_bits, stop_bits, parity)

wait_time = 4

#for an infinite amount of time
loop do
  #get the number of unread messages in the inbox
  unread = gmail.inbox.count(:unread)

  #lets us know that we've checked the unread messages
  puts "Checked unread."

  #check if the number of unread messages has increased
  #if so, we have a new email! So, blink the LED.
  if unread > prev_unread
    port.write "b"
  end

  #reset the number of unread emails
  prev_unread = unread

  #wait before we make another request to the Gmail servers
  sleep wait_time
end

I then go to the directory where this file (gmail_notifier.rb) lives and run ruby gmail_notifier.rb. This is the error i am receiving after running that command:

/Users/ryan/.rvm/rubies/ruby-2.0.0-head/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require': cannot load such file -- serialport (LoadError)
    from /Users/ryan/.rvm/rubies/ruby-2.0.0-head/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require'
    from gmail_notifier.rb:4:in `<main>'

Anyone know why the gems are not being found? I did run gem install gmail and gem install serialport already.

ryanpitts1
  • 862
  • 1
  • 16
  • 33
  • from the terminal can you just confirm that `gem which gmail` and `gem which serialport` give sensible paths? – Mike H-R Nov 20 '13 at 03:48

1 Answers1

1

See here, you need to have:

gem 'gmail'
gem 'serialport'

before your require line. (As long as you are on ruby >1.8)

Community
  • 1
  • 1
Mike H-R
  • 7,726
  • 5
  • 43
  • 65
  • I believe this will correct my issue...although now i am having a separate issue that i did not see before. The serialport gem ins't installing correctly. Separate issue from this SO question though. Thanks for the help with that part. – ryanpitts1 Nov 20 '13 at 03:58
  • Figured out the rest! I had to run `xcode-select --install` to get command line tools since i'm on a mac and can't get the ruby devkit. After running that the script works perfectly! Thanks again @Mike. – ryanpitts1 Nov 20 '13 at 04:23
  • 1
    hahaha I just [answered exactly that question for someone else](http://stackoverflow.com/questions/20086965/no-available-formula-for-gcc46-while-installing-ruby-1-9-3-on-os-x-with-rvm/20087200#20087200). Glad you got it sorted! – Mike H-R Nov 20 '13 at 04:26