terça-feira, 20 de abril de 2021

U-BLOX NINA B302 CONTROLANDO SERVO VIA VISUINO

  U-BLOX NINA B302 CONTROLANDO SERVO  VIA VISUINO

BETA


O objetivo deste BLOG é demonstrar como é possível utilizar o VISUINO para programar o módulo U-BLOX NINA B302. Foi utilizado o BREAKOUT para o teste. No exemplo, iremos fazer um servo se deslocar de 0 a 180 graus e novamente a 0.

O componente U-BLOX NINA B302 para VISUINO ainda é experimental.

SERVO

Servo Motor Arduino é um equipamento utilizado nos mais diversificados projetos para controle de posição e movimento e está geralmente associado a projetos de pequena e média escala. Mesmo que bastante semelhantes, o servo motor é comercializado com ângulos de 180º e 360º (Rotação contínua). Servo Motor 180 e 360 Graus



BREAKOUT

Adquirimos então os seguintes componentes


Montado ficou assim


O esquema elétrico é este


Algumas características do BREAKOUT
Botão de RESET;
Instale Arduino e SDK da Nordic (NRF52)

  • Baixe e instale a última versão da IDE do Arduino
  • Execute a IDE do Arduino e click em files-->preference e digite

    https://www.adafruit.com/package_adafruit_index.json

  • Vá agora em Tools > Board > Boards Manager e procure por "Adafruit nrf52" e instale
  • Aguarde alguns minutos para instalação do SDK. 

Gravando bootloader da Adafruit

Use o gravador SEGGER JLINK para gravar o BREAKOUT com módulo NINA B302, conecte nos pinos do SWCLK (pino 7) e SWDIO (pino 9) do SEGGER JLINK nos pinos  SWDCLK e SWDIO do BREAKOUT (pinos nas laterais, próximo à antena). Não esquecer de ligar os GND do BREAKOUT no GND do SEGGER JTAG, bem como alimentar o BREAKOUT com 3.3V. 



Ligue os pinos SWD DIO e CLK ...
...nestes pinos da placa BREAKOUT

Você pode também usar o ST-LINK V2



Abra J-FLASH lite e grave o bootloader da Adafruit


O bootloader se encontra em 

....\packages\adafruit\hardware\nrf52\0.21.0\bootloader\feather_nrf52840_express
Requer instalação do Arduino Adafruit NRF52

Compile depois para o NINA B302 se quiser!

Com ele, você poderá transferir programas via DFU USB. Maiores detalhes sobre este bootloader


ATENÇÃO, o bootloader usa USB para gravação do NINA 302, OU SEJA, CRIA UMA COMM VIRTUAL, TAMBÉM PARA SER A SERIAL PADRÃO DO ARDUINO


Conecte na USB + e USB - um cabo USB, AGUARDE INSTALAR OS DRIVERS



ÓTIMA REFERÊNCIA PARA PINOS DO ARDUINO E PINOS (GPIOS) DO NINA B302


Consulte
https://www.u-blox.com/sites/default/files/NINA-B3_DataSheet_%28UBX-17052099%29.pdf

Baixe e instale o VISUINO


"O Visuino é o mais recente software inovador da Mitov Software. Um ambiente de programação visual que permite programar suas placas Arduino."


Copie para o Visuino o seguinte arquivo Mitov.Boards.Nina.vcomp em
C:\Users\Usuario\Documents\Arduino\libraries\Mitov\Visuino

