C++ API (Arduino and Particle)

BlankSlateModulo

class BlankSlateModulo

A general purpose I/O module for digital input, digital output, analog input, and PWM output.

Public Functions

bool getDigitalInput(uint8_t pin)

Disables the output on the specified pin and returns the pin’s value.

uint8_t getDigitalInputs()

Reads the digital inputs from all 8 pins. Does not enable/disable outputs on any pins.

float getAnalogInput(uint8_t pin)

Disables the output on the specified pin and performs an analog read.

void setDirection(uint8_t pin, bool output)

Sets the pin direction to either output or input.

void setDirections(uint8_t outputs)

Sets the pin directions for all 8 pins simultaneously.

void setDigitalOutput(uint8_t pin, bool value)

Enables the output and sets the output value on the specified pin.

bool setDigitalOutputs(uint8_t values)

Set the digital outputs on all 8 pins. Does not enable or disable outputs on any pins.

void setPWMValue(uint8_t pin, float value)

Enable the output and set the PWM duty cycle on the specified pin.

Pins 0-4 have hardware PWM support. Pins 5-7 only have software PWM which has more jitter, especially at high frequencies.

void setPullup(uint8_t pin, bool enable)

Sets whether a pullup is enabled on the specified pin.

void setPullups(uint8_t pullups)

Set whether the pullup is enabled on all 8 pins.

void setPWMFrequency(uint8_t pin, uint16_t value)

Set the frequency for PWM signals on the specified pin.

uint8_t getAddress()

Return the i2c address, or 0xFF if no device could be found.

uint16_t getDeviceID()

Return the device ID, or 0xFFFF if no device could be found.

void setDeviceID(uint16_t deviceID)

Set the ID of the modulo that this object should connect to.

DisplayModulo

class DisplayModulo

A full color OLED display.

Public Types

typedef void( DisplayModulo::EventCallback) (DisplayModulo &module, int button)

A callback function.

Public Functions

int width() const

Return the width of the display in pixels.

int height() const

Return the height of the display in pixels.

DisplayModulo()

Use the first DisplayModulo that’s not already in use.

DisplayModulo(uint16_t deviceID)

Use the DisplayModulo with the specified deviceID.

void clear()

Fill the screen with black, set the line, fill, and text colors to white, and return the cursor to (0,0)

void setCurrent(float current)

Set the display’s master current.

Higher current values produce a brighter, more vivid image but may increase image burn-in and audible noise from the OLED driver. The default is .75.

void setContrast(float r, float g, float b)

Set the per channel contrast values, which affect image brightness and color balance.

The default is (.93, 0.555, 1.0).

void setLineColor(float r, float g, float b, float a)

Set the current line color.

void setFillColor(float r, float g, float b, float a)

Set the current fill color.

void setTextColor(float r, float g, float b, float a)

Set the current text color.

void setTextSize(uint8_t size)

Set the text size.

This is a multiplier of the base text size, which is 8px high.

void fillScreen(float r, float g, float b)

Fill the screen.

void setCursor(int x, int y)

Set the cursor position, which is where the next text will be drawn.

void drawLine(int x0, int y0, int x1, int y1)

Draw a line segment from (x0,y0) to (x1,y1)

void drawRect(int x, int y, int w, int h, int radius)

Draw a rectangle with the upper left corner at (x,y) and the specified width, height, and corner radius.

void drawCircle(int x, int y, int r)

Draw a circle centered at (x,y) with the specified radius.

void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2)

Draw a triangle.

size_t write(uint8_t c)

Write a single charachter c.

Note that the Print methods (print(...), println(...), etc.) are also available.

void refresh(bool flip)

Display the results of all previous drawing commands.

Note that after calling refresh, the next drawing operation will block until the frame has been drawn.

bool isComplete()

Return whether all previous drawing operations have been completed.

bool isEmpty()

Return whether the queue of drawing operations is empty.

If the display is still refreshing, it may be empty but not complete.

bool getButton(int button)

Return whether the specified button is currently pressed.

uint8_t getButtons()

Return the state of all three buttons, one in each bit.

void drawSplashScreen()

Draw the Modulo logo and the word ‘MODULO’ on a purple background.

void drawLogo(int x, int y, int width, int height)

Draw the Modulo logo.

void setButtonPressCallback(EventCallback *handler)

Set the function that should be called when a button is pressed.

void setButtonReleaseCallback(EventCallback *handler)

Set the function that should be called when a button is released.

uint8_t getAddress()

Return the i2c address, or 0xFF if no device could be found.

uint16_t getDeviceID()

Return the device ID, or 0xFFFF if no device could be found.

