0

I've just acquired myself a Pi-mote from Energenie. I'm trying to replicate the code from their website using Ruby and the pi_piper gem, but I've run in to problems.

For some reason, my turn_1_on function works just fine. But none of the others seem to work. I have tested that it still works correctly and as intended throughout with the python script.

Code as follows:

require 'pi_piper'
  include PiPiper
  # Select the GPIO pins used for the encoder D0-D3 data inputs
  @pin11 = PiPiper::Pin.new(:pin => 17, :direction => :out)
  @pin13 = PiPiper::Pin.new(:pin => 27, :direction => :out)
  @pin15 = PiPiper::Pin.new(:pin => 22, :direction => :out)
  @pin16 = PiPiper::Pin.new(:pin => 23, :direction => :out)

  # Select the signal to select ASK/FSK
  @pin18 = PiPiper::Pin.new(:pin => 24, :direction => :out)

  # Select the signal used to enable/disable the modulator
  @pin22 = PiPiper::Pin.new(:pin => 25, :direction => :out)

  # Disable the modulator by setting CE pin lo
  @pin22.off

  # Set the modulator to ASK for On Off Keying
  # by setting MODSEL pin lo
  @pin18.off

  # Initialise D0-D3 inputs of the encoder to 0000
  @pin11.off
  @pin13.off
  @pin15.off
  @pin16.off

  # The On/Off code pairs correspond to the hand controller codes.
  # True = '1', False ='0'

  def turn_1_on
    @pin11.on
    puts "Pin11 now has value #{@pin11.value}"
    @pin13.on
    puts "Pin13 now has value #{@pin13.value}"
    @pin15.on
    puts "Pin15 now has value #{@pin15.value}"
    @pin16.on
    puts "Pin16 now has value #{@pin16.value}"
    sleep(0.1)
    @pin22.on
    sleep(0.25)
    @pin22.off
  end

  def turn_1_off
    @pin11.on
    puts "Pin11 now has value #{@pin11.value}"
    @pin13.on
    puts "Pin13 now has value #{@pin13.value}"
    @pin15.on
    puts "Pin15 now has value #{@pin15.value}"
    @pin16.off
    puts "Pin16 now has value #{@pin16.value}"
    sleep(0.1)
    @pin22.on
    sleep(0.25)
    @pin22.off
  end
1

Just been playing with this myself. I'm sure you've already sorted it but your pin ordering is wrong -

The encoder signals are -

  • D0 - GPIO pin 17 / Energenie board pin 11
  • D1 - GPIO pin 22 / Energenie board pin 15
  • D2 - GPIO pin 23 / Energenie board pin 16
  • D3 - GPIO pin 27 / Energenie board pin 13

Socket 1 off is then 1, 1, 1, 0 -

  def turn_1_off
    @pin11.on
    puts "Pin11 now has value #{@pin11.value}"
    @pin13.off # <---- PIN 13 is off!
    puts "Pin13 now has value #{@pin13.value}"
    @pin15.on
    puts "Pin15 now has value #{@pin15.value}"
    @pin16.on
    puts "Pin16 now has value #{@pin16.value}"
    sleep(0.1)
    @pin22.on
    sleep(0.25)
    @pin22.off
  end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.