Mitov //--------------------------------------------------------------------------- [Name( 'U-Blox' )] TUBloxCategory : TClassCategory; //--------------------------------------------------------------------------- [Name( 'NINA-B1' )] [Category( TUBloxCategory )] [ParentImage( TUBloxCategory )] TUBloxNinaB1Category : TClassCategory; //--------------------------------------------------------------------------- [Name( 'MicroE' )] TMicroECategory : TClassCategory; //--------------------------------------------------------------------------- [Name( 'NINA-B1' )] [Category( TMicroECategory )] [AlternateCategory( TUBloxNinaB1Category )] [ParentImage( TUBloxNinaB1Category )] TMicroEUBloxNinaB1Category : TClassCategory; //--------------------------------------------------------------------------- [ArduinoBoardCompileParams( 'sandeepmistry:nRF5:Generic_nRF52832' )] [ParentImage( TUBloxCategory )] TArduino_Basic_NINA_B1_Board : TArduino_Basic_nRF5_Board; //--------------------------------------------------------------------------- [Name( 'MicroE NINA-B1' )] [Category( TMicroEUBloxNinaB1Category )] +TArduino_MicroE_NINA_B1_Board : TArduino_Basic_NINA_B1_Board [ArduinoBoardAddDigitalAnalogChannels( 2, 1, TArduinoBasicDigitalPWMI2C0Channel, 'Digital(I2C-SDA)' )] [ArduinoBoardAddDigitalAnalogChannels( 3, 1, TArduinoBasicDigitalPWMI2C0Channel, 'Digital(I2C-SCL)' )] [ArduinoBoardAddDigitalAnalogChannels( 4, 1, TArduinoBasicDigitalPWMChannel, 'Digital(LED)' )] [ArduinoBoardAddDigitalAnalogChannels( 5, 1, TArduinoBasicDigitalPWMSerial0Channel, 'Digital(RX)' )] [ArduinoBoardAddDigitalAnalogChannels( 6, 1, TArduinoBasicDigitalPWMSerial0Channel, 'Digital(TX)' )] [ArduinoBoardAddDigitalAnalogChannels( 7, 1, TArduinoBasicDigitalPWMSerial0Channel, 'Digital(CTS)' )] [ArduinoBoardAddDigitalAnalogChannels( 9, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_28)' )] [ArduinoBoardAddDigitalAnalogChannels( 10, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_29)' )] [ArduinoBoardAddDigitalAnalogChannels( 12, 1, TArduinoBasicDigitalPWMSPI0Channel, 'Digital(SPI-MISO)(SDO)' )] [ArduinoBoardAddDigitalAnalogChannels( 13, 1, TArduinoBasicDigitalPWMSPI0Channel, 'Digital(SPI-MOSI)(SDI)' )] [ArduinoBoardAddDigitalAnalogChannels( 14, 1, TArduinoBasicDigitalPWMSPI0Channel, 'Digital(SPI-SCK)' )] [ArduinoBoardAddDigitalAnalogChannels( 16, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_7)' )] [ArduinoBoardAddDigitalAnalogChannels( 28, 1, TArduinoBasicDigitalPWMSerial0Channel, 'Digital(DTR)(IO_16)' )] [ArduinoBoardAddDigitalAnalogChannels( 29, 1, TArduinoBasicDigitalPWMSerial0Channel, 'Digital(DSR)(IO_17)' )] [ArduinoBoardAddDigitalAnalogChannels( 30, 1, TArduinoCombinedAnalogNoPullDigitalChannel, 'Digital/Analog[ 30 ]' )] [ArduinoBoardAddDigitalAnalogChannels( 31, 1, TArduinoBasicDigitalPWMSerial0Channel, 'Digital(RTS)(CS)' )] Digital : TArduinoDigitalChannels ; //--------------------------------------------------------------------------- [Name( 'EVK-NINA-B3' )] [Category( TUBloxNinaB1Category )] +TArduino_EVK_NINA_B1_Board : TArduino_Basic_NINA_B1_Board [ArduinoBoardAddDigitalAnalogChannels( 0, 1, TArduinoBasicDigitalPWMSerial0Channel, 'Digital(RX)' )] [ArduinoBoardAddDigitalAnalogChannels( 1, 1, TArduinoBasicDigitalPWMSerial0Channel, 'Digital(TX)' )] [ArduinoBoardAddDigitalAnalogChannels( 2, 1, TArduinoBasicDigitalPWMChannel, ' Digital(IO_21)' )] [ArduinoBoardAddDigitalAnalogChannels( 3, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_20)' )] [ArduinoBoardAddDigitalAnalogChannels( 4, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_1)' )] [ArduinoBoardAddDigitalAnalogChannels( 5, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_32)' )] [ArduinoBoardAddDigitalAnalogChannels( 6, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_28)' )] //NFC [ArduinoBoardAddDigitalAnalogChannels( 7, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_29)' )] //NFC [ArduinoBoardAddDigitalAnalogChannels( 8, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_33)' )] [ArduinoBoardAddDigitalAnalogChannels( 9, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_46)' )] [ArduinoBoardAddDigitalAnalogChannels( 10, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_2)' )] [ArduinoBoardAddDigitalAnalogChannels( 11, 1, TArduinoBasicDigitalPWMSPI0Channel, 'Digital(IO_3)(SPI-MOSI)(SDI)' )] [ArduinoBoardAddDigitalAnalogChannels( 12, 1, TArduinoBasicDigitalPWMSPI0Channel, 'Digital(IO_8)(SPI-MISO)(SDO)' )] [ArduinoBoardAddDigitalAnalogChannels( 13, 1, TArduinoBasicDigitalPWMSPI0Channel, 'Digital(IO_45)(SPI-SCK)' )] [ArduinoBoardAddDigitalAnalogChannels( 14, 1, TArduinoCombinedAnalogNoPullDigitalChannel, 'Analog(IO_25)[ 0 ]' )] [ArduinoBoardAddDigitalAnalogChannels( 15, 1, TArduinoCombinedAnalogNoPullDigitalChannel, 'Analog(IO_24)[ 1 ]' )] [ArduinoBoardAddDigitalAnalogChannels( 16, 1, TArduinoCombinedAnalogNoPullDigitalChannel, 'Analog(IO_27)[ 2 ]' )] [ArduinoBoardAddDigitalAnalogChannels( 17, 1, TArduinoCombinedAnalogNoPullDigitalChannel, 'Analog(IO_18)[ 3 ]' )] [ArduinoBoardAddDigitalAnalogChannels( 18, 1, TArduinoCombinedAnalogNoPullDigitalChannel, 'Analog(IO_17)[ 4 ]' )] [ArduinoBoardAddDigitalAnalogChannels( 19, 1, TArduinoCombinedAnalogNoPullDigitalChannel, 'Analog(IO_16)[ 5 ]' )] [ArduinoBoardAddDigitalAnalogChannels( 20, 1, TArduinoCombinedAnalogNoPullDigitalI2C0Channel, 'I2C-SCL(IO_5)' )] [ArduinoBoardAddDigitalAnalogChannels( 21, 1, TArduinoCombinedAnalogNoPullDigitalI2C0Channel, 'I2C-SDA(IO_4)' )] [ArduinoBoardAddDigitalAnalogChannels( 22, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_52)' )] [ArduinoBoardAddDigitalAnalogChannels( 23, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_51)' )] [ArduinoBoardAddDigitalAnalogChannels( 24, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_50)' )] [ArduinoBoardAddDigitalAnalogChannels( 25, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_49)' )] [ArduinoBoardAddDigitalAnalogChannels( 26, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_48)' )] [ArduinoBoardAddDigitalAnalogChannels( 27, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_47)' )] [ArduinoBoardAddDigitalAnalogChannels( 28, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_34)' )] [ArduinoBoardAddDigitalAnalogChannels( 29, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_35)' )] [ArduinoBoardAddDigitalAnalogChannels( 30, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_36)' )] [ArduinoBoardAddDigitalAnalogChannels( 31, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_37)' )] [ArduinoBoardAddDigitalAnalogChannels( 32, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_38)' )] [ArduinoBoardAddDigitalAnalogChannels( 33, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_39)' )] [ArduinoBoardAddDigitalAnalogChannels( 34, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_40)' )] [ArduinoBoardAddDigitalAnalogChannels( 35, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_41)' )] [ArduinoBoardAddDigitalAnalogChannels( 36, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_42)' )] [ArduinoBoardAddDigitalAnalogChannels( 37, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_43)' )] [ArduinoBoardAddDigitalAnalogChannels( 38, 1, TArduinoBasicDigitalPWMChannel, 'Digital(IO_44)' )] Digital : TArduinoDigitalChannels ; //--------------------------------------------------------------------------- ; // Mitov

