SensorKit-X40
Contents
SEN-Kit X40
Introduction
This guide shows how to bring up SEN Kit X40 on your Tinker Borad and verify/exam with some applications.
SEN Kit X40 is a combination development kit contains a total of 40 different sensors, which are most famous and widely used on common open-source platform.
For specifics and details of sensors , please visit the official website http://www.joy-it.net/en/sensor-kit-x40/
With a lot of componments, I will devide them into groups base on the porting dependencies or their common feature.
Search for the key number or sensor name in outlines to see the section of porting steps.
Outlines
a. with GPIO
KY-003 Hall Magnetfeld-Sensor Modul
KY-004 Taster-Modul
KY-005 Infrarot Transmitter Modul
KY-006 Passives Piezo-Buzzer Modul
KY-009 RGB LED SMD Modul
KY-010 Lichtschranken-Modul
KY-011 2-Farben [Rot+Grün] 5mm LED Modul
KY-012 Aktives Piezo-Buzzer Modul
KY-016 RGB 5mm LED Modul
KY-017 Neigungsschalter Modul
KY-019 5V Relais Modul
KY-020 Neigungs-Schalter Modul
KY-021 Mini Magnet Reed Modul
KY-027 Magic Light Cup Modul
KY-029 2-Farben [Rot+Grün] 3mm LED Modul
KY-031 Klopf-Sensor Modul
KY-032 Hindernis Detektor Modul
KY-033 Tracking Sensor Modul
KY-034 7 Farben LED Flash-Modul
b. with ADC (Analog Digital Converter)
KY-018 Fotowiderstand Modul
KY-023 Joystick Modul (XY-Achsen)
KY-024 Linear magnetic Hall Sensor
KY-025 Reed Modul
KY-026 Flamen-Sensor Modul
KY-028 Temperatur Sensor Modul (Thermistor)
KY-035 Bihor Magnet Sensor Modul
KY-036 Metall-Touchsensor Modul
KY-037 Mikrofon Sensor Modul [hohe Empfindlichkeit]
KY-038 Mikrofon Sound Sensor Modul
KY-039 Herzschlag Sensor Modul
c. with Level shifter
KY-051 Voltage Translator / Level Shifter
d. others
KY-015 Kombi-SensorTemperatur+Feuchtigkeit
KY-022 Infrarot Receiver Modul
Image Version
Please use V2.0.3 image version or above
Porting steps
Before porting, please prepare the corresponding sample codes and do the HW connection.
Both of them can reference to http://sensorkit.joy-it.net/index.php?title=Hauptseite or the manual (in German).
Please note that we use the version of sample codes for RPi, not Arduino.
a. with GPIO
This section introduces those sensors need only GPIO library, since the modification are almost the same, I will show the steps with the sample code of KY-002.
And you can find all modified sample codes in attachment.
Before starting, please download the library from our github: https://github.com/TinkerBoard/gpio_lib_python
(Warning: If you have downloaded the library before 2017/10/25, please re-download it, or you may meet the add_event_detect() error in exam!)
And follow below instructions:
$ sudo apt-get update $ sudo apt-get install python-dev $ cd <PATH_TO_GPIO_LIB_PYTHON> && python setup.py install
Then, modify the gpio setting in the sample code:
import ASUS.GPIO as GPIO # Change from RPi.GPIO to ASUS.GPIO.
# If you do the "python setup_RPi.py install" before, you can skip it.
GPIO.setmode(GPIO.ASUS) # Change from GPIO.BCM to GPIO.ASUS
# It's also support BCM mode in recent library, but it's annoying that I have to check the pin location in RPi first.
# So I suggest to use ASUS or BOARD mode; see below table to translate pin location to value.
GPIO_PIN = 163 # The value depends on what gpio mode you set and which physical pin you connected to signal pin.
# For an example, 163 means pin number 18 in Tinker board.
You can reference to below table for the value of GPIO pin in different modes:
Now it's done for this section, is it not easy? After modifying, you can run the sample code as like:
$ python SensorTest_RPi.py
b. with ADC (Analog Digital Converter)
This section introduces those sensors output 1 (or 2) analog signals that need to connect to an ADC for reading values.
Initially, the kit provided an ADC(KY-053), ADS1X15, for development, but due to out of stock, we use another one, MCP3008.
To replace ADS1X15, MCP3008 use SPI interface; please reference to below pin connection figure from MCP3008 to Tinker Board:
The A0/A1 are analog signals input, connect sensor's singal to A0 (and A1, if any)
Moreover, I provide a simple python class, mcp3008.py, by referencing to https://www.raspberrypi-spy.co.uk/2013/10/analogue-sensors-on-the-raspberry-pi-using-an-mcp3008/
Please see the ADC_test.py (under folder 53 in attachment) for the using examples.
Now, we can start porting the sensor with ADC, I will show the steps with sample code of KY-018 Fotowiderstand Modul
Please follow below steps: (remove red and add green words)
from Adafruit_ADS1x15 import ADS1x15 # import new class mcp3008
import mcp3008
adc = ADS1x15(ic=ADS1115) # open adc
adc = mcp3008.MCP3008()
voltage = adc.readADCSingleEnded(adc_channel, gain, sps) # read adc value
voltage = adc.ConvertVolts(adc.ReadChannel(channel = adc_channel))
Then, run the modified code as below:
$ python RPi_Single_Analog_Sensor.py
The red rectangle indicates that I use flashlight on the sensor.
c. with Level shifter
There is only one sensor, KY-050 Ultraschallabstandssensor, depends on level shifter (KY-051).
The level shifter is HW only, you don't have to use any code/program to control it, it will work automatically.
For Ultraschallabstandssensor, after HW connection is done, the left work is just to set gpio.
You can reference to section a. or the modified sample code in attachment (under folder 50) .
d. others
Those sensors in this section depend on different functions/libs, I will introduce them one-by-one.
- KY-001 Temperatur Sensor Modul
Enable one-wire in kernel then you can run the sample code, reference to the DS18B20 for more details.
- KY-015 Kombi-SensorTemperatur+Feuchtigkeit
And the question is the library, Adafruit_Python_DHT, does not support Tinker board.
Thus, we use another library, dht11.py instead, you can go the this https://github.com/szazo/DHT11_Python to see the original provider.
import dht11 # import library
import Adafruit_DHT
DHTSensor = dht11.DHT11(pin=GPIO_Pin) # open DHT11
DHTSensor = Adafruit_DHT.DHT11
result = DHTSensor.read() # the values stored in result.humidity & result.temperature
Luftfeuchte, Temperatur = Adafruit_DHT.read_retry(DHTSensor, GPIO_Pin)And you can find the modified code in attachment (under folder 15).
- KY-022 Infrarot Receiver Modul
For adding IR function, first we have to enable the related config in kernel.
CONFIG_RC_CORE=y CONFIG_LIRC=y CONFIG_IR_LIRC_CODEC=y CONFIG_MEDIA_RC_SUPPORT=y
Second, copy the module files into Tinker Board: (find the files in attachment under folder 22)
<prestyle="background: rgb(238, 238, 238); border: 1px solid rgb(204, 204, 204); padding: 5px 10px; margin-left: 40px;"> $ cp lirc_rpi.ko /home/linaro $ cp lirc-rpi.dtbo /boot/overlays
Then, set to load the dtbo file, add below into the end of /boot/hw_intf.conf:
intf:dtoverlay=lirc-rpi
After rebooting, the LIRC kernel function is enabled.
$ sudo apt-get install lirc $ cp lirc_options.conf /etc/lirc $ reboot
After booting, follow below instructions to test the IR receiver:
$ insmod lirc_rpi.ko $ sudo /etc/init.d/lircd stop $ mode2 -d /dev/lirc0
Use any remote controler to transmit to the receiver, you will see the pulse and space time of the IR wave pattern.
You can use ctrl + c to exit.
Furthermore, you may want to recognize each key code from your remote controller.
Yor have to register your remote controller first.
$ sudo /etc/init.d/lircd stop $ irrecord -d /dev/lirc0 ~/testRC
Next, follow the program prompts to record your key code(s), after done, the new config file will store in your home directory.
$ cp ~/testRC.lircd.conf /etc/lirc/lircd.con
Then, start the lircd service and use irw to test your remote controller:
$ sudo /etc/init.d/lircd start $ irw
Now, you can use your remote controller points to the receiver and press the key you record before, it will show the key information as you define.
- KY-052 Drucksensor / Temperatursensor [BMP180]
We also use another library to instead, you can find more details in this https://github.com/ControlEverythingCommunity/BMP180
$ python BMP180.py
The result should be as following:
References
http://www.joy-it.net/en/sensor-kit-x40/
http://sensorkit.joy-it.net/index.php?title=Hauptseite
https://www.raspberrypi-spy.co.uk/2013/10/analogue-sensors-on-the-raspberry-pi-using-an-mcp3008/
https://github.com/szazo/DHT11_Python
https://github.com/bengtmartensson/lirc_rpi
https://github.com/ControlEverythingCommunity/BMP180