How to Beep a Grove Buzzer in Raspberry Pi

W/ Base Board

1) Connect the module to the D2 port.

2) Run the following code:

from grovepi import *

pin = 2

pinMode(pin, "OUTPUT")

while True:
  digitalWrite(pin, 0) # or 1

W/o Base Board

Advertisements

How to Detect Press of a Grove Button in Raspberry Pi

W/ Base Board

1) Connect the module to the D2 port.

2) Run the following code:

from grovepi import *

pin = 2

pinMode(pin, "INPUT")

while True:
  print digitalRead(pin)

W/o Base Board

How to Check the Battery Level in Myo

Myo Script

Not supported.

Myo SDK

import myo

class SampleListener(myo.DeviceListener):
  def on_battery_level(self, event):
    print(event.battery_level)

  def on_connected(self, event):
    event.device.request_battery_level()

myo.init()

hub = myo.Hub()

listener = SampleListener()

hub.run_forever(listener.on_event)

How to Vibrate in Myo

Myo Script

scriptId = 'br.eti.fernandoribeiro.myo.SampleScript'
scriptTitle = 'Sample Script'

function onForegroundWindowChange(app, title)
  ...
  return true
end

function onActiveChange(isActive)
  if isActive then
    myo.vibrate('short') -- or medium or long
  end
end

Myo SDK

import myo

class SampleListener(myo.DeviceListener):
  def on_connected(self, event):
    event.device.vibrate()

myo.init()

hub = myo.Hub()

listener = SampleListener()

hub.run_forever(listener.on_event)

How to Lock/Unlock in Myo

Myo Script

scriptId = 'br.eti.fernandoribeiro.myo.SampleScript'
scriptTitle = 'Sample Script'

function onForegroundWindowChange(app, title)
  ...
  return true
end

function onActiveChange(isActive)
  if isActive then
    myo.lock() -- or unlock()
  end
end

Myo SDK

import myo

class SampleListener(myo.DeviceListener):
  def on_connected(self, event):
    event.device.lock() # or unlock()

myo.init()

hub = myo.Hub()

listener = SampleListener()

hub.run_forever(listener.on_event)

How to Get Orientation Data in Myo

Myo Script

scriptId = 'br.eti.fernandoribeiro.myo.SampleScript'
scriptTitle = 'Sample Script'

function onForegroundWindowChange(app, title)
  ...
  return true
end

function onPeriodic()
  x, y, z = myo.getOrientationWorld()

  myo.debug('X = ' .. x)
  myo.debug('Y = ' .. y)
  myo.debug('Z = ' .. z)
end

Myo SDK

import myo

class SampleListener(myo.DeviceListener):
  def on_orientation(self, event):
    print(event.orientation)

myo.init()

hub = myo.Hub()

listener = SampleListener()

hub.run_forever(listener.on_event)

How to Get Gyroscope Data in Myo

Myo Script

scriptId = 'br.eti.fernandoribeiro.myo.SampleScript'
scriptTitle = 'Sample Script'

function onForegroundWindowChange(app, title)
  return true
end

function onPeriodic()
  x, y, z = myo.getGyro()

  myo.debug('X = ' .. x)
  myo.debug('Y = ' .. y)
  myo.debug('Z = ' .. z)
end

Myo SDK

import myo

class SampleListener(myo.DeviceListener):
  def on_orientation(self, event):
    print(event.gyroscope)

myo.init()

hub = myo.Hub()

listener = SampleListener()

hub.run_forever(listener.on_event)

How to Get Acceleration Data in Myo

Myo Script

scriptId = 'br.eti.fernandoribeiro.myo.SampleScript'
scriptTitle = 'Sample Script'

function onForegroundWindowChange(app, title)
  return true
end

function onPeriodic()
  x, y, z = myo.getAccel()

  myo.debug('X = ' .. x)
  myo.debug('Y = ' .. y)
  myo.debug('Z = ' .. z)
end

Myo SDK

import myo

class SampleListener(myo.DeviceListener):
  def on_orientation(self, event):
    print(event.acceleration)

myo.init()

hub = myo.Hub()

listener = SampleListener()

hub.run_forever(listener.on_event)

How to Detect a Pose in Myo

Myo Script

scriptId = 'br.eti.fernandoribeiro.myo.SampleScript'
scriptTitle = 'Sample Script'

function onForegroundWindowChange(app, title)
  ...
  return true
end

function onPoseEdge(pose, edge)
  if pose == 'doubleTap' and edge == 'on' then -- or fingersSpread, first, waveIn, waveOut or rest
    myo.debug(pose)
  end
end

Myo SDK

import myo

class SampleListener(myo.DeviceListener):
  def on_pose(self, event):
    if (event.pose == myo.Pose.double_tap): # or fingers_spread, fist, wave_in, wave_out or rest
      print(event.pose)

myo.init()

hub = myo.Hub()

listener = SampleListener()

hub.run_forever(listener.on_event)

How to Get Voltage with a Grove Voltage Divider in Wio Node

REST API

1) Connect the module to PORT1.

2) Run the following code:

import requests

res = requests.get('https://host/v1/node/GroveVolDividerA0/voltage_x3', headers = { 'Authorization': 'nodetoken' }) # or voltage_x10

if res.ok:
  print res.text

CLI

1) Connect the module to PORT1.

2) Configure the CLI:

wio login

3) Run the following command:

wio call nodetoken GET /v1/node/GroveVolDividerA0/voltage_x3 # or voltage_x10