Pi Pico and Arduino IDE

I have picked up a raspberry pi pico and instead of learning micro python I have discovered I can program with Arduino IDE.
I have wired my project using DHT11, DS1302, 3 buttons and max7219 8x32 LED.
The max7219 isnt displaying anything readable. I have buttons connected and the display changes when pushed. Some screens scroll from top to bottom, others random dots. I have rotated the display code but does nothing. I tried using 'max72xx.h' but the display didn't work but the 'LedControl.h' file at least displays something.

Below is my code

#include <DHT.h>
#include <DS1302.h>
#include <LedControl.h>

//DHT11
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

//DS1302
#define DS1302_SCLK 3
#define DS1302_IO 4
#define DS1302_CE 5
DS1302 rtc(DS1302_SCLK, DS1302_IO, DS1302_CE);

//max7219
#define MAX7219_DIN 6
#define MAX7219_CS 7
#define MAX7219_CLK 8
LedControl lc = LedControl(MAX7219_DIN, MAX7219_CLK, MAX7219_CS, 1);

//buttons
#define BTN_SCROLL 9
#define BTN_ADJ_HOUR 10
#define BTN_ADJ_MINUTE 11

void setup() {
  Serial.begin(9600);
  dht.begin();
  rtc.halt(false);
  rtc.writeProtect(false);
  
  lc.shutdown(0, false);
  lc.setIntensity(0, 8);
  lc.clearDisplay(0);

  pinMode(BTN_SCROLL, INPUT_PULLUP);
  pinMode(BTN_ADJ_HOUR, INPUT_PULLUP);
  pinMode(BTN_ADJ_MINUTE, INPUT_PULLUP);
}

void loop() {
  static int displayMode = 0;
  static unsigned long lastUpdate = 0;
  const unsigned long updateInterval = 1000;

  if (millis() - lastUpdate >= updateInterval) {
    lastUpdate = millis();

    switch (displayMode) {
      case 0: showTime(); break;
      case 1: showDate(); break;
      case 2: showTemperature(); break;
      case 3: showHumidity(); break;
    }
  }

  if (digitalRead(BTN_SCROLL) == LOW) {
    displayMode = (displayMode + 1) % 4;
    delay(200);
  }

  if (digitalRead(BTN_ADJ_HOUR) == LOW) {
    adjustHour();
    delay(200);
  }

  if (digitalRead(BTN_ADJ_MINUTE) == LOW) {
    adjustMinute();
    delay(200);
  }
}

void showTime() {
  Time t = rtc.time();
  char buffer[10];
  sprintf(buffer, "%02d:%02d:%02d", t.hr, t.min, t.sec);
  displayText(buffer);
}

void showDate() {
  Time t = rtc.time();
  char buffer[10];
  sprintf(buffer, "%02d-%02d-%04d", t.date, t.mon, t.yr);
  displayText(buffer);
}

void showTemperature() {
  float temp = dht.readTemperature();
  char buffer[10];
  sprintf(buffer, "Temp: %.1fC", temp);
  displayText(buffer);
}

void showHumidity() {
  float hum = dht.readHumidity();
  char buffer[10];
  sprintf(buffer, "Hum: %.1f%%", hum);
  displayText(buffer);
}

void displayText(const char* text) {
  lc.clearDisplay(0);
  int length = strlen(text);

  if (length > 8) {
    scrollText(text);
  } else {
    for (int i = 0; i < length; i++) {
      lc.setChar(0, 7 - i, text[i], false);
    }
  }
}


void scrollText(const char* text) {
  int length = strlen(text);

  for (int pos = 0; pos <= length - 8; pos++) {
    lc.clearDisplay(0);
    for (int i = 0; i < 8; i++) {
      if (text[pos + i] != '\0') {
        lc.setChar(0, 7 - i, text[pos + i], false);
      }
    }
    delay(200);
  }
}

void adjustHour() {
  Time t = rtc.time();
  t.hr = (t.hr + 1) % 24;
  rtc.time(t);
}

void adjustMinute() {
  Time t = rtc.time();
  t.min = (t.min + 1) % 60;
  rtc.time(t);
}

Did you test the hardware separately with RP Pico? so DHT11 + Pico, DS1302 + Pico... and so on? Are the separate projects works?

After testing a small projects, the time to combine all stuff begins.
Start from using DHT11 only, then add DS1302 and not going further until the both works fine... then try the buttons... and the LEDS

Yes, both sensors work and print to serial. The display works with examples but discovered for some reason my code doesn't like the LedControl.h file so went back to the MD_MAX72XX.h file and the MD_Parola.h file, adjusted code and good to go. Oh no RTC has a flat battery, so date and time won't adjust or update. A job for tomorrow.

Test the display separately with the Max72XX library's example code.

Yip got it going by doing that and adding a parola.h file too.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.