void setDeviceID(uint16_t deviceID)

Set the ID of the modulo that this object should connect to.

IRRemoteModulo

class IRRemoteModulo

Infrared remote control transmitter and receiver.

This class supports encoding and decoding many of the most popular IR remote control protocols, including NEC, Sony, JVC, Panasonic, and LG.

If a particular remote is not supported you can still receive raw IR data (a sequence of pulse lengths). If you share the raw data for a particular unsupported remote on the forum ( community.modulo.co ) we may be able to add support for it. You can capture the raw data using the IRTutorial example sketch.

Public Types

typedef void(* IRRemoteModulo::ReceiveCallback) (int8_t protocol, uint32_t data, uint16_t *rawData, uint8_t rawLen)

The callback function type.

Public Functions

IRRemoteModulo()

Use the first IRRemoteModulo that’s not already in use.

IRRemoteModulo(uint16_t deviceID)

Use the IRRemoteModulo with the specified deviceID.

void send(int8_t protocol, uint32_t data)

Send an IR code with the specified protocol number and data bits.

void sendRaw(uint8_t *data, uint8_t len)

Send raw data.

Each byte is the number of 50us ticks that the output should be on or off. The first byte is an off period.

void setBreakLength(uint16_t len)

Set the no signal time that’s required before the receiver considers a transmission complete.

void setReceiveCallback(ReceiveCallback callback)

Set the function that should be called when data is received.

The callback will receive the decoded protocol and data, along with an array containing the raw pulse widths.

uint8_t getAddress()

Return the i2c address, or 0xFF if no device could be found.

uint16_t getDeviceID()

Return the device ID, or 0xFFFF if no device could be found.

void setDeviceID(uint16_t deviceID)

Set the ID of the modulo that this object should connect to.

JoystickModulo

class JoystickModulo

Public Types

typedef void( JoystickModulo::EventCallback) (JoystickModulo &module)

A callback function.

Public Functions

JoystickModulo()

Use the first JoystickModulo module that’s not already in use.

JoystickModulo(uint16_t deviceID)

Use the JoystickModulo with the provided deviceID.

bool getButton()

Return whether the button is currently pressed.

float getHPos()

Return the horizontal position of the joystick. (between -1 and 1)

float getVPos()

Return the vertical position of the joystick. (between -1 and 1)

void setButtonPressCallback(EventCallback *handler)

Set the function that should be called when the button is pressed.

void setButtonReleaseCallback(EventCallback *handler)

Set the function that should be called when the button is released.

void setPositionChangeCallback(EventCallback *handler)

Set the function that should be called when the position changes.

uint8_t getAddress()

Return the i2c address, or 0xFF if no device could be found.

uint16_t getDeviceID()

Return the device ID, or 0xFFFF if no device could be found.

void setDeviceID(uint16_t deviceID)

Set the ID of the modulo that this object should connect to.

KnobModulo

class KnobModulo

An RGB illuminated knob and push button.

Public Types

typedef void( KnobModulo::EventCallback) (KnobModulo &module)

A callback function.

Public Functions

KnobModulo()

Use the first KnobModulo that’s not already in use.

KnobModulo(uint16_t deviceID)

Use the knob with the specified deviceID.

bool setColor(float r, float g, float b)

Set the color of the knob’s LED in rgb.

bool setHSV(float h, float s, float v)

Set the color of the knob’s LED in hsv.

bool getButton()

Return whether the knob is currently being pressed.

int16_t getAngle()

Return the angle of the knob in degrees.

int16_t getPosition()

Return the position of the knob in clicks (24 per revolution).

void setButtonPressCallback(EventCallback *handler)

Set the function that should be called when the button is pressed.

void setButtonReleaseCallback(EventCallback *handler)

Set the function that should be called when the button is released.

void setPositionChangeCallback(EventCallback *handler)

Set the function that should be called when the position changes.

uint8_t getAddress()

Return the i2c address, or 0xFF if no device could be found.

uint16_t getDeviceID()

Return the device ID, or 0xFFFF if no device could be found.

void setDeviceID(uint16_t deviceID)

Set the ID of the modulo that this object should connect to.

MotorDriverModulo

class MotorDriverModulo

A driver for DC Motors, Stepper Motor, and other high current devices.

Public Types

typedef void( MotorDriverModulo::EventCallback) (MotorDriverModulo &module)

A callback function.

Public Functions

MotorDriverModulo()

Use the first MotorDriverModulo that’s not already in use.

MotorDriverModulo(uint16_t deviceID)

Use the Motor with the provided deviceID.

void setMotorA(float amount)

