Slight improvement, I changed the (simulated) readout variable "volts" to an integer, and this:
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?
now gives the correct string in the serial monitor. Still " ? Volt" on the oled screen though..... Learning to use OLED displays
-
- Posts: 332
- Joined: 31 Jan 2019, 11:48
- Location: Boskoop, Netherlands
Re: Learning to use OLED displays
Last edited by MaxZ on 15 Sep 2019, 18:13, edited 2 times in total.
-
- Posts: 748
- Joined: 16 Feb 2018, 14:11
- Location: Warwickshire
Re: Learning to use OLED displays
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:
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:
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());
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());
-
- Posts: 332
- Joined: 31 Jan 2019, 11:48
- Location: Boskoop, Netherlands
Re: Learning to use OLED displays
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! Thanks again, cheers,
Max.
Anyway, I changed the sketch to this, and it works a treat, on the serial monitor and on the oled! Thanks again, cheers,
Max.
-
- Posts: 332
- Joined: 31 Jan 2019, 11:48
- Location: Boskoop, Netherlands
Re: Learning to use OLED displays
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?
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?
-
- Posts: 332
- Joined: 31 Jan 2019, 11:48
- Location: Boskoop, Netherlands
Re: Learning to use OLED displays
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.... At least I can do the trick with a free digital I/O pin, right?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)
Btw, the picture is from the manufacturers website (RobotDyn), but I actually have their 5V 16MHz version.
Thanks, cheers,
Max.
-
- Posts: 56
- Joined: 25 Feb 2018, 17:59
Re: Learning to use OLED displays
Commenting for future reference
-
- Posts: 332
- Joined: 31 Jan 2019, 11:48
- Location: Boskoop, Netherlands
Re: Learning to use OLED displays
Max.
(pssst, don't tell Rob, it's his birthday present )