# FrameBuffer.poly(x, y, coords, c[, f]) - help needed

I’ve been trying to get this to draw a filled rectangle on a mono oled (ssd1306 SPI / I2C and similar)

The MicroPython documentation for Pico in Read-the-Docs provides:

FrameBuffer.poly(x, y, coords, c[, f])¶

Given a list of coordinates, draw an arbitrary (convex or concave) closed polygon at the given x, y location using the given color.

The coords must be specified as a array of integers, e.g. array(‘h’, [x0, y0, x1, y1, … xn, yn]).

The optional f parameter can be set to True to fill the polygon. Otherwise just a one pixel outline is drawn.

I’ve not needed to use array before and cannot get the syntax right. [10,10,120,30,30,61] are the coordinates I want to use.

Has anyone got this to work?

So I’ve not done this, but it looks like it would be easiest to define the array separately first. The MicroPython documentation also seems to point to the Python documentation for arrays.

I’m not sure what you’ve tried, but it looks like you need to create an object of type array.

import array
myData = array.array()

You also need to declare the type of data in the array. h looks like it is for a signed short, which I’m assuming makes no sense as your coordinates will always be positive integers, so unsigned int (‘I’) or unsigned char (?) (‘B’) might make more sense.

import array
myData = array.array('I')

import array
myData = array.array('I', [10,10,120,30,30,61])

Then call the FrameBuffer function:

import array
myData = array.array('I', [10,10,120,30,30,61])

FrameBuffer.poly(x, y, myData, c)

That’s what I’d take away from that anyway.

Thank you, Shoe

import time, math
from machine import Pin, I2C, ADC
import ssd1306
import framebuf
import array

WIDTH  = 128                                            # oled display width
HEIGHT = 64                                             # oled display height

sda=machine.Pin(8)
scl=machine.Pin(9)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)

oled = ssd1306.SSD1306_I2C(128, 64, i2c)

myData = array.array('I', [10,10,120,30,30,61])

oled.poly(0, 0, myData, 1,1)
oled.show()

That has got it working.

Rather strange that we need to include an offset from the origin as the first two numbers, x and y. Could use it to move the triangle about without a load of adjustments to the array.

Glad you got it working. Like you said, I assume the x/y offset is for animating an object around the screen or duplicating it in several places.