Learning to use OLED displays

Examples, screenshots, graphics, fonts...
MaxZ
Posts: 159
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Learning to use OLED displays

Post by MaxZ » 15 Sep 2019, 12:35

Slight improvement, I changed the (simulated) readout variable "volts" to an integer, and this:
Schermafbeelding 2019-09-15 om 13.30.06.png
Schermafbeelding 2019-09-15 om 13.30.06.png (21.08 KiB) Viewed 447 times
now gives the correct string in the serial monitor. Still " ? Volt" on the oled screen though..... :?:

Edit:.......which offcourse is because I am trying to get the formatted string on the screen, and the float variable "voltsfl" on the serial monitor, duh.

So "sprintf" fails somehow, but why?
Last edited by MaxZ on 15 Sep 2019, 18:13, edited 2 times in total.

Martin
Posts: 320
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: Learning to use OLED displays

Post by Martin » 15 Sep 2019, 18:03

For perfomance reasons, float handling is not included in the Arduino's sprintf

Easiest way to do what you want is to use the Arduino's String class:

Code: Select all

  volts=1023;
  float voltsfl = (float)volts * calib;
  String s = String(voltsfl, 3); // the second parameter, 3, is the number of decimal places
  Serial.println(s.c_str());
the s.c_str() method converts the String, s to a "normal" string that you can pass to Serial or your graphics driver.

if you want to get it into a buffer you've defined yourself, say, str_volts[], you can use strcpy:

Code: Select all

  char str_volts[16];
  float volts;
  float calib = 1.0;
  
  
  volts = 4.1234;
  volts *= calib;
  String s = String(volts, 3); // 3 decimal places
  strcpy(str_volts, s.c_str());

MaxZ
Posts: 159
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Learning to use OLED displays

Post by MaxZ » 15 Sep 2019, 19:08

Thanks Martin. I have a little bit of a problem to get my head around this kind of string manipulation, probably because I do not know the difference between the "Arduino String class" and a "normal" string. The Arduino reference page describes it as "a C-style, null-terminated string", I guess that refers to C-language? (C++?) which I am not familiar with.

Anyway, I changed the sketch to this, and it works a treat, on the serial monitor and on the oled!
Schermafbeelding 2019-09-15 om 19.58.55.png
Thanks again, cheers,
Max.

MaxZ
Posts: 159
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Learning to use OLED displays

Post by MaxZ » 17 Sep 2019, 10:52

Hi all,

I know it could be risky, but it is too good an option, so I have to ask. The ProMini board I am going to use has pins A4/5/6/7 lined up on the end of the board, and I am wondering if I risk frying anything when I set A6 and A7 to high and low respectively and use those as gnd and vcc connections. I could then solder the oled to those four connections with the mounting pins directly to mount it on the back of the ProMini.
From what I have read the current draw is less than 10 mA, so that should not be a problem. I could just try it, but I cannot oversee the consequences of the behaviour of those pins on power up. What do you guys think?
Schermafbeelding 2019-09-16 om 18.51.38.png

MaxZ
Posts: 159
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Learning to use OLED displays

Post by MaxZ » 17 Sep 2019, 13:04

Phil_G wrote:
17 Sep 2019, 12:37
It would be fine Max but A6 and A7 dont have digital circuitry (only A0 to A5 can be used as digitals) consequently you cant set them high and low for vcc and ground.
Since they are input-only, you could externally hard wire them to ground and vcc (3v3 in this case)
Ah, too bad...I was hoping to avoid the wiring to the vcc and gnd pins of the board, but it seems I am stuck with it. Vcc is the main problem, I have to wire it to the oled, to the pot that serves as voltage divider and keeping it available for the input wire and the power connection during (re-)programming. Oh well.... :roll: At least I can do the trick with a free digital I/O pin, right?

Btw, the picture is from the manufacturers website (RobotDyn), but I actually have their 5V 16MHz version.

Thanks, cheers,
Max.

FBMinis
Posts: 47
Joined: 25 Feb 2018, 17:59

Re: Learning to use OLED displays

Post by FBMinis » 30 Sep 2019, 13:08

Commenting for future reference :)

MaxZ
Posts: 159
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: Learning to use OLED displays

Post by MaxZ » 11 Jan 2020, 10:00

:D :D
DSC03954.JPG
DSC03956.JPG
Cheers,
Max.

(pssst, don't tell Rob, it's his birthday present ;) )

User avatar
Phil_G
Posts: 303
Joined: 15 Feb 2018, 23:32
Contact:

Re: Learning to use OLED displays

Post by Phil_G » 11 Jan 2020, 10:22

Thats brilliant Max I love it, it will make a great birthday present!

Post Reply