2021-03-12 11:04:02 +00:00
# Pico Explorer Base <!-- omit in toc -->
2021-01-27 09:36:08 +00:00
2021-03-12 11:04:02 +00:00
Pico Explorer Base straps a whole host of physical computing goodies to your Pico - a vibrant 1.14" (240x240) IPS LCD screen, four switches, a piezo buzzer/speaker and a DRV8833 motor driver, as well as handy accessible general purpose inputs and outputs and a built in breadboard.
2021-01-27 09:36:08 +00:00
We've included helper functions to handle every aspect of drawing to the screen and interfacing with the buttons, piezo and motor driver. [See the library reference ](#reference ) for details.
- [Example Program ](#example-program )
- [Reference ](#reference )
- [PicoGraphics ](#picographics )
- [Constants ](#constants )
- [Buttons ](#buttons )
- [ADC Channels ](#adc-channels )
- [GPIO ](#gpio )
2022-06-13 14:43:08 +01:00
- [Motors ](#motors )
2021-01-27 09:36:08 +00:00
- [Functions ](#functions )
2022-06-13 14:43:08 +01:00
- [Motors ](#motors-1 )
- [Analog ](#analog )
- [Buzzer ](#buzzer )
- [Buttons ](#buttons-1 )
- [ST7789 ](#st7789 )
2021-01-27 09:36:08 +00:00
## Example Program
2022-06-13 14:43:08 +01:00
The following example shows how to set up all of Pico Explorers functions:
2021-01-27 09:36:08 +00:00
```c++
#include "pico_explorer.hpp"
2022-06-13 14:43:08 +01:00
#include "drivers/st7789/st7789.hpp"
#include "libraries/pico_graphics/pico_graphics.hpp"
#include "button.hpp"
#include "motor.hpp"
#include "analog.hpp"
2021-01-27 09:36:08 +00:00
using namespace pimoroni;
2022-06-13 14:43:08 +01:00
// Display driver
ST7789 st7789(PicoExplorer::WIDTH, PicoExplorer::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT));
2021-01-27 09:36:08 +00:00
2022-06-13 14:43:08 +01:00
// Graphics library - in RGB332 mode you get 256 colours and optional dithering for ~56K RAM.
PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr);
// Buttons
Button button_a(PicoExplorer::A);
Button button_b(PicoExplorer::B);
Button button_x(PicoExplorer::X);
Button button_y(PicoExplorer::Y);
// Motors
Motor motor1(PicoExplorer::MOTOR1_PINS);
Motor motor2(PicoExplorer::MOTOR2_PINS);
// Analog
Analog adc0(PicoExplorer::ADC0_PIN);
Analog adc1(PicoExplorer::ADC1_PIN);
Analog adc2(PicoExplorer::ADC2_PIN);
2021-01-27 09:36:08 +00:00
2022-06-13 14:43:08 +01:00
int main() {
motor1.init();
motor2.init();
while(true) {
// update screen
st7789.update(&graphics);
}
2021-01-27 09:36:08 +00:00
}
```
## Reference
### PicoGraphics
Pico Explorer uses our Pico Graphics library to draw graphics and text. For more information [read the Pico Graphics function reference. ](../pico_graphics/README.md#function-reference ).
2021-03-12 11:04:02 +00:00
Please note that the backlight on Pico Explorer is not dimmable (we needed the pins to hook up other functions) so the `set_backlight` function is not available for this board.
2021-01-27 09:36:08 +00:00
### Constants
#### Buttons
2022-06-13 14:43:08 +01:00
The four buttons, A, B, X and Y have corresponding constants set to their respective GPIO pins.
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
PicoExplorer::A = 12;
PicoExplorer::B = 13;
PicoExplorer::X = 14;
PicoExplorer::Y = 15;
2021-01-27 09:36:08 +00:00
```
#### ADC Channels
2022-06-13 14:43:08 +01:00
The three ADC channels are defined as `ADC0_PIN` , `ADC1_PIN` and `ADC2_PIN` , and should be used with an instance of the `Analog` class:
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
PicoExplorer::ADC0_PIN = 26;
PicoExplorer::ADC1_PIN = 27;
PicoExplorer::ADC2_PIN = 28;
2021-01-27 09:36:08 +00:00
```
#### GPIO
2022-06-13 14:43:08 +01:00
The 8 general purpose IO pins on the lower Pico Explorer are GP0 through GP7, we've created constants for you to identify them easily.
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
PicoExplorer::GP0 = 0;
PicoExplorer::GP1 = 1;
PicoExplorer::GP2 = 2;
PicoExplorer::GP3 = 3;
PicoExplorer::GP4 = 4;
PicoExplorer::GP5 = 5;
PicoExplorer::GP6 = 6;
PicoExplorer::GP7 = 7;
2021-01-27 09:36:08 +00:00
```
2022-06-13 14:43:08 +01:00
You should use Pico SDK's `gpio_get` to read a pin, eg:
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
bool pin_state = gpio_get(pico_explorer.GP0);
2021-01-27 09:36:08 +00:00
```
2022-06-13 14:43:08 +01:00
#### Motors
The two motor channels are defined as pin pairs, and should be used with an instance of the `Motor` class:
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
PicoExplorer::MOTOR1_PINS = {9, 8};
PicoExplorer::MOTOR2_PINS = {11, 10};
2021-01-27 09:36:08 +00:00
```
2022-06-13 14:43:08 +01:00
### Functions
2021-01-27 09:36:08 +00:00
2022-06-13 14:43:08 +01:00
#### Motors
2021-01-27 09:36:08 +00:00
2022-06-13 14:43:08 +01:00
Pico Explorer uses our `Motor` library to drive motors. Motors are driven by PWM via an onboard DRV8833. Constants are provided for both motors, so setup is as easy as:
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
#include "motor.hpp"
2021-01-27 09:36:08 +00:00
2022-06-13 14:43:08 +01:00
using namespace motor;
2021-01-27 09:36:08 +00:00
2022-06-13 14:43:08 +01:00
Motor motor1(PicoExplorer::MOTOR1_PINS);
Motor motor2(PicoExplorer::MOTOR2_PINS);
2021-01-27 09:36:08 +00:00
```
2022-06-13 14:43:08 +01:00
You should also init your motors to set up the required GPIO/PWM on their pins:
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
motor1.init();
motor2.init();
2021-01-27 09:36:08 +00:00
```
2022-06-13 14:43:08 +01:00
Speed should be given as a float between `-1.0` and `1.0` , eg:
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
motor1.speed(1.0) // Full-speed forward
motor1.speed(-1.0) // Full-speed backward
2021-01-27 09:36:08 +00:00
```
2022-06-13 14:43:08 +01:00
And to stop the motor:
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
motor1.stop()
2021-01-27 09:36:08 +00:00
```
2022-06-13 14:43:08 +01:00
#### Analog
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
float get_adc(uint8_t channel);
2021-01-27 09:36:08 +00:00
```
2022-06-13 14:43:08 +01:00
Pico Explorer's ADC channels are connected to Pico's ADC-capable pins 26, 27 and 28 which correspond to channels 0, 1 and 2 respectively.
2021-01-27 09:36:08 +00:00
2022-06-13 14:43:08 +01:00
Constants are supplied for these in the PicoExplorer library, so you can create an Analog instance for each:
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
#include "analog.hpp"
Analog adc0(PicoExplorer::ADC0_PIN);
Analog adc1(PicoExplorer::ADC1_PIN);
Analog adc2(PicoExplorer::ADC2_PIN);
2021-01-27 09:36:08 +00:00
```
2022-06-13 14:43:08 +01:00
And read a voltage with:
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
adc0.read_voltage();
2021-01-27 09:36:08 +00:00
```
2022-06-13 14:43:08 +01:00
#### Buzzer
2021-01-27 09:36:08 +00:00
2022-06-13 14:43:08 +01:00
Note: You must bridge the pin you use over to the `AUDIO` pin on the Pico Explorer header in order to drive the onboard Piezo.
2021-01-27 09:36:08 +00:00
2022-06-13 14:43:08 +01:00
TODO document buzzer
2021-01-27 09:36:08 +00:00
2022-06-13 14:43:08 +01:00
#### Buttons
2021-01-27 09:36:08 +00:00
```c++
2022-06-13 14:43:08 +01:00
#include "button.hpp"
Button button_a(PicoExplorer::A);
Button button_b(PicoExplorer::B);
Button button_x(PicoExplorer::X);
Button button_y(PicoExplorer::Y);
2021-01-27 09:36:08 +00:00
```
2022-06-13 14:43:08 +01:00
### ST7789
2021-01-27 09:36:08 +00:00
2022-06-13 14:43:08 +01:00
Pico Explorer uses the ST7789 display driver to handle the LCD. For more information [read the ST7789 README. ](../../drivers/st7789/README.md ).