PART 4 - RP2040 & GC9A01 Ardunio & Pi Random Eyes and Gauges

by egocen in Circuits > Arduino

72 Views, 0 Favorites, 0 Comments

PART 4 - RP2040 & GC9A01 Ardunio & Pi Random Eyes and Gauges

rectGauge.png
disp2.png
disp1.png
FWIMETVM7ES7M3S.png
F8B225TM7ES7NJG.png
FK43QGNM7ES7M2X.png

Starting with a simple gauge drawing, we will incrementally develop the project by integrating the millis() function for real-time data updates. This approach will enable us to display sensor data dynamically on the screen, enrich the user interface, and make the project more interactive. Throughout this process, with the help of Microsoft Copilot, you'll have the opportunity to improve your technical abilities and come up with innovative solutions. I hate Cos() but!

We will Add sensors to created sketch on PART3. (https://www.instructables.com/PART3-Drawing-Eyes-Graphics-Using-ArdunioGFXLibrar/)




Supplies

mpu6050.png
soundss.png
rp2040.png
gc9a01round.png

RP2040-Zero

2 x GC9A01 round Display

sound sensor

Mpu6050

Connections

rp2dpWmpu.png

We added the mpu6050 sensor using the i2c port to GPIOs 4 and 5 in our project.

And Code

With this code, we'll show each function we've developed on the display, one by one. This will help us demonstrate the features and capabilities we've created in a clear and engaging way.

We have some functions shown names below. You can use its loop section. I was tried its sequentially with the taskno variable.

In the next steps we will improve the gauge views


void suterazi(); //its draw line for sprit leveling from mpu6050 data

void i2cscan(); //i2cscan sample code

void gozciz(); //draw eyes

void drawTemperatureGauge(Arduino_GFX *gfx, float temperature) //draw a gauge with rp2040 internal Heat sensor value.

void saatgosterge() //basic time displayer clock

void ekolizer() //basic ekolizer from sound sensor analog values. Not displayed in this demo


Draw Nice Gauges Help With CoPilot

solidGauge.png
rectangularGauge.png
linesGauge.png

Now I was tried Draw a solid Gauge and Rectangular Gauge its drawed by coPilots

Here is the codes:


float temperature = readTemperature() ; //reads internal sensor

cerveveGauge(temperature, 0, 50); //show between 0 and 50 values. solid gauge you can call in loop

or

drawRectangularGauge(temperature, 0, 50, YELLOW); //between 0-50 values and set neddle color

or

cizgiGauge(temperature, 0, 50); //show between 0 and 50 values. frame with lines

---

void drawRectangularGauge(float value, float minVal, float maxVal, uint16_t needleColor) {

int16_t x = gfx->width() / 2;

int16_t y = gfx->height() / 2;

int rectWidth = 10;

int rectHeight = 20;

int gap = 5; // Boşluk miktarı

int r = min(gfx->width(), gfx->height()) / 2 - 20;


// Gösterge segmentleri

for (int i = -135; i <= 135; i += (rectHeight + gap)) {

uint16_t color;

if (i < 0) color = BLUE;

else if (i < 90) color = GREEN;

else color = RED;


// Dörtgenin köşe noktalarını hesapla

int xA = x + (r - rectHeight / 2) * cos(radians(i));

int yA = y + (r - rectHeight / 2) * sin(radians(i));

int xB = x + (r + rectHeight / 2) * cos(radians(i));

int yB = y + (r + rectHeight / 2) * sin(radians(i));

int xC = x + (r + rectHeight / 2) * cos(radians(i + rectHeight));

int yC = y + (r + rectHeight / 2) * sin(radians(i + rectHeight));

int xD = x + (r - rectHeight / 2) * cos(radians(i + rectHeight));

int yD = y + (r - rectHeight / 2) * sin(radians(i + rectHeight));


// Dörtgeni çiz

gfx->fillTriangle(xA, yA, xB, yB, xC, yC, color);

gfx->fillTriangle(xA, yA, xC, yC, xD, yD, color);

}


// Şekilli ibreyi çiz (merkezde geniş, dışa doğru ince)

int angle = map(value, minVal, maxVal, -135, 135);

int x1 = x + r * cos(radians(angle));

int y1 = y + r * sin(radians(angle));

int x2 = x + (r - 70) * cos(radians(angle + 5));

int y2 = y + (r - 70) * sin(radians(angle + 5));

int x3 = x + (r - 70) * cos(radians(angle - 5));

int y3 = y + (r - 70) * sin(radians(angle - 5));

gfx->fillTriangle(x, y, x2, y2, x3, y3, needleColor);

gfx->fillTriangle(x, y, x1, y1, x2, y2, needleColor);

gfx->fillTriangle(x, y, x1, y1, x3, y3, needleColor);


// Sıcaklık değeri gösterimi

gfx->setCursor(x - 10, y - 30);

gfx->setTextSize(3);

gfx->print((int)value);

gfx->print(" C");

}


void cerveveGauge(float value, float minVal, float maxVal) {

int16_t x = gfx->width() / 2;

int16_t y = gfx->height() / 2;

int rectWidth = 10;

int rectHeight = 20;

int r = min(gfx->width(), gfx->height()) / 2 - 20;


// Gösterge segmentleri

for (int i = -135; i <= 135; i += 10) {

uint16_t color;

if (i < 0) color = BLUE;

else if (i < 90) color = GREEN;

else color = RED;


// Dörtgenin köşe noktalarını hesapla

int x1 = x + (r - rectHeight / 2) * cos(radians(i));

int y1 = y + (r - rectHeight / 2) * sin(radians(i));

int x2 = x + (r + rectHeight / 2) * cos(radians(i));

int y2 = y + (r + rectHeight / 2) * sin(radians(i));

int x3 = x + (r + rectHeight / 2) * cos(radians(i + 10));

int y3 = y + (r + rectHeight / 2) * sin(radians(i + 10));

int x4 = x + (r - rectHeight / 2) * cos(radians(i + 10));

int y4 = y + (r - rectHeight / 2) * sin(radians(i + 10));


// Dörtgeni çiz

gfx->fillTriangle(x1, y1, x2, y2, x3, y3, color);

gfx->fillTriangle(x1, y1, x3, y3, x4, y4, color);

}


//needle

int angle = map(value, minVal, maxVal, -135, 135);

gfx->drawLine(x, y, x + r * cos(radians(angle)), y + r * sin(radians(angle)), WHITE);


// Sıcaklık değeri gösterimi

gfx->setCursor(x - 10, y - 30);

gfx->setTextSize(2);

gfx->print((int)value);

gfx->print(" C");

}




void cizgiGauge(float value, float minVal, float maxVal) {

int16_t x = gfx->width() / 2;

int16_t y = gfx->height() / 2;

int rectWidth = 10;

int rectHeight = 20;

int r = min(gfx->width(), gfx->height()) / 2 - 20;


// Gösterge segmentleri

for (int i = -135; i <= 135; i += 10) {

uint16_t color;

if (i < 0) color = BLUE;

else if (i < 90) color = GREEN;

else color = RED;

int xStart = x + (r - rectHeight / 2) * cos(radians(i));

int yStart = y + (r - rectHeight / 2) * sin(radians(i));

int xEnd = x + (r + rectHeight / 2) * cos(radians(i));

int yEnd = y + (r + rectHeight / 2) * sin(radians(i));

gfx->drawLine(xStart, yStart, xEnd, yEnd, color);

}


// neddle draw

int angle = map(value, minVal, maxVal, -135, 135);

gfx->drawLine(x, y, x + r * cos(radians(angle)), y + r * sin(radians(angle)), WHITE);


// Sıcaklık değeri gösterimi

gfx->setCursor(x - 10, y - 30);

gfx->setTextSize(2);

gfx->print((int)value);

gfx->print(" C");

}

RANDOM EYES

Ekran g&ouml;r&uuml;nt&uuml;s&uuml; 2025-02-25 213357.png
Ekran g&ouml;r&uuml;nt&uuml;s&uuml; 2025-02-25 213416.png
Ekran g&ouml;r&uuml;nt&uuml;s&uuml; 2025-02-25 213406.png


//DEMO

gozciz (1,90,-1,RGB565_BLUE); //-1 normal eyes 90 size

delay (1000);

gozciz (1,90,0,RGB565_BLUE); //left 90 size, 0 degree

delay (1000);

gozciz (1,40,90,RGB565_BLUE); //up 40 size, 90 degree

delay (1000);

gozciz (1,50,180,RGB565_BLUE); //down 50 size, 180 degree

delay (1000);


randomeye(); //random size and random direction

delay(400);


void gozciz(int goz,int boyut, int aci, int renk){

int beyaz=100;

int kx = 120 ;

int ky = 120 ;

//mavi,siyah merkez bulma -1 sa orta


if (aci != -1){

kx = (120 + (beyaz-boyut) * cos(aci * (PI / 180.0)));

ky = 120 - (beyaz-boyut) * sin(aci * (PI / 180.0));

}

//parıltı merkezi

int x = kx + boyut * sqrt(2) / 2;

int y = ky - boyut * sqrt(2) / 2;


if (goz==1) //sol

{

// Sol gözü çiz left

gfx->fillCircle(120, 120, beyaz, RGB565_WHITE); // Gözün beyaz kısmı

gfx->fillCircle(kx, ky, boyut, renk); // Mavi iris

gfx->fillCircle(kx, ky, boyut-20, RGB565_BLACK); // Siyah pupil

gfx->fillCircle(x-30, y+30, (boyut-20)/10, RGB565_WHITE); // Beyaz parıltı


}else{ //sag right

gfx2->fillCircle(120, 120, beyaz, RGB565_WHITE); // Gözün beyaz kısmı

gfx2->fillCircle(kx, ky, boyut, renk); // Mavi iris

gfx2->fillCircle(kx, ky, boyut-20, RGB565_BLACK); // Siyah pupil

gfx2->fillCircle(x-30, y+30, (boyut-20)/10, RGB565_WHITE); // Beyaz parıltı

}

}


void randomeyes(){

int ranboyut = random(40, 80);

int ranaci = random(0, 360);

gozciz (1,ranboyut,ranaci,RGB565_BLUE); //sag/sol goz,boyut, konum açı,renk

gozciz (2,ranboyut,ranaci,RGB565_BLUE); //sag/sol goz,boyut, konum açı,renk

}