Page 2 of 2

Re: Learning to use OLED displays

Posted: 15 Sep 2019, 12:35
by MaxZ
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 8518 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?

Re: Learning to use OLED displays

Posted: 15 Sep 2019, 18:03
by Martin
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());

Re: Learning to use OLED displays

Posted: 15 Sep 2019, 19:08
by MaxZ
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.

Re: Learning to use OLED displays

Posted: 17 Sep 2019, 10:52
by MaxZ
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

Re: Learning to use OLED displays

Posted: 17 Sep 2019, 13:04
by MaxZ
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.

Re: Learning to use OLED displays

Posted: 30 Sep 2019, 13:08
by FBMinis
Commenting for future reference :)

Re: Learning to use OLED displays

Posted: 11 Jan 2020, 10:00
by MaxZ
:D :D
DSC03954.JPG
attachment=2]DSC03956.JPG[/attachment]
DSC03956.JPG
Cheers,
Max.

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