So right now I assembled my LCD shield kit and the demos are working fine.
Next up, I wanted to write a simple program where I hard-code a bunch of strings which then get displayed on one line and get scrolled if too long (16 chars).
My code's working fine, but I can only manage to save like 3-4 messages without getting weird currupted memory problems (broken messages on the LCD included).
I'm new to embedded programming and have no real clue how to keep the messages out of the RAM.
Here's my code. It doesn't matter if I "save" the messages like this or if I loop through a char* list[] {...} array.
The following code is working fine and the 3 messages scroll endlessy (messages from slipsum.com for testing).
/* ATtiny85 as an I2C Master Ex2 BroHogan 1/21/11
* Modified for Digistump - Digispark LCD Shield by Erik Kettenburg 11/2012
* SETUP:
* ATtiny Pin 1 = (RESET) N/U ATtiny Pin 2 = (D3) N/U
* ATtiny Pin 3 = (D4) to LED1 ATtiny Pin 4 = GND
* ATtiny Pin 5 = SDA on DS1621 & GPIO ATtiny Pin 6 = (D1) to LED2
* ATtiny Pin 7 = SCK on DS1621 & GPIO ATtiny Pin 8 = VCC (2.7-5.5V)
* NOTE! - It's very important to use pullups on the SDA & SCL lines!
* PCA8574A GPIO was used wired per instructions in "info" folder in the LiquidCrystal_I2C lib.
* This ex assumes A0-A2 are set HIGH for an addeess of 0x3F
* LiquidCrystal_I2C lib was modified for ATtiny - on Playground with TinyWireM lib.
* TinyWireM USAGE & CREDITS: - see TinyWireM.h
*/
//#define DEBUG
#include <TinyWireM.h> // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos
#include <LiquidCrystal_I2C.h> // for LCD w/ GPIO MODIFIED for the ATtiny85
#define GPIO_ADDR 0x27 // (PCA8574A A0-A2 @5V) typ. A0-A3 Gnd 0x20 / 0x38 for A - 0x27 is the address of the Digispark LCD modules.
#define LCD_CHARS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(GPIO_ADDR, LCD_CHARS, LCD_LINES); // set address & 16 chars / 2 lines
void setup(){
TinyWireM.begin(); // initialize I2C lib - comment this out to use with standard arduinos
lcd.init(); // initialize the lcd
lcd.backlight(); // Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print("Setup OK. Start.");
}
int currentMessageNumber = 0;
void blankDisplay()
{
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 0);
}
void displayMessage(char* message)
{
int msgLen = strlen(message);
blankDisplay();
currentMessageNumber++;
lcd.print("Message ");
lcd.print(currentMessageNumber, DEC);
lcd.print(":");
lcd.setCursor(0, 1);
// Display message (and scroll it if too long)
char curItem[16];
for (int i = 0; i < (msgLen - LCD_CHARS + 1); i++)
{
for (int k = 0; k < LCD_CHARS; k++)
{
if (i + k < msgLen) {
curItem[k] = message[i+k];
} else {
curItem[k] = ' ';
}
}
lcd.setCursor(0, 1);
lcd.print(curItem);
if (i == 0) { delay(1000); } // To be able to read start of message
delay(350);
}
delay(2000);
}
void loop(){
currentMessageNumber = 0;
delay(1500);
displayMessage("Your bones don't break, mine do. That's clear.");
displayMessage("Your cells react to bacteria and viruses differently than mine. You don't get sick, I do.");
displayMessage("That's also clear. But for some reason, you and I react the exact same way to water.");
}
Now add the following lines and get weird results:
displayMessage("We swallow it too fast, we choke. We get some in our lungs, we drown.");
displayMessage("However unreal it may seem, we are connected, you and I. We're on the same curve, just on opposite ends.");
displayMessage("The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men.");
I'm pretty sure it's a problem with the 512K RAM, but how can I work around this problem?
My C++ knowledge is very basic unfortunately.
The binary size could hold like ~80 messages like this.