Pular para o conteúdo principal

Multiplexação de pinos no Seeed Studio XIAO nRF52840 (Sense)

O Seeed Studio XIAO nRF52840 (Sense) possui interfaces ricas. Existem 11 E/S digitais que podem ser usadas como pinos PWM e 6 entradas analógicas que podem ser usadas como pinos ADC. Ele suporta as três interfaces de comunicação serial mais comuns, como UART, I2C e SPI. Este wiki será útil para aprender sobre essas interfaces e implementá-las em seus próximos projetos!

As funções básicas aqui funcionam bem para ambas as bibliotecas Arduino do Seeed Studio XIAO nRF52840.

Visão geral de hardware​

Frente do XIAO nRF52840​

Verso do XIAO nRF52840​

Mapa de pinos

Pino XIAOFunçãoPino do chipDescriçãoNome Arduino
5VVBUSEntrada/Saída de energia
GND
3V33V3_OUTSaída de energia
D0AnalógicoP0.02GPIO, AIN00
D1AnalógicoP0.03GPIO, AIN11
D2AnalógicoP0.28GPIO, AIN42
D3AnalógicoP0.29GPIO, AIN53
D4Analógico, SDAP0.04GPIO, dados I2C, AIN24
D5Analógico, SCLP0.05GPIO, clock I2C, AIN35
D6TXP1.11GPIO, transmissão UART7/6
D7RXP1.12GPIO, recepção UART8/7
D8SPI_SCKP1.13GPIO, clock SPI9/8
D9SPI_MISOP1.14GPIO, dados SPI10/9
D10SPI_MOSIP1.15GPIO, dados SPI11/10
NFC1P0.09NFC
NFC2P0.10NFC
ResetP0.18RESET
ADC_BATREAD_BAT_ENABLEP0.14Controle de habilitação para leitura da tensão da bateria
RF Switch Port SelectP2.05Alternar antena onboard
RF Switch PowerP2.03Alimentação
CHARGE_LEDP0.17CHG-LED_Red
USER_LED_RP0.26Pino de LED RGB vermelho controlado pelo usuário11
USER_LED_BP0.06Pino de LED RGB azul controlado pelo usuário13/12
USER_LED_GP0.30Pino de LED RGB verde controlado pelo usuário12/13

Digital​

Conecte um botão de pressão ao pino D6 e um LED ao pino D10. Em seguida, envie o seguinte código para controlar o LIGAR/DESLIGAR do LED usando o botão de pressão.

const int buttonPin = 6;     // pushbutton connected to digital pin 6
const int ledPin = 10; // LED connected to digital pin 10

int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED off:
digitalWrite(ledPin, HIGH);
} else {
// turn LED on:
digitalWrite(ledPin, LOW);
}
}

Digital como PWM​

Conecte um LED ao pino D10. Em seguida, envie o código a seguir para ver o LED desvanecendo gradualmente.

int ledPin = 10;    // LED connected to digital pin 10

void setup() {

}

void loop() {
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

// fade out from max to min in increments of 5 points:
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}

Analógico​

Conecte um potenciômetro ao pino A5 e um LED ao pino D10. Em seguida, envie o código a seguir para controlar o intervalo de piscar do LED girando o botão do potenciômetro.

const int sensorPin = 5;
const int ledPin = 10;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
// read the value from the sensor:
int sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}

Serial​

Use Serial1 para usar o UART via GPIO em vez de USB. Você também pode usar ambos simultaneamente. Use o pino D6 como pino TX do UART e o pino D7 como pino RX do UART para enviar a mensagem "Hello World!".

void setup() {
Serial1.begin(115200);
while (!Serial1);
}

void loop() {
Serial1.println("Hello World!");
delay(1000);
}

I2C​

Grove - OLED Display 1.12 (SH1107)Seeed Studio XIAO nRF52840 (Sense)
GNDGND
VCC5V
SDASDA
SCLSCL

pir

  • Passo 2. Abra o Arduino IDE, navegue até Sketch > Include Library > Manage Libraries...

  • Passo 3. Procure por u8g2 e instale-o

pir

  • Passo 4. Envie o código a seguir para exibir strings de texto no OLED Display
#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>

U8G2_SH1107_SEEED_128X128_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 5, /* data=*/ 4, /* reset=*/ U8X8_PIN_NONE);

void setup(void) {
u8g2.begin();
}

void loop(void) {
u8g2.firstPage();

do {
u8g2.setFont(u8g2_font_luBIS08_tf);
u8g2.drawStr(0,24,"Hello Seeed!");
} while ( u8g2.nextPage() );
}

SPI​

Grove - OLED Display 1.12 (SH1107)Seeed Studio XIAO nRF52840 (Sense)
GNDGND
5V5V
SCLSCK
SIMOSI
RESD3
D/CD4
CSD5

pir

  • Passo 2. Este display OLED suporta comunicação tanto I2C quanto SPI, e o modo padrão é I2C. Para usar o modo SPI, você precisa consultar o Grove - OLED Display 1.12 (SH1107) V3.0 wiki para alterar a comunicação do display OLED para SPI antes de prosseguir

Nota: Certifique-se de que a biblioteca U8g2 esteja instalada a partir dos passos anteriores.

  • Passo 3. Envie o código a seguir para exibir strings de texto no OLED Display
#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>

U8G2_SH1107_128X128_1_4W_HW_SPI u8g2(U8G2_R3, /* cs=*/ 5, /* dc=*/ 4, /* reset=*/ 3);

void setup(void) {
u8g2.begin();
}

void loop(void) {
u8g2.firstPage();

do {
u8g2.setFont(u8g2_font_luBIS08_tf);
u8g2.drawStr(0,24,"Hello Seeed!");
} while ( u8g2.nextPage() );
}
Loading Comments...