Loading...
Searching...
No Matches
Arduino.h File Reference

Entry header for sketches: Arduino API + board pin map + Phyduino extras. More...

#include "api/ArduinoAPI.h"
#include "api/itoa.h"
#include "api/deprecated-avr-comp/avr/dtostrf.h"
#include "pico.h"
#include "pins_arduino.h"
#include "SerialUSB.h"
#include "SerialUART.h"
#include "RP2040.h"

Go to the source code of this file.

Macros

#define interrupts()
#define noInterrupts()
#define digitalPinToInterrupt(pin)

Functions

uint8_t digitalPinToGpio (pin_size_t pin)
 RP2040 GPIO behind an Arduino pin, for use with the pico-sdk.
void analogReadResolution (int bits)
 Sets the number of bits analogRead() returns, for every analog pin.
void analogWriteResolution (int bits)
 Sets the range analogWrite() takes, for every pin.
void analogWriteFrequency (uint32_t hz)
 Sets the PWM frequency used by later analogWrite() calls.
void analogReadAveraging (uint8_t samples)
 Sets how many samples are averaged for each analog result, on every analog pin.
uint32_t analogFullScaleMillivolts (pin_size_t pin)
 Voltage that reads as full scale on an analog pin.
uint32_t analogReadMillivolts (pin_size_t pin)
 Reads an analog pin as a voltage, whatever its ADC and full scale.
int32_t analogReadDifferentialMillivolts (pin_size_t plus, pin_size_t minus)
 Voltage between two analog pins, plus minus minus.
bool analogReadMultiple (const pin_size_t *pins, uint8_t count, uint16_t *results)
 Reads several analog pins as close together in time as possible.
uint32_t analogReadBurst (pin_size_t pin, uint16_t *buffer, size_t count, uint32_t sample_rate_hz)
 Samples one analog pin at a fixed rate into an array, and waits until it is full.
uint32_t analogStartBurst (pin_size_t pin, uint16_t *buffer, size_t count, uint32_t sample_rate_hz)
 Starts a burst like analogReadBurst(), but returns at once; the samples are taken in the background.
bool analogBurstDone ()
 Whether the burst started by analogStartBurst() has finished.
void analogStopBurst ()
 Stops the burst started by analogStartBurst() before it has finished.
Variant hooks (not for sketches)
uint16_t variantAnalogRead (pin_size_t pin)
 Reads an analog pin that has no RP2040 GPIO, with the variant's averaging setting.
uint32_t variantAnalogFullScaleMillivolts (pin_size_t pin)
 Full scale of a variant analog pin.
void variantAnalogReadAveraging (uint8_t samples)
 Sets the averaging for the variant's analog pins.
bool variantAnalogReadMultiple (const pin_size_t *pins, uint8_t count, uint16_t *raw)
 Reads several variant analog pins in one go.
bool variantAnalogReadDifferential (pin_size_t plus, pin_size_t minus, int32_t *millivolts)
 Measures plus - minus if the variant can do it in hardware.
uint32_t variantAnalogStartBurst (pin_size_t pin, uint16_t *buffer, size_t count, uint32_t sample_rate_hz)
 Starts a background burst on a variant analog pin; 12-bit samples into buffer.
bool variantAnalogBurstDone ()
 Whether the variant's burst has finished (true if none was started).
void variantAnalogStopBurst ()
 Stops the variant's burst.

Variables

constexpr uint8_t kPinToGpio [] = PHYDUINO_PIN_TO_GPIO
 RP2040 GPIO for each Arduino pin, indexed by pin number (PHYDUINO_PIN_TO_GPIO).

Detailed Description

Entry header for sketches: Arduino API + board pin map + Phyduino extras.

The pico-sdk is available too; sketches can include e.g. "hardware/pwm.h" and use digitalPinToGpio() to get the RP2040 GPIO behind an Arduino pin.

Function Documentation

◆ variantAnalogBurstDone()

bool variantAnalogBurstDone ( )

Whether the variant's burst has finished (true if none was started).

Returns
true once every sample is in the buffer.

◆ variantAnalogFullScaleMillivolts()

uint32_t variantAnalogFullScaleMillivolts ( pin_size_t pin)

Full scale of a variant analog pin.

Parameters
pinArduino pin number.
Returns
Full scale in mV, or 0 if the pin is not one of the variant's.

◆ variantAnalogRead()

uint16_t variantAnalogRead ( pin_size_t pin)

Reads an analog pin that has no RP2040 GPIO, with the variant's averaging setting.

Parameters
pinArduino pin number.
Returns
12-bit value (0-4095), or 0 if the pin is not one of the variant's.

◆ variantAnalogReadAveraging()

void variantAnalogReadAveraging ( uint8_t samples)

Sets the averaging for the variant's analog pins.

Parameters
samples1, 4, 8, 16 or 32 (already rounded by the core).

◆ variantAnalogReadDifferential()

bool variantAnalogReadDifferential ( pin_size_t plus,
pin_size_t minus,
int32_t * millivolts )

Measures plus - minus if the variant can do it in hardware.

Parameters
plusArduino pin number.
minusArduino pin number.
millivoltsResult in mV.
Returns
false if the pair has no hardware differential mode or the result is out of its range; the core then uses two single readings.

◆ variantAnalogReadMultiple()

bool variantAnalogReadMultiple ( const pin_size_t * pins,
uint8_t count,
uint16_t * raw )

Reads several variant analog pins in one go.

Parameters
pinsVariant analog pins.
countNumber of pins.
rawArray of count 12-bit results, in the order of pins.
Returns
false if a pin is not one of the variant's or the ADC does not answer.

◆ variantAnalogStartBurst()

uint32_t variantAnalogStartBurst ( pin_size_t pin,
uint16_t * buffer,
size_t count,
uint32_t sample_rate_hz )

Starts a background burst on a variant analog pin; 12-bit samples into buffer.

Parameters
pinArduino pin number.
bufferArray for count samples.
countNumber of samples.
sample_rate_hzSamples per second.
Returns
Rate used in Hz, or 0 if not possible.