Copie o seguinte arquivos variant.cpp em
\Users\Usuario\AppData\Local\Arduino15\packages\adafruit\hardware\nrf52\0.21.0\variants

/* Copyright (c) 2014-2015 Arduino LLC. All right reserved. Copyright (c) 2016 Sandeep Mistry All right reserved. Copyright (c) 2018, Adafruit Industries (adafruit.com) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // Thanks to great work of [Miguel Alexandre Wisintainer](https://github.com/tcpipchip). // See [u-blox nina b](https://github.com/khoih-prog/WiFiNINA_Generic/issues/1) #include "variant.h" #include "wiring_constants.h" #include "wiring_digital.h" #include "nrf.h" const uint32_t g_ADigitalPinMap[] = { // D0 .. D13 29, // D0 is P0.29 (UART TX) 45, // D1 is P1.13 (UART RX 44, // D2 is P1.12 (NFC2) 31, // D3 is P0.31 (LED1) 13, // D4 is P0.13 (LED2) 11, // D5 is P0.11 9, // D6 is P0.09 10, // D7 is P0.10 (Button) 41, // D8 is P1.09 12, // D9 is P0.12 14, // D10 is P0.14 15, // D11 is P0.15 32, // D12 is P1.00 7, // D13 is P0.07 // D14 .. D21 (aka A0 .. A5) 4, // D14 is P0.04 (A0) 30, // D15 is P0.30 (A1) 5, // D16 is P0.05 (A2) 2, // D17 is P0.02 (A3) 28, // D18 is P0.28 (A4) 3, // D19 is P0.03 (A5) // D20 .. D21 (aka I2C pins) 16, // D20 is P0.16 (SDA) 24, // D21 is P0.24 (SCL) // QSPI pins (not exposed via any header / test point) 19, // D22 is P0.19 (QSPI CLK) 17, // D23 is P0.17 (QSPI CS) 20, // D24 is P0.20 (QSPI Data 0) 21, // D25 is P0.21 (QSPI Data 1) 22, // D26 is P0.22 (QSPI Data 2) 26, // D27 is P0.23 (QSPI Data 3) 40, // D28 is P1.08 - IO34 41, // D29 is P1.01 - IO35 44, // D30 is P1.02 - IO36 45, // D31 is P1.03 - IO37 42, // D32 is P1.10 - IO38 43, // D33 is P1.11 - IO39 47, // D34 is P1.15 - IO40 46, // D35 is P1.14 - IO41 26, // D36 is P0.26 - IO42 6, // D37 is P0.6 - IO43 27, // D38 is P0.27 - IO44 }; void initVariant() { // LED1 & LED2 pinMode(PIN_LED1, OUTPUT); ledOff(PIN_LED1); pinMode(PIN_LED2, OUTPUT); ledOff(PIN_LED2); }

Copie o seguinte arquivo variant.h em
\Users\Usuario\AppData\Local\Arduino15\packages\adafruit\hardware\nrf52\0.21.0\variants

/* Copyright (c) 2014-2015 Arduino LLC. All right reserved. Copyright (c) 2016 Sandeep Mistry All right reserved. Copyright (c) 2018, Adafruit Industries (adafruit.com) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // Thanks to great work of [Miguel Alexandre Wisintainer](https://github.com/tcpipchip). // See [u-blox nina b](https://github.com/khoih-prog/WiFiNINA_Generic/issues/1) #ifndef _VARIANT_NINA_B302_UBLOX_ #define _VARIANT_NINA_B302_UBLOX_ /** Master clock frequency */ #define VARIANT_MCK (64000000ul) #define USE_LFXO // Board uses 32khz crystal for LF // define USE_LFRC // Board uses RC for LF /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ #include "WVariant.h" #ifdef __cplusplus extern "C" { #endif // __cplusplus // Number of pins defined in PinDescription array #define PINS_COUNT (40) #define NUM_DIGITAL_PINS (34) #define NUM_ANALOG_INPUTS (6) #define NUM_ANALOG_OUTPUTS (0) // LEDs #define PIN_LED1 (3) #define PIN_LED2 (4) #define LED_BUILTIN PIN_LED1 #define LED_CONN PIN_LED2 #define LED_RED PIN_LED1 #define LED_BLUE PIN_LED2 /* * Buttons */ #define PIN_BUTTON1 (7) /* * Analog pins */ #define PIN_A0 (14) #define PIN_A1 (15) #define PIN_A2 (16) #define PIN_A3 (17) #define PIN_A4 (18) #define PIN_A5 (19) #define D0 (0) #define D1 (1) #define D2 (2) #define D3 (3) #define D4 (4) #define D5 (5) #define D6 (6) #define D7 (7) #define D8 (8) #define D9 (9) #define D10 (10) #define D11 (11) #define D12 (12) #define D13 (13) static const uint8_t A0 = PIN_A0 ; static const uint8_t A1 = PIN_A1 ; static const uint8_t A2 = PIN_A2 ; static const uint8_t A3 = PIN_A3 ; static const uint8_t A4 = PIN_A4 ; static const uint8_t A5 = PIN_A5 ; #define ADC_RESOLUTION 14 #define PIN_NFC1 (31) #define PIN_NFC2 (2) /* * Serial interfaces */ #define PIN_SERIAL1_RX (1) #define PIN_SERIAL1_TX (0) /* * SPI Interfaces */ #define SPI_INTERFACES_COUNT 1 #define PIN_SPI_MISO (22) //24 original #define PIN_SPI_MOSI (23) //25 original #define PIN_SPI_SCK (24) //26 original static const uint8_t SS = (13); static const uint8_t MOSI = PIN_SPI_MOSI; static const uint8_t MISO = PIN_SPI_MISO; static const uint8_t SCK = PIN_SPI_SCK; /* * Wire Interfaces */ #define WIRE_INTERFACES_COUNT 1 #define PIN_WIRE_SDA (20) #define PIN_WIRE_SCL (21) // QSPI Pins #define PIN_QSPI_SCK 22 #define PIN_QSPI_CS 23 #define PIN_QSPI_IO0 24 #define PIN_QSPI_IO1 25 #define PIN_QSPI_IO2 26 #define PIN_QSPI_IO3 27 // On-board QSPI Flash #define EXTERNAL_FLASH_DEVICES GD25Q16C #define EXTERNAL_FLASH_USE_QSPI #ifdef __cplusplus } #endif /*---------------------------------------------------------------------------- * Arduino objects - C++ only *----------------------------------------------------------------------------*/ #endif //_VARIANT_NINA_B302_UBLOX_

