Sample Code

The source code contains some examples in the ./src/examples directory. The examples can be compiled once librpip has been installed. See the Install page for details.

Basic

The basic example simply initialises librpip and then prints out what hardware was found and its current config. Its is useful for testing peripheral configuration.

https://github.com/frasersdev/librpip/blob/master/src/examples/basic/basic.c

I2c-lcd

This example uses a Midas MCCOG22005A i2c lcd display. I like these displays for two reasons:

  1. they use i2c instead of a 4/8 bit parallel data connection. The timing nuances are pretty much all catered for by the lcd’s i2c module so implementation is much simpler in code (no more bodgy bit banging – in user space this can be bit of a problem as the cpu can go off to another thread without warning).
  2. They are a 3.3v module – so they are safe to read from.

They are the only lcd module I use with a rPi now.

https://github.com/frasersdev/librpip/blob/master/src/examples/i2c-lcd/i2c-lcd.c

I2c-mpu6500

The i2c-mpu6500 sample uses transactions to get accelerometer readings from a mpu6500 across the I2C bus. The datasheets for this device are here and here.

https://github.com/frasersdev/librpip/blob/master/src/examples/i2c-mpu6500/i2c-mpu6500.c

I2c-th02

The i2c-th02 sample uses transactions to get temperature and humidity readings from a h02 module. The datasheet is here. This device needs to be polled for output once the request has been made and so several transactions are used to read it.

https://github.com/frasersdev/librpip/blob/master/src/examples/i2c-th02/i2c-th02.c

Pwm

The pwm example configures both pwm devices, pwm0 brightens and dims a led, pwm1 moves a server between -45° & 45°.

https://github.com/frasersdev/librpip/blob/master/src/examples/pwm/pwm.c

Spi-mcp3002

The spi-3002 reads the voltage from channel 0 of a mcp3002 10bit A2D converter over the SPI bus. It also uses transactions to achieve this. The example prints out the sample (as an int), the sample covered to volts (assumes 3.3v) and average volts (to suppress any jitter).

https://github.com/frasersdev/librpip/blob/master/src/examples/spi-mcp300x/spi-mcp300x.c

Spi-mcp3202

The spi-3002 reads the voltage from channel 0 of a mcp3202 12bit A2D converter over the SPI bus. Again it uses transactions to achieve this. The example prints out the sample (as an int), the sample covered to volts (assumes 3.3v) and average volts (to suppress any jitter).

https://github.com/frasersdev/librpip/blob/master/src/examples/spi-mcp320x/spi-mcp320x.c