Programming embedded system is very often  to involve interfacing sensors. Sensors are commonly connected to GPIO, I2C and SPI buses. Developers must fully understand the I/O pins assignment on the board to identify those buses for a connection. Followings will be useful for developers to understand programming these buses, thus to control the sensors on LInux kernel.

  1. I/O Pins
    • Raspberry Pi
    • WRTnode
    • LAN connection(JP4) between two WRTnodes
      	pin 23(RN) <---> pin 26(TN)
      	pin 24(RP) <---> pin 25(TP)
      	
  2. Linux GPIO programming
    • Access GPIO from Linux user space
    • HC-SR04 ultrasonic distance sensor
      • to control ultrasonic distance sensor (HC-SR04) can be done with GPIO. To start the measurement of distance, pin 2 (TRIG) of the module should receive a high pulse for at least ten microseconds. The pulse will initiate the module to transmit eight cycles of ultrasonic burst at 40 kHz and wait for the reflected ultrasonic burst. When the sensor detects the reflected ultrasonic burst, it sets pin 3 (ECHO) to high state. Duration of the reflected pulse depends on the distance from the obstacle, which can be easily calculated as: Distance (in centimeters) = T/58 where, T = Width of pulse at ECHO pin in microseconds
      • an example - although it is talking about python programming, the concept is same to C/C++.
      • a demo
  3. Linux SPI Programming
  4. Linux I2C Programming
  5. Using I2C from userspace in Linux
  6. Raspberry Pi SPI/I2C/1Wire/GPIO Topics
  7. Raspberry Pi using C++ (i2cdev)
  8. Using GPIOs to generate PWM for servo control
    how to use - write 500000-2500000ns(0-180 degree) to /sys/class/pwm/gpio_pwm:19/duty_ns, where 19 is gpio number.
    • On WRTnode 
      Assignement of GPIOs for PWM output is as followings
          " 0", /* JP3 pin 17 */
          "19", /* JP3 pin 18 */
          "18", /* JP3 pin 19 */
          "17", /* JP3 pin 20 */
          "40", /* JP3 pin 22 */
          "41", /* JP3 pin 23 */
          "42", /* JP3 pin 24 */
          "43", /* JP3 pin 25 */
          "44"  /* JP3 pin 26 */
      		
    • On Raspberry Pi 
      Assignement of GPIOs(BCM) for PWM output is as followings, see this diagram for the pins used
      	4,17,18,27,22,23,24,10,9,25,11,8