Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

SensorKit

Per Persson edited this page Jul 7, 2017 · 2 revisions

Calvin Sensor Kit v0.1

This file is autogenerated from calvin.config and images/ using the sensor-kit-doc.py utility. Process with markdown to generate a nicely formatted document, e.g.;

markdown readme.md > readme.html

or use the version on the Calvin wiki

Compatibility

Type 3 - Model A+, B+, Pi Zero, Pi2B, Pi3B

  • 40 pin expansion header (J8).
  • Hardware revision numbers of 16 or greater.
  • User GPIO 2-27 (0 and 1 are reserved).

Pinout

...--------------------------------+
                                   |
      GPIO  pin pin  GPIO          |
           +-------+               |
3V3     -  | 1    2|   -   5V      |
SDA     2  | 3    4|   -   5V      |
SCL     3  | 5    6|   -   GND     |
        4  | 7    8|  14   TXD     |
GND     -  | 9   10|  15   RXD     |
ce1    17  |11   12|  18   ce0     |
       27  |13   14|   -   GND     |
       22  |15   16|  23           |
3V3     -  |17   18|  24           |
MOSI   10  |19   20|   -   GND     |
MISO    9  |21   22|  25           |
SCLK   11  |23   24|   8   CE0     |
GND     -  |25   26|   7   CE1     |
N/A     0  |27   28|   1   N/A     |
        5  |29   30|   -   GND     |
        6  |31   32|  12           |
       13  |33   34|   -   GND     |
miso   19  |35   36|  16   ce2     |
       26  |37   38|  20   mosi    |
GND     -  |39   40|  21   sclk    |
           +-------+               .
                                   .
                                   .

Configuring devices

First a word about Calvin sensors on a Rasberry Pi: The preferred way to package IoT-devices in Calvin's world is units with a single capability, or a few capabilities, each with its own attributes to resolve actor placement in a real world deployment.

That said, Raspberry Pi's are a great way to get started with Calvin, and we have defined a default sensor-kit with parts that are easy to find in stores and online. In order to maximize the number of simultaneous sensors that can be used and to avoid conflicts between sensors (in terms of pins used) we also provide default pin configurations for the sensor-kit below.

Note that we are using GPIO pin numbering, not board pin numbering below.

Almost all sensors can be attached to a single Raspberry Pi at the same time, and if there is a conflict it is stated in the documentation below.

With each sensor, its default config entry is shown. The full config file is part of the sensor-kit code that can be found in calvin/examples/sensor-kit. That config file makes a good starting point for any customization that a user might want to do.

There is still room for expansion, since GPIO pins 6, 14, 15, and 27 are as of yet undefined, although using them as follows would make sense:

  • pin 6 : Digital out
  • pin 27 : Digital in
  • pin 14 : TxD
  • pin 15 : RxD

Devices

Push button (KY-004)

N.B. a button behaves differently from a switch

Default pin(s): 16

KY-004

Config entry in capabilities list:

io.button: {
    "comment": "Push-to-make button", 
    "attributes": {
        "switch_pin": 16
    }, 
    "module": "io.ky040knob.raspberry_pi.PIGPIOKY040"
}

Usage example:

in : io.Button()
out : io.Print()

in.state > out.token

Conflicts: io.knob

Rotary encoder with push button (KY-040)

Default pin(s): 17,18

KY-040

Config entry in capabilities list:

io.knob: {
    "comment": "Rotary encoder", 
    "attributes": {
        "data_pin": 17, 
        "clock_pin": 18
    }, 
    "module": "io.ky040knob.raspberry_pi.PIGPIOKY040"
}

Usage example:

in : io.Knob()
old : flow.Init(data=50)
mul : math.Compute(op="*")
add : math.Compute(op="+")
out : io.Print()
dimmer : io.PWM()

in.direction > mul.a
5 > mul.b

mul.result > add.a
old.out > add.b

add.result > old.in
add.result > out.token
add.result > dimmer.dutycycle


Conflicts: io.button

Ultrasonic distance sensor (Distance)

Default pin(s): 20,21

Distance

Config entry in capabilities list:

io.distance: {
    "attributes": {
        "echo_pin": 21, 
        "trigger_pin": 20
    }, 
    "module": "io.sr04distance.raspberry_pi.GPIOSR04"
}

Usage example:

distance : sensor.Distance(frequency=5)
out : io.Print()

distance.meters > out.token

