Hallo Zusammen,
als Anfänger grübelt man ja über viele Dinge, da man einiges noch nicht versteht. Ich kämpfe mich so ein bisschen durch die Materie, und das ist es ja auch was spass macht, allerdings habe ich für das folgende Problem bisher keine Lösung gefunden.
Ich habe einen Arduino Nano, der mehrere Sachen übernehmen soll. Das ganze soll ein kleiner Roboter werden, der sich aber nicht bewegen soll.
Die Matrix LED ist das Gesicht, hierüber werden die Augen angezeigt, er blinzelt, lächelt, usw... (läuft als progmem und millis, um Delay zu vermeiden) eine LED ist mit einem Heartbeat programmiert, diese simuliert eine Herzschlag. Ein Temp Sensor DHT11 (auch über millis) ermittelt die Raumtemperatur, und eine weitere RGB LED zeigt dementsprechend über die Farbigkeit die Temp an (Blau kalt, rot Warm,usw...). Außerdem wird die Temp in einem Oled angezeigt SH1106. Bis hier funktioniert alle sehr gut, allerdings würde ich auf dem Oled gerne ausserdem noch Textzeilen anzeigen lassen, die nach einer bestimmten Zeit wechseln, also nach 10-15sek. soll en andere Zeilen angezeigt werden. Wenn ich das allerdings mit in den Sketch einfüge kommt nichts sinnvolles dabei raus. Der Sketch wird zwar kompiliert, das Oled zeigt aber den Text nur abgehakt an, also immer nur ein paar Fragmente.
Ich hoffe, das ihr vielleicht einen Tip habt, was ich machen kann, oder ob das evtl. zuviel für den Nano ist? Ich bedanke mich schon im voraus für euer Feedback!
EDIT: Vielen Dank für die erste Starthilfe hier im Forum!!!
Was nicht funktioniert: Die Zeilen die den Code für das Oled beschreiben, also Quasi ab...
"const char s1[] PROGMEM =..."
Wenn ich den Teil alleine auf einem Arduino mit Oled laufen lasse, funtkioniert dieser Teil des Codes. Ich vermute mal, das ich entweder irgendwo nen Fehler mit eingebaut habe, oder das der Code vielleicht nicht so richtig mit dem Rest harmoniert.
Hier der Code...
#include <LedControl.h>
#include <HeartbeatLed.h>
#include <dht.h>
#include <Arduino.h>
#include <U8x8lib.h>
#include <Wire.h>
const int DIN_PIN = 7;
const int CS_PIN = 6;
const int CLK_PIN = 5;
HeartbeatLed heartbeat(12);
dht DHT;
#define DHT11_PIN A3
U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
int redPin = 10; // Red LED, connected to digital pin 10
int grnPin = 9; // Green LED, connected to digital pin 9
int bluPin = 8; // Blue LED, connected to digital pin 8
const uint64_t IMAGES[] PROGMEM = {
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000660000,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c400000660600,
0x0070800000660600,
0x0070800000660600,
0x003c400000660600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000333300,
0x003c420000666600,
0x003c420000cccc00,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000660000,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000cccc00,
0x003c420000989800,
0x003c420000303000,
0x003c420000606000,
0x003c420000616100,
0x003c420000636300,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x3c42000000666600,
0x4200000000666600,
0x0000000000666600,
0x00002a2e00666600,
0x002a2e2a00666600,
0x002a2e2a00666600,
0x002a2e2a00666600,
0x002a2e2a00666600,
0x2a2e2a0000666600,
0x2e2a000000666600,
0x2a00000000666600,
0x0000000000666600,
0x0000003c00666600,
0x00003c4200666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x0078840000333300,
0x00f0080000191900,
0x00e01000000c0c00,
0x0080400000030300,
0x0000000000000000,
0x0001010000800000,
0x000606000020c000,
0x001919000008f000,
0x0066660000423c00,
0x0066660000423c00,
0x0066660000423c00,
0x0066660000423c00,
0x0000660000423c00,
0x0066660000423c00,
0x0066660000423c00,
0x0066660000423c00,
0x0066660000423c00,
0x0066660000423c00,
0x0066660000423c00,
0x0066660000427e00,
0x0066420000427e00,
0x007e420000426600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x183c420000666600,
0x183c428181666600,
0x183c428181ff6600,
0x183c5285a1ff6600,
0x183c5ac5abff6600,
0x183c7addafff6600,
0x183c7effffff6600,
0x183c7effffff6600,
0x183c7effffff6600,
0x083c767cdbff6600,
0x083c663c99ff6600,
0x003c661899ff6600,
0x003c6610897e6600,
0x003c661000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
0x003c420000666600,
};
const int IMAGES_LEN = sizeof(IMAGES)/8;
LedControl display = LedControl(DIN_PIN, CLK_PIN, CS_PIN);
int ledState = LOW; // ledState used to set the LED
unsigned long previousMillis = 0; // will store last time LED was updated
unsigned long previousMillisDHT11 = 0;
unsigned long previousMillisu8x8 = 0;
const long interval = 1000;
const long intervalDHT11 = 3000;
const long intervalu8x8 = 5000;
void setup() {
delay(3000);
u8x8.begin();
u8x8.setPowerSave(0);
//u8x8.setFlipMode (1);
u8x8.setFont(u8x8_font_victoriabold8_r);
u8x8.drawString(0,2," Robi OS 3.5 ");
delay(2000);
u8x8.setFont(u8x8_font_victoriabold8_r);
u8x8.drawString(0,5," ##");
delay(200);
u8x8.setFont(u8x8_font_victoriabold8_r);
u8x8.drawString(0,5," #####");
delay(200);
u8x8.setFont(u8x8_font_victoriabold8_r);
u8x8.drawString(0,5," #########");
delay(200);
u8x8.setFont(u8x8_font_victoriabold8_r);
u8x8.drawString(0,5," #############");
delay(2000);
u8x8.clearDisplay () ;
display.clearDisplay(0);
display.shutdown(0, false);
display.setIntensity(0, 15);
Serial.begin(9600);
pinMode(redPin, OUTPUT);// Sets the pins as output for RGB LED
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
}
const char s1[] PROGMEM = " Weltherrschaft" ;
const char s11[] PROGMEM = " erobern in " ;
const char s111[] PROGMEM = " 3 Tagen..." ;
const char s1111[] PROGMEM = " Tolles Buch!!! ;)" ;
const char s2[] PROGMEM = "Test" ;
const char s22[] PROGMEM = " Test" ;
const char s222[] PROGMEM = " Test" ;
const char s2222[] PROGMEM = " Test";
const char s3[] PROGMEM = " Heute ist ein" ;
const char s33[] PROGMEM = " guter Tag" ;
const char s333[] PROGMEM = " egal was die" ;
const char s3333[] PROGMEM = " Realitaet sagt !!! " ;
const char s4[] PROGMEM = " Heute ist:" ;
const char s44[] PROGMEM = " der 76. Oktember" ;
const char s444[] PROGMEM = " oder war es der" ;
const char s4444[] PROGMEM = " 152. Maerzuar???" ;
const char *a[] = { s1, s2, s3, s4 };
const char *b[] = { s11, s22, s33, s44 };
const char *c[] = { s111, s222, s333, s444 };
const char *d[] = { s1111, s2222, s3333, s4444 };
void displayImage(uint64_t image) {
for (int i = 0; i < 8; i++) {
byte row = (image >> i * 8) & 0xFF;
for (int j = 0; j < 8; j++) {
display.setLed(0, i, j, bitRead(row, j));
}
}
}
int i = 0;
void loop() {
heartbeat.update();
uint64_t image;
memcpy_P(&image, &IMAGES[i], 8);
displayImage(image);
if (++i >= IMAGES_LEN )
i = 0;
delay(50);
{
u8x8.setFont(u8x8_font_chroma48medium8_r);
u8x8.setCursor(0,0);
u8x8.print("Temp:");
u8x8.print(DHT.temperature ,0);
u8x8.print("'");
u8x8.print(" Hum:");
u8x8.print(DHT.humidity ,0);
u8x8.print("%");
u8x8.setCursor(0, 2);
u8x8.print((class __FlashStringHelper *)a[i]); // print a sting (PROGMEM) via RAM array.
u8x8.setCursor(0, 4);
u8x8.print((class __FlashStringHelper *)b[i]); // print a sting (PROGMEM) via RAM array.
u8x8.setCursor(0, 6);
u8x8.print((class __FlashStringHelper *)c[i]); // print a sting (PROGMEM) via RAM array.
u8x8.setCursor(0, 8);
u8x8.print((class __FlashStringHelper *)d[i]); // print a sting (PROGMEM) via RAM array.
} //while ( u8x8.nextPage() );
unsigned long currentMillisu8x8 = millis();
if (currentMillisu8x8 - previousMillisu8x8 >= intervalu8x8){
previousMillisu8x8 = currentMillisu8x8;
i++;
if ( i >= 4 )
i = 2;
unsigned long currentMillisDHT11 = millis();
if (currentMillisDHT11 - previousMillisDHT11 >= intervalDHT11){
previousMillisDHT11 = currentMillisDHT11;
//digitalRead(DHT, !digitalRead(DHT));
int chk = DHT.read11(DHT11_PIN);
int t = DHT.temperature;
int h = DHT.humidity;
Serial.print("Temperature = ");
Serial.print(t);
Serial.print( "," );
Serial.print("Humidity = ");
Serial.print(h);
Serial.print("\n");
if((DHT.temperature < 50) && (DHT.temperature >= 23)) {
// Writing the LED colour pins HIGH or LOW to set colours
digitalWrite(redPin, HIGH); // RED
digitalWrite(grnPin, LOW);
//delay(10);
digitalWrite(bluPin, LOW);
}
if((DHT.temperature < 23) && (DHT.temperature >= 22)) {
// Writing the LED colour pins HIGH or LOW to set colours
digitalWrite(redPin, HIGH); // purple
digitalWrite(grnPin, LOW);
//delay(10);
digitalWrite(bluPin, HIGH);
}
if((DHT.temperature < 22) && (DHT.temperature >= 20)) {
// Writing the LED colour pins HIGH or LOW to set colours
digitalWrite(redPin, HIGH); // white
digitalWrite(grnPin, HIGH);
//delay(10);
digitalWrite(bluPin, HIGH);
}
if((DHT.temperature < 20) && (DHT.temperature >= 18)) {
// Writing the LED colour pins HIGH or LOW to set colours
digitalWrite(redPin, LOW); // BLUE
digitalWrite(grnPin, HIGH);
//delay(10);
digitalWrite(bluPin, HIGH);
}
if((DHT.temperature < 18) && (DHT.temperature >= 10)) {
// Writing the LED colour pins HIGH or LOW to set colours
digitalWrite(redPin, LOW); // BLUE
digitalWrite(grnPin, HIGH);
//delay(10);
digitalWrite(bluPin, HIGH);
}
}
}
}