1 ## Build IoT.js with Raspberry Pi 2
3 IoT.js supports two build types:
5 1. Build on your desktop. We support Linux(Ubuntu) and macOS. - Cross compile
6 2. Build on Raspberry Pi 2.
8 ### Setting Raspberry Pi
10 IoT.js officially supports Raspbian. For more information, please visit [the official site](https://www.raspberrypi.org/downloads/raspbian/).
12 #### Enable the I2C interface
14 To use I2C module, the I2C interface must be enabled.
16 From the command line type:
20 This will launch raspi-config utility.
21 * Select "9 Advanced Options"
24 The screen will ask you to enable I2C interface.
27 * Select "Finish" to return to the command line.
29 Reboot your Raspberry Pi.
31 #### Enable the PWM interface
33 Raspberry Pi2 has two PWM outputs on the following pins.
35 | PWM Number | GPIO PIN(FUNC) |
37 | PWM0 | GPIO12(4), GPIO18(2) |
38 | PWM1 | GPIO13(4), GPIO19(2) |
40 To use PWM module, you must add PWM overlays in `/boot/config.txt` file.
42 For example, to get a single PWM on GPIO18, add overlays like below.
44 dtoverlay=pwm,pin=18,func=2
47 For example, to get multi PWM on GPIO18 and GPIO19, add overlays like below.
49 dtoverlay=pwm-2chan,pin=18,func=2,pin2=19,func2=2
52 For more information about overlays, refer to [README](https://github.com/raspberrypi/linux/blob/rpi-4.9.y/arch/arm/boot/dts/overlays/README).
54 * Note that it is necessary to have root privileges in order to run PWM module.
56 #### Enable the UART interface
58 To use UART module, the UART interface must be enabled.
60 In `/boot/config.txt` file, change the value of enable_uart from 0 to 1.
65 To disable the serial console, edit the file `/boot/cmdline.txt`.
66 remove the word phase ```"console=serial0,115200"``` or ```"console=ttyAMA0,115200"```
68 To enable the serial console, edit the file `/boot/cmdline.txt`.
69 add the word phase ```"console=serial0,115200"``` or ```"console=ttyAMA0,115200"```
71 Reboot your Raspberry Pi.
73 * Note for Raspberry Pi 3 : You should use /dev/ttyS0 instead of /dev/ttyAMA0 in RPI3.
75 ### Build IoT.js on your desktop.
80 Install arm linux cross compiler.
83 sudo apt-get install gcc-arm-linux-gnueabihf
88 Install arm linux cross compiler via [this site](http://www.welzels.de/blog/en/arm-cross-compiling-with-mac-os-x/).
90 The default location for arm linux compiler toolchain is **"/usr/local/linaro/arm-linux-gnueabihf-raspbian"**.
92 Then you need to locate c_compiler.
93 In **"./cmake/config/arm-linux.cmake"**,
95 SET(EXTERNAL_CMAKE_C_COMPILER
96 /usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
98 In **"./deps/libtuv/cmake/config/config_arm-linux.cmake"**,
101 /usr/local/linaro/arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
104 #### Build IoT.js (Cross compile)
105 Give `target-arch`, `target-os` and `target-board` options to the script named 'build.py', then the script do the rest for you.
108 ./tools/build.py --buildtype=[release|debug] --target-arch=arm \
109 --target-os=linux --target-board=rpi2
112 #### Running in Raspberry Pi 2
114 This script gives you `build/arm-linux/release/iotjs/iotjs` or `build/arm-linux/debug/iotjs/iotjs`.
115 Copy this binary with your favorite tool or `scp` like below.
118 scp build/arm-linux/release/iotjs/iotjs pi@(your RPi2 IP):/home/pi/.
121 Lastly, open a shell and run with your test program.
124 ssh pi@(your RPi2 IP)
125 ./iotjs (your test program)
128 ### Build IoT.js on Raspberry Pi 2
134 sudo apt-get install cmake
138 Executing below command will build IoT.js and run our testsuite.
141 ./tools/build.py --target-board=rpi2