Arnov Sharma
Published © MIT

Raspberry Pi Pico Matrix Project

Made a Matrix Dev Board, which includes 100 WS2812B LEDs and MPU6050

BeginnerFull instructions provided1 hour119
Raspberry Pi Pico Matrix Project

Things used in this project

Hardware components

Raspberry Pi Pico
Raspberry Pi Pico
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Gerber File

Schematics

SCH

Code

CODE- Scrolling Text

C/C++
#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>

#define MATRIX_PIN 0 // GPIO pin connected to the LED matrix data pin
#define MATRIX_WIDTH 10
#define MATRIX_HEIGHT 10

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_PIN,
  NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS,
  NEO_GRB + NEO_KHZ800);

int x = 0; // Initialize position

void setup() {
  Serial.begin(115200);
  Serial.println("Matrix scrolling text display setup...");

  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(50);
  matrix.setTextColor(matrix.Color(0, 0, 255)); // White color for text
  matrix.setTextSize(1); // Ensure text size is appropriate
  x = matrix.width(); // Start cursor position at the matrix width
}

void loop() {
  matrix.fillScreen(0); // Clear screen
  const char *text = "Why don't scientists trust atoms? Because they make up everything!";
  
  matrix.setCursor(x, 0);
  matrix.print(text);
  Serial.print("Cursor X position: "); Serial.println(x);
  Serial.print("Text to display: "); Serial.println(text);

  int textWidth = 6 * strlen(text); // Calculate the width of the text
  if (--x < -textWidth) {
    x = matrix.width();
    Serial.println("Resetting cursor position.");
  }

  matrix.show();
  delay(110); // Adjust the delay to control the scrolling speed
}

Pixle Control Sketch

C/C++
#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Wire.h>
#include <MPU6050_light.h>

#define MATRIX_PIN 0
#define MATRIX_WIDTH 10
#define MATRIX_HEIGHT 10
#define NUMPIXELS (MATRIX_WIDTH * MATRIX_HEIGHT)

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_PIN,
  NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS,
  NEO_GRB + NEO_KHZ800);

MPU6050 mpu(Wire1);

int prevX = MATRIX_WIDTH / 2;
int prevY = MATRIX_HEIGHT / 2;

void setup() {
  matrix.begin();
  matrix.setBrightness(50);

  // Initialize I2C1 with pins 26 (SDA) and 27 (SCL)
  Wire1.setSDA(26);
  Wire1.setSCL(27);
  Wire1.begin();

  mpu.begin();
  mpu.calcOffsets(true, true); // Calculate and apply offsets

  // Display initialization success
  matrix.fillScreen(0);
  matrix.show();
}

void loop() {
  mpu.update();

  // Normalize accelerometer values
  float axNorm = -mpu.getAccX() * 5; // Invert X-axis sensitivity
  float ayNorm = mpu.getAccY() * 5; // Adjust sensitivity

  // Clear the previous pixel
  matrix.drawPixel(prevX, prevY, matrix.Color(0, 0, 0));

  // Calculate the new position
  int centerX = MATRIX_WIDTH / 2;
  int centerY = MATRIX_HEIGHT / 2;

  int newX = constrain(centerX + (int)ayNorm, 0, MATRIX_WIDTH - 1); // Horizontal movement
  int newY = constrain(centerY - (int)axNorm, 0, MATRIX_HEIGHT - 1); // Vertical movement

  // Update the matrix with the new position
  matrix.drawPixel(newX, newY, matrix.Color(255, 0, 0)); // Display influenced pixel
  matrix.show();
  
  // Update the previous position
  prevX = newX;
  prevY = newY;

  delay(20); // Reduce delay for smoother movement
}

Credits

Arnov Sharma

Arnov Sharma

308 projects • 306 followers
Just your average MAKER

Comments