Expansion Boards
All of these devices act as Device Factories and should be accessed as such.
ADS112C04 ADC
16-Bit, 4 Channel, 2,000 samples per second delta-sigma ADC.
ADS1015 / ADS1115 ADC
Ads1x15 Javadoc.
Datasheets:
- ADS1015 - 3,300 samples per second, 12-Bit, 4 channel ADC Datasheet
- ADS1115 - 860 samples per second, 16-Bit, 4 channel ADC Datasheet
Microchip Analog to Digital Converters
Provides support for the following Microchip analog-to-digital converter devices:
- MCP300x: MCP3001, MCP3002, MCP3004, MCP3008
- MCP320x: MCP3201, MCP3202, MCP3204, MCP3208
- MCP330x: MCP3301, MCP3302, MCP3304
Usage example: An LDR controlled LED (using a 10kΩ resistor for the LDR and a 220Ω resistor for the LED):
Code for the above circuit is implemented in LdrControlledLed, the important bit:
try (McpAdc adc = new McpAdc(type, chipSelect); LDR ldr = new LDR(adc, pin, r1); PwmLed led = new PwmLed(ledPin)) {
// Detect variations of 5%, taking a reading every 20ms
ldr.addListener((event) -> led.setValue(1-event.getUnscaledValue()), .05f, 20);
Logger.debug("Sleeping for 20s");
SleepUtil.sleepSeconds(20);
}
McpAdc Javadoc.
Microchip MCP23xxx GPIO Expansion Board
Supports MCP23008, MCP23017 and MCP23S17.
An example circuit for controlling an LED with a button, all connected via an MCP23017:
Code for the above circuit is implemented in MCP23017Test, the important bit:
try (MCP23017 mcp23017 = new MCP23017(intAPin, intBPin);
Button button = new Button(mcp23017, inputPin, GpioPullUpDown.PULL_UP);
LED led = new LED(mcp23017, outputPin)) {
led.on();
SleepUtil.sleepSeconds(1);
led.off();
SleepUtil.sleepSeconds(1);
led.blink(0.5f, 0.5f, 10, false);
button.whenPressed(nanoTime -> led.on());
button.whenReleased(nanoTime -> led.off());
Logger.debug("Waiting for 10s - *** Press the button connected to MCP23017 pin {} ***",
Integer.valueOf(inputPin));
SleepUtil.sleepSeconds(10);
button.whenPressed(null);
button.whenReleased(null);
}
Implementations:
PCA9685 PWM / Servo Driver
Provides support for the PCA9685 12-bit 16-channel PWM driver as used by the Adafruit PWM Servo Driver. Implements PwmOutputDeviceFactoryInterface hence can be passed into the constructor of PWM output devices.
Usage example:
float delay = 0.5f;
try (PwmOutputDeviceFactoryInterface df = new PCA9685(); PwmLed led = new PwmLed(df, pin)) {
led.setValue(.25f);
SleepUtil.sleepSeconds(delay);
led.toggle();
SleepUtil.sleepSeconds(delay);
led.setValue(.5f);
SleepUtil.sleepSeconds(delay);
led.blink(0.5f, 0.5f, 5, false);
led.pulse(1, 50, 5, false);
} catch (RuntimeIOException e) {
Logger.error(e, "Error: {}", e);
}
PCF8574 GPIO Expansion Board
Support for the PCF8574 8-Bit I/O Expander.
PCF8574 Javadoc.
PCF8591 ADC / DAC
Support for the PCF8591 8-bit A/D and D/A converter.
PCF8591 Javadoc.
Picon Zero Intelligent Robotics Controller
Output Shift Registers
E.g. SN74HC595. See OutputShiftRegisterDeviceFactory.