Set the motor output A to the specified amount, between -1 and 1.

Changes the mode to ModeDC if it’s not already.

void setMotorB(float amount)

Set the motor output B to the specified amount, between -1 and 1.

Changes the mode to ModeDC if it’s not already.

void setMode(Mode mode)

Set the driver mode.

void setCurrentLimit(float limit)

Set the driver curren limit (between 0 and 1).

void setPWMFrequency(uint16_t frequency)

Set the motor driver PWM frequency.

void setStepperSpeed(float stepsPerSecond)

Set the stepper speed in whole steps per second.

void setStepperRate(uint32_t usPerStep)

Set the number of microseconds to take between each whole step.

void setStepperResolution(int microsteps, uint16_t minMicrostepDuration)

Set the number of microsteps to take between each whole step.

It can be 1, 2, 4, 8, 16, 32, 64, 128, or 256.

If the duration of a microstep (in microseconds) would be less than minMicrostepDuration, then the number of microsteps is decreased automatically. This helps to avoid skipping steps when the rate is higher than the motor or driver can handle.

void setStepperTarget(int32_t targetPosition)

Set the stepper target position.

The target position is in 1/256 of a whole step. (So setting the target to 256 will take as many steps/ microsteps as are necessary to move to the position that is 1 whole step from the starting position.)

int32_t getStepperPosition()

Return the current position of the stepper motor in 1/256 increments of wholes steps.

bool hasFault()

Return whether a fault condition (such as a short between motor terminals, over current shutdown, or over temperature shutdown) is currently present.

void setPositionReachedCallback(EventCallback *handler)

Set the function that should be called when the stepper target position is reached.

void setFaultChangedCallback(EventCallback *callback)

Set the function that should be called when a fault occurs or is cleared.

void setChannel(uint8_t channel, float amount)

Set the an input to te DRV8848 driver IC to a particular PWM value, between 0 and 1.

Changes the mode to ModeDC if it’s not already.

This is a low level function and may not do what you expect. If you are trying to drive single-ended loads, use setOutput instead.

uint8_t getAddress()

Return the i2c address, or 0xFF if no device could be found.

uint16_t getDeviceID()

Return the device ID, or 0xFFFF if no device could be found.

void setDeviceID(uint16_t deviceID)

Set the ID of the modulo that this object should connect to.

TemperatureProbeModulo

class TemperatureProbeModulo

A module for reading the temperature from a thermocouple.

Public Types

typedef void( TemperatureProbeModulo::TemperatureChangeCallback) (TemperatureProbeModulo &module)

A callback function.

Public Functions

float getTemperatureC()

Return the temperature of the probe in celsius.

float getTemperatureF()

Return the temperature of the probe in fahrenheit.

bool isValid()

Return whether temperature probe is connected and has a valid value.

void setTemperatureChangeCallback(TemperatureChangeCallback *handler)

Set the function that should be called when the button is pressed.

uint8_t getAddress()

Return the i2c address, or 0xFF if no device could be found.

uint16_t getDeviceID()

Return the device ID, or 0xFFFF if no device could be found.

void setDeviceID(uint16_t deviceID)

Set the ID of the modulo that this object should connect to.

Modulo

class _Modulo

Public Static Functions

void loop()

loop should be called from the sketch loop function.

void setup()

setup is called automatically

void globalReset()

Reset all devices on the bus to their power-up state.

void exitBootloader()

Tell devices that are running their bootloaders to begin normal operation.

uint16_t getNextDeviceID(uint16_t lastDeviceID)

Search the bus for the device with the lowest deviceID that is greater than or equal to the one provided.

uint16_t getNextUnassignedDeviceID(uint16_t lastDeviceID)

Search the bus for the device with the lowest deviceID that is greater than or equal to the one provided.

bool setAddress(uint16_t deviceID, uint8_t address)

Set a device’s I2C address.

The address is not persistant. It will be cleared when the modulo is reset or powered off.

uint8_t getAddress(uint16_t deviceID)

Get a device’s I2C address, if it currently has one.

bool getDeviceType(uint16_t deviceID, char *deviceType, uint8_t maxLen)

Get a device’s deviceType.

bool setStatus(uint16_t deviceID, ModuloStatus status)

Set a device’s status LED to Off, On, or Blinking.

bool setDeviceID(uint16_t deviceID, uint16_t newID)

Permanently change a device’s deviceID.

bool transfer(uint8_t address, uint8_t command, uint8_t *sendData, uint8_t sendLen, uint8_t *receiveData, uint8_t receiveLen, bool receiveString)

Perform a data transfer on the modulo bus.

This is normally only used internally within the various Modulo classes.