Class Gertboard


  • public class Gertboard
    extends Object

    The Gertboard has an on-board Digital to Analog (DAC) converter and an Analog to Digital (ADC) converters. These are connected via the SPI bus back to the Raspberry Pi host.

    Each of the DAC and ADC chips has 2 channels.

    The DAC has a resolution of 8 bits and produces an output voltage between 0 and 2.047 volts, the ADC has a resolution of 10 bits and can take an input voltage between 0 and 3.3 volts.

    Part of the wiringPi library includes code to setup and drive these chips in an easy to use manner.

    To use in a program, first you need to make sure that the 5 SPI jumpers are present on the Gertboard (there are 7 in total, 5 for the SPI, 2 to connect the serial to the ATmega), the photo below shows all 7 jumpers in-place.

    Before using the Pi4J library, you need to ensure that the Java VM in configured with access to the following system libraries:

    • pi4j
    • wiringPi
    This library depends on the wiringPi native system library. (developed by Gordon Henderson @ http://wiringpi.com/)

    Author:
    Robert Savage (http://www.savagehomeautomation.com)
    See Also:
    https://pi4j.com/, http://wiringpi.com/dev-lib/gertboard-analog/
    • Method Detail

      • gertboardAnalogWrite

        public static void gertboardAnalogWrite​(int chan,
                                                int value)

        This outputs the supplied value (0-255) to the given channel (0 or 1). The output voltage is:

         vOut = value / 255 * 2.047
         

        or to find the value for a given voltage:

         value = vOut / 2.047 * 255
         

        Parameters:
        chan - Analog channel to write to (0 or 1).
        value - The output value (0-255) supplied to the given channel (0 or 1).
        See Also:
        http://wiringpi.com/dev-lib/gertboard-analog/
      • gertboardAnalogRead

        public static int gertboardAnalogRead​(int chan)

        This returns a value from 0 to 1023 representing the value on the supplied channel (0 or 1). To convert this to a voltage, use the following formula:

         vIn = value * 3.3 / 1023
         

        Parameters:
        chan - Analog channel to read from (0 or 1).
        Returns:
        This returns a value from 0 to 1023 representing the value on the supplied channel (0 or 1).
        See Also:
        http://wiringpi.com/dev-lib/gertboard-analog/
      • gertboardSPISetup

        public static int gertboardSPISetup()

        This must be called to initialize the SPI bus to communicate with the Gertboards ADC and DAC chips. If the return value is smaller than 0 then an error occurred and errno will be set appropriately.

        Returns:
        If the return value is smaller than 0 then an error occurred and errno will be set appropriately. If the return value is '0' or greater than the call was successful.
        See Also:
        http://wiringpi.com/dev-lib/gertboard-analog/
      • gertboardAnalogSetup

        public static int gertboardAnalogSetup​(int pinBase)

        This setup routine allocates 2 pins and overlays the analog to digital input pins with the digital to analog output pins. So reading channel pinBase + 0 reads the first analog input channel (pin DA0 on the Gertboard), and writing pinBase + 0 outputs to the first analog output channel. (Pin AD0).

        Parameters:
        pinBase - pinBase is the base pin that you want the analog ports to appear as
        Returns:
        If the return value is smaller than 0 then an error occurred and errno will be set appropriately. If the return value is '0' or greater than the call was successful.
        See Also:
        http://wiringpi.com/dev-lib/gertboard-analog/