Something went wrong while trying to load the full version of this site. Try hard-refreshing this page to fix the error.

is anyone successfully using i2c OLED / LCD?

php0614

Hi, does anyone have successfully managed to attach OLED or LCD monitor (such as 128X32 or 128X64 monitor) to Bela and also successfully drawn shapes, waveforms, etc.. ?

I know it is possible in theory, but I haven't seen any picture it is actually working.
Is it very difficult thing?


thetechnobear

Ive literally just got a 128x64 oled over i2c working in last hour or so ๐Ÿ™‚
see https://forum.bela.io/d/123-bela-displays-using-i2c-pins/42

I'm currently using the python library... as Ive not really any real time need,
to get it working from C++ is going to need more effort.


thetechnobear

heres you proof ๐Ÿ˜‰

alt text


lorrno

thetechnobear did you take this any further? any chance we could get a tutorial on how to hook it up?

I would love to do it but my electronic skills are super super basic (LED example style basic) and I'm very far from being a programmer (apart from PD where i feel at home)

I'd guess this is something that would interest most Bela users and that most of them have no idea on how to do it, a tutorial would be amazing


thetechnobear

@giuliomoro I've just been looking at the organelle code base , it also uses the same oled , so may be a good c++ lib to use.
(It's using spi but the i2c is very similar)



lokki

lorrno yes, i would also be interested in an OLED solution for the bela. i have a project in the finishing stages and i need to display lots of states for the ui. i am running out of digital outs with switches and leds :-) and it would be much more convenient to display everything on a screen...



thetechnobear

lokki or, @thetechnobear what are the limitations of the python approach, what are we talking about latency wise? i don't need a scope displayed, just some u.i. elements that change when pressing some buttons.

main issue would be the cpu/memory overhead.

I'll be honest, I didn't get around to taking it further, then it 'fell off my breadboard' (for other projects) , and since then I re-flashed by bela - so I need to get it all reconnected again.
now ive been doing some other stuff, id probably be tempted to use something like the library you linked too.


lokki

thetechnobear ok, thanks for the clarification. if you find the time to look at that library, that would be nice. but i understand if it is not a priority ๐Ÿ™‚


lokki

@giuliomoro could you quickly have a look at the library i linked to? i am willing to give this a try...

i assume i will have to make a separate thread to handle the calls to the OLED library functions, any ideas how much of an impact this will have on performance? are we talking dropouts, cpu spikes, mode switches?

thanks for some insights.


giuliomoro

giuliomoro replace the name of the function main() with oled_main() or similar

lokki this is a critical step: otherwise you will not be running a Bela program, but just the main() from the Oled's Main.c. That's why "adding some sound generator into render()" is a good idea: you will know if there is something wrong.


giuliomoro

That seems fairly straightforward, if it works. To test it:

  • connect the oled display
  • outside the Bela environment:
    • put all the files from the library and example in the same folder:
      I2C.h
      SSD1306_OLED.h
      gfxfont.h
      I2C.c
      SSD1306_OLED.c
      Main.c
      example_app.c
    • compile them and link them all together: gcc *.c -o oled
    • run the result: ./oled
    • it this works, keep going!
  • inside the Bela environment
    • create a new C++ Bela project
    • put all the files from the library in the project, but in Main.c replace the name of the function main() with oled_main() or similar
    • edit the render.cpp file as follows (untested):
      #include <Bela.h>
      extern "C" {
      int oled_main(void);  // declare the oled_main() function from Main.c
      }
      AuxiliaryTask oledTask;
      void* oledTaskFunction(void*)
      {
          while(!gShouldStop){ // run the content of the loop until the program stops
              oled_main();
              usleep(50000); // always sleep in a busy loop to avoid hogging all the CPU
         }
      }
      bool setup(BelaContext* context, void* userData)
      {
          Bela_createAuxiliaryTask(oledTaskFunction, 1, "oledTask", NULL);
          Bela_scheduleAuxiliaryTask(oledTask);
      }
      // optional: add some sound generator into render()
    • run and enjoy
    • The next step would be to replace the call tooled_main() with something in that reacts to some global variables that you would set inrender().
    • in combination with a Heavy project
    • you need a custom render.cpp
    • add there the same changes as above
    • use heavy's sendHook to set the global variables that affect the OLED output

giuliomoro

@lokki I added a usleep() in the while (!gShouldStop) loop above


lokki

giuliomoro thanks so much for this. will give this a whirl asap! in the meantime i realised that my OLEDs i have here are SH1106 based, so i ordered some SSD1306 models. will take a few days. the driver seems to be very similar, so maybe i can even rewrite the code to accept both OLEDs at some point.

maybe @thetechnobear can try with his display first :-)


giuliomoro

Other thing, I seem to see from their example application that they connect to bus I2c-2. That is the one where also the Bela codec is, and it's NOT the one that is broken out on the Bela cape. This is no big deal, assuming the address in use by the display is different from the one used by the Bela codec; but you may want to double check this.


lokki

giuliomoro I seem to see from their example application that they connect to bus I2c-2

good to know. although i had not even considered using the bela-cap i2c since i saw the pins in use on the photos and video.

hmm, but it should not be too much trouble rewriting the code to use i2c port 1, no? (just in case)


giuliomoro

it's this line here I think (as I did not dig deep into the code):

https://github.com/deeplyembeddedWP/SSD1306-OLED-display-driver-for-BeagleBone/blob/master/Example%20Code/Main.c#L37

    if(init_i2c_dev2(SSD1306_OLED_ADDR) == 0)

possibly there is a different function init_i2c_dev1(), or you can just replace whatever constant they have internally to point to the other i2c bus.


lokki

giuliomoro

the function is defined in i2c.c and it looks straightforward to change. which port is broken out on the bela cape? i2c-0 or i2c-1?

EDIT: found it in the doc, it's i2c-1


lokki

and, rewrote the function. it compiles fine btw. ๐Ÿ™‚

now, waiting for that display...(could take a few weeks, phuuh)


Next Page ยป