• Hardware
  • is anyone successfully using i2c OLED / LCD?

please use backticks ( ``` ) and not ' to enclose your code

vivian if i were to try and plot this line to oled

The currently supported functions are the ones above and they show the few types of prints you can get currently. U assume they display some basic text only, but I don't have a working display at hand, did you try them out? To obtain anything other than that, you'll need to write some custom C++ code. The available graphics functions are here https://github.com/giuliomoro/OSC2OLED4Bela/blob/master/SSD1306_OLED.h#L151-L165

Looking at the names there, you'd probably to use drawPixel(). I don't actually know how to handle bundles in OSC neither from the Sc side or the C side, so I'll assume for simplicity that you are sending some float values and you want to show those, but there is definitely room for improvements!

For instance, I expect that if you add this to the body of int parseMessage(oscpkt::Message msg, void* arg):

	oscpkt::Message::ArgReader args = msg.match("/values");
    if(args)
    {
		const unsigned int nValues = args.nbArgRemaining();
    	float values[nValues];
    	for(unsigned int n = 0; n < nValues; ++n)
    	{
    		if(args.isFloat())
    		{
	    		args.popFloat(values[n]);
    		} else if(args.isInt32()) {
    			int i;
    			args.popInt32(i);
    			values[n] = i;
    		} else {
    			fprintf(stderr, "Wrong type at argument %d\n", n);
    			return -1;
    		}
    	}
    	// now tenValues contains the 10 values.
        // prepare a bitmap:
        printf("received: ");
        for(unsigned int n = 0; n < 10; ++n)
        	printf("%f ", values[n]);
        printf("\n");
        clearDisplay();
        for(unsigned int x = 0; x < SSD1306_LCDWIDTH; ++x)
        {
        	// we interpret each value as the vertical displacement and
        	// we want to draw a series of horizontal lines at the specified points
        	unsigned int valIdx = x * float(nValues) / SSD1306_LCDWIDTH;
        	unsigned int y = values[valIdx] * SSD1306_LCDHEIGHT;
        	drawPixel(x, y, WHITE);
        }
        Display();
    }

then you can send

~displayOSC.sendMsg('/values', 0, 0.1);

or

~displayOSC.sendMsg('/values', 0, 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9);

to display n horizontal bars which are placed left-to-right at a relative vertical positiony, as specified by each of the float arguments (range 0 - 1). If you pass as many arguments as the number of horizontal pixels in the display ( typically 128), then each bar will be one pixel wide. There must be a better way of doing this from Sc than specifying the numbers as comma-separated values and probably using OSC bundles it would be a better idea.

vivian do i use .asString to speak to OSC or .asRawOSC?

no idea, sorry.

vivian Window.closeAll;
w = Window ("gui", Rect(20,20,150,30))
.front
.alwaysOnTop(true);
~sliderx = Slider(w, Rect(20,20,150,30))
~sliderx.action({
arg obj;
w.view.background_(Color.black);
obj.value.postln;
});

I am not sure what this does, but it would seem it's trying to create a slider in a GUI? There's no easy way to have the Sc GUI mirrored on the OLED display. You'll have to send dedicated commands which are parsed by the C++ file and sent to the display.

    5 days later

    not sure what you mean with "plot a graph behind "?

      giuliomoro sorry, similar to this example where there are pixel plots behind the float pixels
      alt text

      also i cant find how i can change the thickness of the float pixels displayed

      Right, so this requires a bit more of work. The thickness of the pixel is always 1 (the drawPixel command writes one pixel at a time). Also, we transitioned to another library which is more flexible and works with more screens. Here it is: https://github.com/giuliomoro/O2O/ . You can run that example as it is and use /waveform to achieve the same that you are currently achieving with /values.
      Did you add any other code to the current version of the library?

        if you have an SSD1306 you'll need to replace this line in main.cpp:

        U8G2_SH1106_128X64_NONAME_F_HW_I2C_LINUX u8g2(U8G2_R0);

        with:

        
        class U8G2_SSD1306_128X64_NONAME_F_HW_I2C_LINUX : public U8G2 {
          public: U8G2_SSD1306_128X64_NONAME_F_HW_I2C_LINUX(const u8g2_cb_t *rotation) : U8G2() {
            u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2, rotation, u8x8_byte_linux_i2c, u8x8_linux_i2c_delay);
          }
        };
        
        U8G2_SSD1306_128X64_NONAME_F_HW_I2C_LINUX u8g2(U8G2_R0);

          giuliomoro this is weird but when i throw the zip in the ide and make the project and run the changed main.cpp i get this
          alt text

          5 months later

          aha! ran into the same issue.
          might be good to add that to the 'Using an OLED Screen' knowledge base page?

          also, for Github noobs such as myself, 'the latest dev branch' is somewhat vague.
          i'm assuming it's dev-i2c, but if that turns out to be the working one, it was still a lucky guess.

            also, allow me to type

            No rule to make target '/root/Bela/projects/O2O-main/build/

            for community searching purposes. i kinda lucked out finding this thread.

            so i got lucky 🙂 and got the ascii BELA logo on my screen. wonderful!

            i had to change the
            [connect 192.168.6.2 7562 (
            message box in the included local.pd file to
            [connect 192.168.7.2 7562 (
            for everything to communicate correctly.

            yay!

            Remork also, for Github noobs such as myself, 'the latest dev branch' is somewhat vague.

            I literally meant the latest dev branch: the current version of the dev branch, sorry fpr the confusion.
            I would discourage using dev-i2c for anything as it's only randomly occasionally rebased on dev but otherwise unmaintained

            6 days later

            tried updating to the latest dev branch over the IDE.
            that went wrong somehow, got a dropped IDE connection and no way to recover.
            trying the script method as we speak.

            edit: seems to have worked. yay.

            a year later

            so i'm trying to get an SSD1327 128x128 oled to work.
            updated the code on the board using the script method (again, IDE method failed).
            dropped O2O .zip on IDE, adjusted setup function to
            u8g2_Setup_ssd1327_midas_128x128_f
            it runs, i get the ASCII Bela logo, and i can communicate with local.pd.

            my problem is the display speed: if i runparameters, lfo'sorwaveformsfrom the example, everything slows down dramatically, where it feels like the display can't keep up with the data it's being sent.
            e.g. waveformssends data every 100ms, but that data gets displayed magnitudes slower.
            if i hitnumberafter one of the other functions it will eventually display a number, but only after it churns out every single change it was sent - and it seems to be chewing on that info for quite a long time.
            e.g. i hadlfo'srunning for about ten seconds, turned it off and hit display-text. that text would take over a minute to appear.

            i've a feeling the old OSC2OLED4BELA was faster, but maybe that's just me thinking everything was better when i was younger.

            is this to do with the library? am i the first one to notice this? any way to remedy this?
            i read about boosting the clock speed (post #57 of this thread) but not sure how to go about doing that, or if that is even the key to the issue. thanks!