Temperature sensor (KY-001)

Default pin(s):

KY-001

Config entry in capabilities list:

io.temperature: {
    "comment": "This device talks 1-wire on pin GPIO4", 
    "attributes": {
        "id": "n/a"
    }, 
    "module": "io.ds18b20thermometer.raspberry_pi.DS18B20"
}

Usage example:

temperature : sensor.Temperature(frequency=1)
out : io.Print()

temperature.centigrade > out.token

Relative humidity sensor (KY-015)

DHT11 based, but not used as temparature sensor because of the poor resolution.

Default pin(s): 19

KY-015

Config entry in capabilities list:

io.humidity: {
    "attributes": {
        "pin": 19
    }, 
    "module": "io.dht11temphumidity.raspberry_pi.DHT11"
}

Usage example:

trigger : std.Trigger(tick=1, data=true)
hum : sensor.RelativeHumidity()
print : io.Print()

trigger.data > hum.measure
hum.percent > print.token

Hall magnetic sensor module (KY-003)

Default pin(s): 23

KY-003

Config entry in capabilities list:

io.hallswitch: {
    "attributes": {
        "pull": "OFF", 
        "direction": "IN", 
        "edge": "BOTH", 
        "pin": 23
    }, 
    "module": "io.gpiopin.raspberry_pi.PIGPIOPin"
}

Tilt switch (KY-020)

Default pin(s): 13

Config entry in capabilities list:

io.tiltswitch: {
    "attributes": {
        "pull": "DOWN", 
        "direction": "IN", 
        "edge": "BOTH", 
        "pin": 13, 
        "bouncetime": 200
    }, 
    "module": "io.gpiopin.raspberry_pi.PIGPIOPin"
}

Usage example:

in : sensor.TiltSwitch()
out : io.Print()
led : io.Led()

in.open > out.token
in.open > led.on

Conflicts: io.vibrationsensor, io.knocksensor

Schock sensor module (KY-031)

Default pin(s): 13

Config entry in capabilities list:

io.knocksensor: {
    "attributes": {
        "pull": "DOWN", 
        "direction": "IN", 
        "edge": "BOTH", 
        "pin": 13, 
        "bouncetime": 200
    }, 
    "module": "io.gpiopin.raspberry_pi.PIGPIOPin"
}

Conflicts: io.vibrationsensor, io.tiltswitch

Optical gap switch (KY-010)

Default pin(s): 22

KY-010

Config entry in capabilities list:

io.lightbreaker: {
    "attributes": {
        "pull": "DOWN", 
        "direction": "IN", 
        "edge": "BOTH", 
        "pin": 22, 
        "bouncetime": 200
    }, 
    "module": "io.gpiopin.raspberry_pi.PIGPIOPin"
}

Usage example:

in : sensor.KnockSensor()
out : io.Print()
led : io.Light()

in.open > out.token
in.open > led.on

Digital out (LED with resistor) ([LED][LED])

Serial resistor 220 Ohm needed for LED.

Default pin(s): 5

LED

Config entry in capabilities list:

io.light: {
    "comment": "Digital out, use with LED + 150 Ohm resistor", 
    "attributes": {
        "direction": "OUT", 
        "pin": 5
    }, 
    "module": "io.gpiopin.raspberry_pi.PIGPIOPin"
}

Usage example:

button : io.Button()
light: io.Light()
out : io.Print()

button.state > light.on
button.state > out.token


PWM out (LED with resistor) ([PWM][PWM])

Serial resistor 220 Ohm needed for LED.

Default pin(s): 26

PWM

Config entry in capabilities list:

io.pwm: {
    "attributes": {
        "frequency": 50, 
        "pin": 26, 
        "dutycycle": 50
    }, 
    "module": "io.pwm.raspberry_pi.PIGPIOPWM"
}

Active buzzer module (KY-012)

Active buzzer 2.5kHz.

N.B. The labels on the PCB are wrong on many of these, try swapping the leads if there is no beeping.

Default pin(s): 12

KY-012

Config entry in capabilities list:

io.buzzer: {
    "comment": "Active buzzer (KY-012, GND -> 'S', GPIO pin to '-')", 
    "attributes": {
        "direction": "OUT", 
        "pin": 12
    }, 
    "module": "io.gpiopin.raspberry_pi.PIGPIOPin"
}

Usage example:

buzzer: io.Buzzer()

50 > buzzer.volume