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:
This library depends on the wiringPi native system library. (developed by Gordon Henderson @ http://wiringpi.com/)
Modifier and Type | Field and Description |
---|---|
static int |
SPI_A2D |
static int |
SPI_ADC_SPEED |
static int |
SPI_D2A |
static int |
SPI_DAC_SPEED |
Modifier and Type | Method and Description |
---|---|
static int |
gertboardAnalogRead(int chan)
This returns a value from 0 to 1023 representing the value on the supplied channel (0 or 1).
|
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.
|
static void |
gertboardAnalogWrite(int chan,
int value)
This outputs the supplied value (0-255) to the given channel (0 or 1).
|
static int |
gertboardSPISetup()
This must be called to initialize the SPI bus to communicate with the Gertboards ADC and DAC
chips.
|
public static final int SPI_ADC_SPEED
public static final int SPI_DAC_SPEED
public static final int SPI_A2D
public static final int SPI_D2A
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.047or to find the value for a given voltage:
value = vOut / 2.047 * 255
chan
- Analog channel to write to (0 or 1).value
- The output value (0-255) supplied to the given channel (0 or 1).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
chan
- Analog channel to read from (0 or 1).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 < 0 then an error occurred and errno will be set appropriately.
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).
pinBase
- pinBase is the base pin that you want the analog ports to appear asCopyright © 2012–2021 Pi4J. All rights reserved.