In the following example, using GPIO, you can create a component (DigitalIn-RTC, DigitalOut-RTC) that detects the ON/OFF of the switch and light up the LED and understand the use of GPIO which is the feature of Raspberry Pi I will deepen. The source code of the sample component can be downloaded from the following.
Raspberry Pi has a GPIO terminal, which allows you to use various external devices.
The pin assignment of the GPIO that is attached to the Raspberry Pi main unit is shown below.
When using GPIO, pay attention to the position of each pin, especially if using 5V terminal, mistake in wiring may damage the Raspberry Pi main unit and SD card, so be careful enough please.
Create a circuit that lights the LED and a circuit that detects ON/OFF of the switch. If you have a breadboard etc, you can easily build a circuit, but since there are few parts even if it is not, you can easily form a circuit by soldering lead wires etc. Below is a list of necessary parts.
Bill of Material | |
LED circuit | |
LED | 1piece |
Resistance | 100Ω(brown black tea gold) - 330Ω(orange orange tea gold) |
Lead wire | Somewhat |
Switch LED circuit | |
LED | 1piece |
Resistance | 330Ω(Orange Orange Tea) - 1kΩ(Brown Black Red Gold) |
Lead wire | Somewhat |
If there is only one Raspberry Pi, connect the following LED and switch circuit to the same Raspberry Pi. If there are two Raspberry Pi, it may be interesting to install LEDs and switches on each Raspberry Pi.
DigitalIn-RTC is a component that outputs the bool value (true/false) input to the data port to the specified GPIO port. In order to observe the output value of the GPIO port, connect the LED and resistor to the Ground pin and GPIO 18 pin and create a circuit as shown below.
This is the case when creating this circuit with breadboard.
DigitalOut-RTC is a component that outputs the bool value (true/false) input to the GPIO port from the data port. In order to input the value to GPIO, connect a resistor and a switch to Ground, 3.3V Power, GPIO 17 and create a circuit as shown below.
This is the case when creating this circuit with breadboard.
Download the source code to Raspberry Pi from below and compile the DigitalIn-RTC/DigitalOut-RTC component.
$ unzip RaspberryPi_sample.zip $ cd RaspberryPi_sample/DigitalInRPI/ $ vi CMakeLists.txt
Now rewrite CMakeLists.txt and set it to suppress document generation.
option(BUILD_DOCUMENTATION "Build the documentation" OFF) ↓ option(BUILD_DOCUMENTATION "Build the documentation" ON) $ mkdir build $ cd build $ cmake .. -- The C compiler identification is GNU 4.6.3 -- The CXX compiler identification is GNU 4.6.3 : Omission -- Configuring done -- Generating done -- Build files have been written to: /home/pi/RaspberryPi_sample/DigitalInRPI/build
If OpenRTM-aist is correctly installed, configure will terminate without problems. If an error occurs due to lack of OpenRTM or coil, please confirm that OpenRTM-aist (C++ version) is correctly installed (dpkg -l |grep openrtm etc.).
$ make : Omission Scanning dependencies of target DigitalInComp [ 66%] Building CXX object src/CMakeFiles/DigitalInComp.dir/DigitalInComp.cpp.o [100%] Building CXX object src/CMakeFiles/DigitalInComp.dir/DigitalIn.cpp.o Linking CXX executable DigitalInComp [100%] Built target DigitalInComp $
The compiled component DigitalInComp is under src.
$ ls src/ CMakeFiles cmake_install.cmake DigitalInComp DigitalIn.so Makefile
Compile like DigitalIn-RTC.
$ cd RaspberryPi_sample/DigitalOutRPI/ $ mkdir build $ vi CMakeLists.txt
Now rewrite CMakeLists.txt and set it to suppress document generation.
option(BUILD_DOCUMENTATION "Build the documentation" OFF) ↓ option(BUILD_DOCUMENTATION "Build the documentation" ON) $ mkdir build $ cd build $ cmake .. -- The C compiler identification is GNU 4.6.3 -- The CXX compiler identification is GNU 4.6.3 : Omission -- Configuring done -- Generating done -- Build files have been written to: /home/pi/RaspberryPi_sample/DigitalOutRPI/build
$ make -- OpenRTMConfig.cmake found. -- Configrued by configuration mode. : Omission Scanning dependencies of target DigitalOutComp [ 66%] Building CXX object src/CMakeFiles/DigitalOutComp.dir/DigitalOutComp.cpp.o [100%] Building CXX object src/CMakeFiles/DigitalOutComp.dir/DigitalOut.cpp.o Linking CXX executable DigitalOutComp [100%] Built target DigitalOutComp $
The compiled component DigitalOutComp is under src.
$ ls src/ CMakeFiles cmake_install.cmake DigitalOutComp DigitalOut.so Makefile
Once each RTC has been successfully compiled, start up each RTC after launching NameServer.
$ rtm-naming $ sudo /home/pi/RaspberryPi_sample/DigitalOutRPI/build/src/DigitalOutComp & $ sudo /home/pi/RaspberryPi_sample/DigitalInRPI/build/src/DigitalInComp &
&color(red){Since the sample component uses GPIO, it must be executed with root authority.} &color(red){※サンプルコンポーネントは GPIO を利用するので root 権限で実行する必要があります。}
Launch RTSystemEditor on PC and connect to NameServewr on Raspberry Pi. After placing each RTC, connecting between the ports, activate.
When each RTC starts normally, the LED turns on/off according to the status of the takt switch.