quarta-feira, 18 de setembro de 2019

NINA B302 com OLED

U-BLOX NINA B302 e CIRCUITPYTHON
 ACESSANDO OLED SSD1306 via I2C

O objetivo deste BLOG é demonstrar como é possível utilizar programar o módulo U-BLOX NINA B302 com a linguagem de Scripts Python para efetuar a escrita em um display OLED SDD1306. Foi utilizado o módulo NINA B302 (opencpu) para o teste.

Neste blog um círculo ficará  animando no display OLED através da utilização da LIB adafruit_ssd1306.

Para fazer a leitura da entrada analógica será necessária a inclusão da LIB adafruit_ssd1306 na flash do NINA B302.

O programa ficará assim:

import microcontroller import busio import adafruit_ssd1306 # Helper function to draw a circle from a given position with a given radius # This is an implementation of the midpoint circle algorithm, # see https://en.wikipedia.org/wiki/Midpoint_circle_algorithm#C_example for details def draw_circle(xpos0, ypos0, rad, col=1): x = rad - 1 y = 0 dx = 1 dy = 1 err = dx - (rad << 1) while x >= y: oled.pixel(xpos0 + x, ypos0 + y, col) oled.pixel(xpos0 + y, ypos0 + x, col) oled.pixel(xpos0 - y, ypos0 + x, col) oled.pixel(xpos0 - x, ypos0 + y, col) oled.pixel(xpos0 - x, ypos0 - y, col) oled.pixel(xpos0 - y, ypos0 - x, col) oled.pixel(xpos0 + y, ypos0 - x, col) oled.pixel(xpos0 + x, ypos0 - y, col) if err <= 0: y += 1 err += dy dy += 2 if err > 0: x -= 1 dx += 2 err += dx - (rad << 1) # Create the I2C interface. i2c = busio.I2C(microcontroller.pin.P1_00, microcontroller.pin.P0_25) oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c) # initial center of the circle center_x = 63 center_y = 15 # how fast does it move in each direction x_inc = 1 y_inc = 1 # what is the starting radius of the circle radius = 8 # start with a blank screen oled.fill(0) # we just blanked the framebuffer. to push the framebuffer onto the display, we call show() oled.show() for x in range(160000): # undraw the previous circle draw_circle(center_x, center_y, radius, col=0) # if bouncing off right if center_x + radius >= oled.width: # start moving to the left x_inc = -1 # if bouncing off left elif center_x - radius < 0: # start moving to the right x_inc = 1 # if bouncing off top if center_y + radius >= oled.height: # start moving down y_inc = -1 # if bouncing off bottom elif center_y - radius < 0: # start moving up y_inc = 1 # go more in the current direction center_x += x_inc center_y += y_inc # draw the new circle draw_circle(center_x, center_y, radius) # show all the changes we just made oled.show()

DESCRIÇÃO
Basicamente o software configura os GPIOS para acessar os pinos de dados de I2C
i2c = busio.I2C(microcontroller.pin.P1_00, microcontroller.pin.P0_25)
// GPIO 7 e GPIO 8 do NINA B302





Apos isto, instancia um objeto com as caracteristicas do display
oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
Então entra num loop para plotar o círculo.
draw_circle(center_x, center_y, radius, col=0)

Se você salvar com o nome code.py, toda vez que resetar o NINA B302.



Foi montado o circuito abaixo com OLED


Círculo



CONHEÇA PYTHON

https://github.com/ehmatthes/pcc/releases/download/v1.0.0/beginners_python_cheat_sheet_pcc_all.pdf

ERRATA:
SERIGRAFIA DOS PINOS DO LADO DIREITO SUPERIOR
(NOMES DOS PINOS REPOSICIONADOS)


Questões: suporte@smartcore.com.br

FONTES: 

https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/introduction
https://learn.sparkfun.com/tutorials/nrf52840-development-with-arduino-and-circuitpython/all
https://www.u-blox.com/sites/default/files/NINA-B3_DataSheet_%28UBX-17052099%29.pdf
https://forums.adafruit.com/viewtopic.php?f=60&t=148531&start=30
https://circuitpython.readthedocs.io/en/2.x/shared-bindings/microcontroller/__init__.html?highlight=microcontroller
https://gitter.im/mu-editor/general
https://learn.adafruit.com/micropython-hardware-ssd1306-oled-display

Sobre a SMARTCORE

A SmartCore fornece módulos para comunicação wireless, biometria, conectividade, rastreamento e automação.
Nosso portifó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