|
| 1 | +--- |
| 2 | +title: OPAMP Library API Documentation |
| 3 | +description: 'Learn how to use the on-board OPAMP on the Arduino R4 boards.' |
| 4 | +author: Pedro Sousa Lima |
| 5 | +tags: [AMPOP, OPAMP] |
| 6 | +--- |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +The OPAMP library allows control over the on-board OP AMP encontered on Arduino R4 boards. |
| 11 | +More information on implementation can be found [here](https://docs.arduino.cc/tutorials/uno-r4-wifi/opamp/). |
| 12 | + |
| 13 | +## Supported Boards |
| 14 | + |
| 15 | +- Arduino UNO R4 WiFi |
| 16 | +- Arduino UNO R4 Minima |
| 17 | + |
| 18 | +## Functions |
| 19 | + |
| 20 | +### `bool begin(OpampSpeedMode)` |
| 21 | + |
| 22 | +Initializes the default op-amp channel. You can specify the speed mode as either high-speed or low-speed. If no speed mode is specified, the op-amp will default to high-speed mode. |
| 23 | + |
| 24 | +**Parameters** |
| 25 | + |
| 26 | + `speed` (optional): The speed mode of the op-amp. Options are: |
| 27 | + - `OPAMP_SPEED_LOWSPEED` |
| 28 | + - `OPAMP_SPEED_HIGHSPEED` (default) |
| 29 | + |
| 30 | +**Returns** |
| 31 | + |
| 32 | +- `true` if initialization was successful. |
| 33 | +- `false` if initialization failed. |
| 34 | + |
| 35 | +### `bool isRunning(uint8_t channel)` |
| 36 | +Checks whether a specific op-amp channel is currently running. |
| 37 | + |
| 38 | +**Parameters** |
| 39 | +- `channel`: The channel number to check (0 to 3). |
| 40 | + |
| 41 | +**Returns** |
| 42 | +- `true` if the channel is active. |
| 43 | +- `false` if the channel is inactive. |
| 44 | + |
| 45 | +### `void end()` |
| 46 | +Deactivates all op-amp channels. |
| 47 | + |
| 48 | +### `void end(uint8_t channel_mask)` |
| 49 | +Deactivates specified op-amp channels. |
| 50 | + |
| 51 | +**Parameters** |
| 52 | +- `channel_mask`: A bitmask specifying which channels to deactivate. |
| 53 | + |
| 54 | +## Example Usage |
| 55 | +Here is an example demonstrating how to initialize and check the status of the op-amp: |
| 56 | + |
| 57 | +```cpp |
| 58 | +#include <OPAMP.h> |
| 59 | + |
| 60 | +void setup() { |
| 61 | + Serial.begin(9600); |
| 62 | + delay(2000); // serial monitor delay |
| 63 | + |
| 64 | + // Activate OPAMP on the default channel (channel 0) |
| 65 | + // Plus: Analog A1 |
| 66 | + // Minus: Analog A2 |
| 67 | + // Output: Analog A3 |
| 68 | + if (!OPAMP.begin(OPAMP_SPEED_HIGHSPEED)) { |
| 69 | + Serial.println("Failed to start OPAMP!"); |
| 70 | + } |
| 71 | + |
| 72 | + bool const isRunning = OPAMP.isRunning(0); |
| 73 | + if (isRunning) { |
| 74 | + Serial.println("OPAMP running on channel 0!"); |
| 75 | + } else { |
| 76 | + Serial.println("OPAMP channel 0 is not running!"); |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +void loop() { |
| 81 | + delay(1000); // do nothing |
| 82 | +} |
| 83 | +``` |
0 commit comments