Bela people,
I'm trying to use a small several line LCD display which has a backpack that communicates via I2C. So I'm using the I2c.h library and I wrote the beginnnings of another library combining the needed LCD commands from arduino examples with the required I2c parts that I modeled after the few examples I could find of Bela programs using I2c. It now compiles and runs with no errors but sends nothing on the I2C bus lines. I checked the address using i2cdetect and when I run that check I can see activity on the bus lines but when I run my program see no activity on the bbus lines and so nothing happens on the display.
I'm not very experienced with C++ so any ideas or help would be very welcome. Here is the entirety of the code:
SunfounderLCD.h
#include <I2c.h>
#include <string>
class SF_LCD : public I2c
{
public:
SF_LCD (int bus, int address); // Constructor. brings in the bus and address
void clear();
void setupLCD(); // sets up things with display, cursor and blink all on
void writeLCD(std::string text);
private:
};
SunfounderLCD.cpp
#include <iostream>
#include <SunfounderLCD.h>
I2c myI2c; // creates an instance of the I2c class
// initialize LCD
SF_LCD::SF_LCD (int bus, int address) { // constructor for the LCD object
myI2c.initI2C_RW(bus, address, 0);
usleep(2000);
}
// clear LCD display needs to send command 0x01
void SF_LCD::clear() {
uint8_t buf[2] = {0x01, 0};
write(i2C_file, buf, 1);
usleep(2000);
}
// setup LCD with display on, cursor on, blink on, needs to send 0x0F
void SF_LCD::setupLCD() {
uint8_t buf[2] = {0x0F, 0};
write(i2C_file, buf, 1);
usleep(2000);
}
// write text to LCD
void SF_LCD::writeLCD(std::string text) {
int len = text.length();
char* buf2 = &text[0];
write(i2C_file, buf2, len);
}
render.cpp
#include <Bela.h>
#include <SunfounderLCD.h>
SF_LCD myDisplay(1, 0x27); // myDisplay I2C is on bus=1 addr=0x27
bool setup(BelaContext *context, void *userData)
{
myDisplay.clear();
myDisplay.setupLCD();
myDisplay.writeLCD("Hello!");
return true;
}
void render(BelaContext *context, void *userData)
{
}
void cleanup(BelaContext *context, void *userData)
{
}