Adicione em boards.txt em
\Users\Usuario\AppData\Local\Arduino15\packages\adafruit\hardware\nrf52\0.21.0

# ---------------------------------- # NINA B302 # ---------------------------------- ninab302.name=NINA B302 ublox # VID/PID for bootloader with/without UF2, Arduino + Circuitpython App ninab302.vid.0=0x239A ninab302.pid.0=0x8029 ninab302.vid.1=0x239A ninab302.pid.1=0x0029 ninab302.vid.2=0x7239A ninab302.pid.2=0x002A ninab302.vid.3=0x239A ninab302.pid.3=0x802A # Upload ninab302.bootloader.tool=bootburn ninab302.upload.tool=nrfutil ninab302.upload.protocol=nrfutil ninab302.upload.use_1200bps_touch=true ninab302.upload.wait_for_upload_port=true ninab302.upload.maximum_size=815104 ninab302.upload.maximum_data_size=237568 # Build ninab302.build.mcu=cortex-m4 ninab302.build.f_cpu=64000000 ninab302.build.board=NINA_B302_ublox ninab302.build.core=nRF5 ninab302.build.variant=NINA_B302_ublox ninab302.build.usb_manufacturer="Nordic" ninab302.build.usb_product="NINA B302 ublox" ninab302.build.extra_flags=-DNRF52840_XXAA -DNINA_B302_ublox {build.flags.usb} ninab302.build.ldscript=nrf52840_s140_v6.ld ninab302.build.vid=0x239A ninab302.build.pid=0x8029 # SofDevice Menu ninab302.menu.softdevice.s140v6=0.3.2 SoftDevice s140 6.1.1 ninab302.menu.softdevice.s140v6.build.sd_name=s140 ninab302.menu.softdevice.s140v6.build.sd_version=6.1.1 ninab302.menu.softdevice.s140v6.build.sd_fwid=0x00B6 # Debug Menu ninab302.menu.debug.l0=Level 0 (Release) ninab302.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0 ninab302.menu.debug.l1=Level 1 (Error Message) ninab302.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1 ninab302.menu.debug.l2=Level 2 (Full Debug) ninab302.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2 ninab302.menu.debug.l3=Level 3 (Segger SystemView) ninab302.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3 ninab302.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1

Execute o Visuino e selecione EVK-NINA-B3


Novo Componente

Em board selecione Adafruit NINA B302 ublox

Adrafruit NRF52

Adicione fluxos conforme figura abaixo:

Servo Conectado na IO33 do BREAKOUT. Sinal também é enviado para IO28 e IO29

Faça o Visuino apontar para a IDE do Arduino


Click no ICONE do Arduino 




Compile e transfira o programa



Veja  o vídeo



Questões: suporte@smartcore.com.br

Sobre a SMARTCORE

A SmartCore fornece módulos para comunicação wireless, biometria, conectividade, rastreamento e automação.
Nosso portfólio inclui modem 2G/3G/4G/NB-IoT/Cat.M, satelital, módulos WiFi, Bluetooth, GNSS / GPS, Sigfox, LoRa, leitor de cartão, leitor QR code, mecanismo de impressão, mini-board PC, antena, pigtail, LCD, bateria, repetidor GPS e sensores.
Mais detalhes em www.smartcore.com.br