Arduino Anxiety - Uno, 128x32 OLED and u8g2lib
Вставка
- Опубліковано 11 вер 2024
- The frustrations of getting a 128x32 pixel OLED working with the new u8g2 display library. Got there in the end though.
0.91" IIC I2C Serial SPI OLED LCD Display 128x32 3.3V/5V AVR PIC STM32 Arduino www.ebay.com/it...
Hello Julian, I just felt the need to say an extra thank you for this video. I am sure the frustration you felt has been the same for everybody playing around with arduinos. It was as if I was hearing myself when I encounter a programming problem. Keep them coming :)
Learning cool British expressions from your channel like 'dodgy' and 'faffing about'
Lee Oliver Right? I want a British accent in my videos... lol
igrewold Cigarette?
I always love to see arduino/oled/neopixel stuff on your channel. Looking forward to more of those videos!
Thank you so much for showing me this. I bought the same thing and was never able to get it going. It was sitting in my drawer for several months. I am a big fan of yours.
22 AWG solid core wire can swap for a female to female dupont in a pinch. Can completely empathize with your frustrations over the lack of immediate documentation that seems to loom all too often.
Absolutely lost it at the "I have no hair left" remark... as a programmer by trade, I can definitely relate...
But the smooth head, i mean code makes it all worth it right ?
Same -not a programmer but I laughed out loud when he said it hahahaha!
That error has nothing to do with C because it is a C++ error (C++ != C, the difference is not trivial). Regardless, what the error means is that the class you're trying to use (U8G2_SSD1305_128X32_NONAME_F_HW_I2C) is undefined. Having looked on the Github repo for u8g2, it seems the ssd1305 classes were only added to the header file about a month ago, so I'm guessing the version of the library you have simply doesn't have them.
Exactly. If you tried to declare a variable like
asdfg xyz;
You would get the error "asdfg does not name a type". It's expecting a type there (like int or some class name), but the name you put there is not the name of an existing type.
1:43 what a neat mnemonic! So D = 4th letter - yellow means 4. And hey, C = 3rd letter - orange means 3. That fits nicely.
this is the only tutorial that worked for me 7 years later, thanks
Great to hear!
I played with this same combination last week without ever having touched an OLED. The u8g2 wiki on github has all the info on making it work. The developer also has a thread on Arduino.cc forums.
I should probably have read all that before blundering around trying to get this to work.
But that would only be half as entertaining! Plus, we get to watch what *not* to do!
The "does not name a type" would indicate something was missing or not right in the ".h" file that describes the available constructor choices. Did you look at that file?
I usually just stick a small bit of solid core wire in the female end of a dupont connector if I need to convert it to male. Breadboard jumpers work great for this. Fits nice and snug.
"long winded explanations..." "I can't read all that!"
You're not alone man. "In a nut shell" is bliss.
a 'type' in C and C++ is any sort of 'thing' that you can make (one or more) variables of.
so int, float, double, long are all examples of types. In fact they're special kind of types in that they're so called 'built-in types', they're part of the C/C++ language definition.
Now what is nice about C/C++ is that they allow you to define your own types which is a pretty fundamental concept in C++. Typically this means you combine a number of those built-in types into a class or struct give that collection of types a name, and you've made yourself a custom type.
That U8_something_something_noname_something is an example of such a custom type, and you create (construct) a named variable (u8g2) of that type, or rather, you're trying to.
The error you're getting is the compiler telling you it sees you're trying to write something that looks like defining a variable (u8g2) of a certain type (U8_something_something_noname_something), but that it hasn't seen a declaration yet of that name as a type.
As you already found out now, the reason why it didn't find a declaration is that you were using an outdated version of the library that did not yet declare that name as a type.
---
What makes C++ particularly interesting is that you can create your own types, and then perform operations on those types just like the built in types.
So you could make a type named 'complex' consisting of a real and an imaginary part, define how all the operations on a complex type work, then write code like:
complex x(1.5, 2) // define x as 1.5 + 2i
complex y; // define y, no value (yet)
y = (x*x) + x; assuming you've defined and implemented * and + operators, this'll work.
this makes working with custom types a lot easier and more 'natural' than languages that don't have this ability. But yes. if you're not used to object oriented programming then this whole concept of custom types looks 'weird' and 'strange', and it really requires you to think about programming in a different way than you would compared to programming in a imperative language like assembler, basic, pascal, c, cobol ... (though basic, pascal and cobol now too have object oriented versions)
"What does it want!?", Is exactly me when working on OLED. They're my arch nemesis. Great video.
I like Arduino projects.
and 'other programming content'. Cheers ;)
I agree, the Arduino clone with the male/female header option is very handy. In fact I think I ordered mine after seeing you use them. Thank you Obi Wan Juliano!
Your "compiler" expects the first thing he sees to be a type. Like: uint8_t
So, you have to include a header file where U8G2_SSD1305_.... is declared. It's the type of your object.
Like you Julian, I find C++ very frustrating. If I can't find a code snippet, it takes me ages to sort issues out. You're not alone!
Thanks Steve :)
It's not C, that cause the problem, it is the u8g2lib. It is an awful library, it want's to be compatible with every display (and therefore very confusing) and because of that is pretty slow. Animations? Don't go with u8g. Try OLED_I2C for example, must faster and not bulky at all (if it is the chip is compatible). "Does not name a type" is a result of all the defines included in the u8g lib, if you define a display that doesn't match a define and/or compile conditions, the class will not be defined and therefore results in "Does not name a type" error. Again, it is not a C problem, it is an library implementation problem. The developer is able to let you know when you 'define' an unknown or impossible display type with a custom compiler error but did not implement this. Blame u8g, not C.
What is the size of the active area this display? In millimeters please
You could just use a male pin header, I found myself yelling!
I've got a couple of the slightly larger oleds on their way, not touched oled before so thanks for the intro. :)
For your female headers:-
Try getting some of those male headers with the extra length pins, and force the spacer down to half way along the pins. Should then fit nicely into the F-headers, with enough pin exposed for the F-duponts to fit nicely as well.
PS: use a vice to shift the spacer...
A bit late to the party but I always use orange for SCL, because a clock works on orange... sigh ;-)
Video length: 13:37, nice! :D
Ileet - pretty common misspelling ;)
I love this, I too share your pain with coding. Great video though, thanks for sharing it as one of these displays has just landed on my desk. You have done all the head banging against a brick wall for me!
The problem with unclear error messages is because of bad compilers, not bad language. If only they used Clang as the compiler in the Arduino toolchain...
It's probably saying that it doesn't know what to make of that line; if it's a constructor, or even an initializer call for a model, it should probably go in the setup() function. Where you have it, according to ANSI C, is a function prototype, but you've provided no implementation. Furthermore, the part in parentheses, "U8G2_R0", is incomplete; if this is the argument name, then it needs a data type, like int, char, void *, etc... (i.e. "UInt8 U8G2_R0" would tell the compiler that the argument name U8G2_R0 is a type of 8-bit, unsigned integer.)
i don't always not name a type, but when i do, i get compile errors.
Join the club!
No problems with 1.8.1 and u8g2 :)
And two things that got me as well:
1) The Wiki with constructors forgets to name a variable. Because of the long constructor/typedef and the fact the default in the examples is u8g2 as variable name I missed it...
2) And more of a Arduino thing, in library manager, you ONLY see the update button after selecting the library :/ Dohhhhhh
Thanks for sharing, tend to learn a lot just by following your train of thought👍👍
Some C developers get over enthusiastic about macros because they are resolved by the compiler.
Just in case anyone else has this problem be aware it can easily be a strict coding issue - my exact same problem was. Always a danger when altering someone else's code I miscounted curly braces!! That's all but it kept throwing up the exact same "type" error all over the place! Just make sure ALL your syntax is absolutely correct. Why a compiler of any worth can't do a simple check for matching braces I don't know. It can still happen but both the editor and the compiler do not make it easy to spot these kinds of stupid errors. That is a partial failing of the IDE, a partial failing of the compiler and a failure of the coder. A coder should be EXPECTED to fail however and the relevant tools SHOULD make ir easier to resolve.
A few people on this thread have already said the u8g2lib is a mess and I agree, and as an example you have to modify the LIBRARY EXPLICITLY JUST to handle 16 bit mode in order to handle line sizes of over 255 (it says 256!!)!! This should simply be a parameter passed during setup. NO-ONE, least of all a beginner should expect to have to hand edit an existing library - it pretty much defeats the object of the exercise!
BTW u8glib is now defunct, deprecated and no longer being developed - it has been replaced with u8g2lib - refer to Github documentation.
A lot of the time when I'm pulling my hair out, there's a good set of videos made by a guy called Julian Illet. He's stopped me going bald loads of times.
Hi, Can you find where the actual display chip is located. I disassembled one (just pcb and sandwiched glass panels) but can't seem to find any chip just voltage regulator. How does it really works? Thanks
so I've run in to the same problem before. basically `does not name a type` means `the thing you typed doesn't exist`. You can think of it like as if you had typed `flo4t a = 0.00`. You would get an error saying that `flo4t` does not name at type, because there is no such type.
What the line `U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(...)` does is creating a new C++ object called `u8g2` of the type `U8G2_SSD1306_128X64_NONAME_1_HW_I2C`. Basically the error means that the library doesn't provide a constructor for the 128x32 OLED using hardware I2C.
The error is definitely confusing, but I hope that helps.
Yep, it helps. I now know the problem is because I had an old version of the library installed. Doh :s
Oh really, i'll have to update mine as well.
Great video. Did you try to run the display without the library?
The problem isn't the elegant simplicity of C, it is the totally inelegant (and unnecessary) complexity of C++. Can you guess which one I like and which one I dislike? ;-)
Someone sounds like they don't realise how simplistic C++ is to use ;)
Ha ha, yes I can guess :)
If it were simple I would use it!
Nick B It is simple!
Long story short, your compiler doesn't recognize the object. e.g `inty var = 0;` is wrong. `int var = 0;` is correct. I would presume that the library doesn't support the OLED controller, so you'll probably have to write your own type or library.
Consult your datasheets for the controller chips and you'll need to write your own type. Looks like you found a type that is similar to what you need. You may need to modify the library's code slightly if you bump into a bug, but it seems to be compatible.
name a type? sounds like the "type" that you call for is either being comment out or simply missing in the header file of that library.
In Arduino 1.8.5 I don't see an option to download the u8g2 library. How can I manually import it?
Julian can you connect the display to your raspberry pi . I want to know if it works on a Pi zero
Arduino IDE's Library manager is frequently out of date Julian (verging on useless IMO). Check your U8g2lib.h against this github.com/olikraus/u8g2/blob/master/cppsrc/U8g2lib.h#L423
2.5.2 seems like a very old version as the changlelog says it's currently at v2.14 github.com/olikraus/u8g2/blob/master/ChangeLog
I think this is the 2.5.2 version github.com/olikraus/u8g2/blob/b4db8002ecaa30db99d1486c99c55db97c26f969/cppsrc/U8g2lib.h and it doesn't have the class that you are expecting.
I use PlatformIO for my library management. It's often much more up to date than the Arduino IDE's. PlatformIO also has the option of installing a more functional IDE along with its command line tools if that sort of thing tickles your fancy.
*// Code From New Version you wanted to use.*
class U8G2_SSD1305_128X32_NONAME_F_HW_I2C : public U8G2 {
public: U8G2_SSD1305_128X32_NONAME_F_HW_I2C(const u8g2_cb_t *rotation, uint8_t reset = U8X8_PIN_NONE, uint8_t clock = U8X8_PIN_NONE, uint8_t data = U8X8_PIN_NONE) : U8G2() {
u8g2_Setup_ssd1305_i2c_128x32_noname_f(&u8g2, rotation, u8x8_byte_arduino_hw_i2c, u8x8_gpio_and_delay_arduino);
u8x8_SetPin_HW_I2C(getU8x8(), reset, clock, data);
}
};
*// Code from old version you ended up using*
class U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C : public U8G2 {
public: U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C(const u8g2_cb_t *rotation, uint8_t reset = U8X8_PIN_NONE) : U8G2() {
u8g2_Setup_ssd1306_i2c_128x32_univision_f(&u8g2, rotation, u8x8_byte_arduino_hw_i2c, u8x8_gpio_and_delay_arduino);
u8x8_SetPin_HW_I2C(getU8x8(), reset);
}
};
P.S. Long time subscriber. Love the channel sir, keep up the good work.
Oh, my bad. You have to click the 'more info' link to see whether the library is up to date. Mine were not up to date. Thanks for that.
"does not name a type" roughly means that your expression has no "reference" in the library....or more easy: it does not exist in the library...
Thanks, helped me a lot to get started on Oled.
Hey, i wonder if you could try to strip bg from this oled display to make it transparent.
"does not name a type" - we've all been there...
It's a brave man who does the inevitable rant in public...
At least I was ...
Hi guys. Is possible to connect 3 displays to one Arduino board and each of these displays will show different text? Is possible to address each display somehow? Thank you very much!
if only arduino ide could have features of a real ide where you can right click and see where things are defined that would have helped a lot
Just finished getting mine running before seeing this video was up.
This is the constructor I settled on, was alreadin in the list
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA);
I also only found the SDA/SCL pins for the first tiome today, hadn't seen them because they were labled on the back, been using A4 & A5.
"I have no hair left." 9:39
Just think about what programming was like back in the days of key punch machines and card readers. I know, my age is telling because I learned programming before there was an IBM PC. Hair left while in college as a computer lab assistant.
I don't know if it makes sense to comment this video after 2 years and you probably already found this out. But the reason for your misformed fonts are not due to the NONAME type but your typo in the resolution. Look at around 9:20 in your video and you can see that you typed SSD1306_128X64_NONAME and not SSD1306_128X32_NONAME so because of that every other pixel line was missing...
Thanks Niclas. I think I spotted that in a follow up video, but it's difficult to remember :)
Lol look at these guys all ragging on C/C++ when the problem didn't have anything to do with the language itself...
Hi Julian and Others
I get this error with the nokia 5110 lcd on u8g2 library:
HelloWorld:52: error: 'U8G2_PCD8544_84X48_F_4W_HW_SPI' does not name a type
Any assistance will be much appreciated.
Thank you.
this is me every time I try to make my arduino do anything without just following instructions. but I had an idea to make a speed meter for my hamsters wheel with a little display to show how fast hes going and how far hes run and Im determined I will make it work
Hall effect sensor on the wheel - but do you measure the number of rotations per unit time, or measure the time per rotation? Decisions decisions :)
Im glad you said that because someone else said I should use a reed switch but I looked at some other peoples projects and both things on ebay and decided a hall sensor thing would be best and thats what I ordered
Couldn't you have just opened the header file and see what the proper constructor was?
Was t becasue you picket 1305 when it should have been 1306?
Julian,
At 10:06 when you show the Library Manager ug8lib does not list the SSD1305 as a supported display controller. Might that be causing the problem?
Yeah, maybe the library manager is giving me a false sense of security. I should maybe re-install the u8g2 library.
good video. including some of your own learning process can be very hlpful for others.
just one thing: get a breadboard! you wont regret it, even if you dont need it very often.
doesnt name a type=> arduino cant find the class in the library. just see if you can find where the classes are. then you can probably figure out whats wrong
I want screen upside down fonts in 0.91 OLED display (90 DEGREE FLIP) HOW CAN I DO THAT
An example of a type is char, int, double etc. In C a struct is also a type. In C++ a struct or class is a type.
To create an object (instance of struct or class) you call a constructor.
If you have a class called car an you want to create a Car and name it Bmw. :-
Car Bmw;
Car is the type.
Bmw is the name given to the object when you use it in code. Eg. Bmw.Brake();
If the Car class has a constructor that requires a parameter.
Create an instance like: -
Car Bmw(unlockDoor);
where unlockDoor is a parameter you pass to it.
so that huge long name is a type.
Can you make this scroll through an ebook?
Awesome tutorial.
Thanks
I want to put like 32+ of these together (2 groups of 16) mounted in a long consecutive horizontal pattern to display the individual names of audio track channels on my 32 channel audio mixing console which is commonly called a scribble strip. I want that along the bottom of the mixer. On the top of the mixer's audio meter bridge, I want to add color displays above each channels dB meter that display each channels spectrum analysis. Please help me with some ideas how to start. I need either one interface to control each thing, or several really small controllers I can install inside the mixer with being to obtrusive. I thank you in advance. These additions to my console would increase it's value and make it have similar features to a high end console.
I feel your pain. C has frustrated me for over 20 years. why can't I just write code in Pascal?
Because it's even worse?
learnelectronics I suppose you could port a cross-compiler for Free Pascal. Would be interesting.
Ah Pascal, happy memories of college. Fist proper programming experience, Apple][e then Turbo Pascal 1.0 on the classes only 386 PC (so much faster at compiling).
That's why I prefer MicroPython boards.
Can you display GIFs on it via node MCU?
coming at this for the first time, i didnt get the "does not name a type" problem but got instead a "u8g2lib.h no such file or directory" then tried to run other examples from the full buffer list as well as the Hello World one and got ( Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\Graham\Documents\Arduino\libraries\U8g2\examples\full_buffer\HelloWorld\HelloWorld.ino: In function 'void setup()':
HelloWorld:260:3: error: 'u8g2' was not declared in this scope.)
note to self: go learn librarries properly.
any guidance much appreciated.
Fortunately not a greenish OLED again huh
Is this even proper C? It seems like object oriented C. That's what I don't like about arduino libraries. They often use higher level languages along with normal C. But writing a library on your own takes ages and you start losing hair at an alarming rate.
Yeah, Arduino uses a mashup of C and C++
When it asks for a type it means that some variable isn't declared.. I.E. int,long.float.double char or struct.. Somewhere buried in the library usually.
So it seems the 128x32_NONAME constructors aren't properly implemented :/
Julian, how can they be? That begins with a number, that's not legal!
The full name is U8G2_SSD1305_128X32_NONAME_F_HW_I2C, I was abbreviating it :)
Yes indeed, the bloat of C++ even extends to naming, hehe!
Nick B That's user defined ;-;
Oh Jules :( I feel you buddy! Glad you got it sorted anyway! :O
Can you change the I2C address ?
Why didn't you just plug a male/male header into the Arduino then just plug your female Dupont jumpers onto that? :-)
Hi
I want use this oled to display temperature by sensor DS18B20
Please show how i can do it
hii Julian I like your o led project
can i connect The my smart phones Display with arduino
Does not name a type means C doesn't recognize the variabile type cos it's not defined in the library. When you write SOMETHING u8g2(...) you are declaring the variable u8g2 which is of type SOMETHING... that's the reason for that error ;)
That must mean that some of the listed constructors aren't actually in the library. That's where I came unstuck.
Julian Ilett That appears to be the case, if you send me where that constructor is listed I can look into the library code and submit a fix to the maintainer so that it won't happen in the future
No need to submit anything now, it was my mistake - update video coming soon.
Hello . big Clive mate here I like you're videos my brother
4?
Good job!
All variables/objects must be declared in C. That 128x32_NONAME constructor had not been declared in the library.
That's a trap for the unwary then, and I got caught in it :/
B R E A D B O A R D . U S E A D A M N B R E A D B O A R D
Please can you do a vid on transistors and how to flash an led? Love your videos! Thanks, Dai
How about this one: ua-cam.com/video/aEEZvnWLZrU/v-deo.html
Julian Ilett Thanks, but I was wondering how the single Led transistor set up worked, not the multivibrator. Cheers
Have an LED one side and a resistor on the other.
Julian Ilett Thanks!
Why not use Adafruit SSD1306 library ???
MadnessJoe , i've been using that library for those displays too for some projects of mine. it gives you 4 lines of text.
MadnessJoe , i've been using that library for those displays too for some projects of mine. it gives you 4 lines of text.
I use extra-long header pins to plug female jumpers into female headers.
I love your stuff, Julian. And of course I'm a subscriber.
Now, I have coded in C and C++ since the dawn of time, long before the war (Gulf war that is), and it was hard not to comment half way through the video. I've promised myself not to do that. Anyway...
The error you got means there is no type defined. Like if you tried
Julian_Ilett_type u8g2();
would give a similar error because "Julian_Ilett_type" is unknown, it doesn't name a type.
int i = 0; // int is a type and, so you can say 'int' names a type.
The big question is why you got that compile error. My best guess is that you have an old version of the library. If you look at github.com/olikraus/u8g2/blob/master/cppsrc/U8g2lib.h you find the definition at line 387. github.com/olikraus/u8g2/blob/master/cppsrc/U8g2lib.h#L387
So. class U8G2_SSD1305_128X32_NONAME_1_HW_I2C : public U8G2 does in fact name a type. The type is a class, and the name is U8G2_SSD1305_128X32_NONAME_1_HW_I2C. It's a public class and it derives from the class U8G2 (which is kind of a root class I guess).
Thanks Robert - spot on. I was using an old version of the library. Just uploaded an update video. Cheers :)
Yes, just finished that video. With a great deal of pride, I have to add. :-D
Will you do another Z80 video?
Yes, I have an idea for that ;)
make your own 4x current sensor using a lm324, icl7660, 4x shunt & 8x resistance pair in differential amp configuration. it wont be VERY accurate, but good enough.
I've got the ICL7660 ammeter kit on my desk :)
cool ! build it please ! :)
Hi julian
would love to see some vids for e-ink displays.
thanks
Funny you should say that ;)
holy shit, it has serifs!
Yeah, the font selection in u8glib and u8g2lib is awesome :)
Time for a lie down after all that faffing about?
Thanks for the videos. :-)
Good idea :)
COoL little display with a Good Guy price. Thanks for EXPOSING your sexy thang 👍😁. Cheers! 🇺🇸
What happens after 8:00 getting drunk, 8:00 being 8:00AM? After 8:00 in america we go to work.
Tea time! :-D
when is the next PIC Assembly Language Tutorials: please
Very soon - I have all the parts for that now :)
I have all the parts too and suitably modded :)
Lets go!
Damn that's good that we don't have transgender connectors, just male and female. Imagine chaos it would make if we would have all that imaginary genders...
"Apache attack helicopter pin" does have a nice ring to it though.
Akinaro 😂😂😂
There are hermaphrodite Connectors, like the SAE Connector ;)
fascist
Oh dear! Did you have a late night Julian? I know you have plenty of male header pin strips ... I've seen you use them. Next time just plug a bit of strip into the female headers and voila! Instant male headers. Bit more caffeine needed methinks! 😎😁
Now make it scroll so "World" can be read.
That's probably quite easy, but I'll be displaying a numerical value to show Amps measured by the INA219.
Robert Albert those ina chips (there are many of them with different specs) are great. Looking forward to see your project going on
Thanks Michael - my main concern is the rather high 100 milliohms shunt resistance. We'll see...
it's easy, clear the screen, write stuff, clear screen, write stuff at horizontal pos +1, clr, +1, clr,+1 ..... and round it up at the end.
You can change the shunt. There are also holes on those eBay INA219 standard modules where a wired resistor could be soldered in. But lowering the value also lowers the max current because this INA219 only can measure up to 320mV between the resistor Terminals I believe. If you can live with max 1,6 A than you could easily use 2 of the resistors in parallel. The gain of the internal amplifier can also be changed but this only helps to get better resolution and therefore lowering the max current. All of course relative to the used shunt resistor.
Well dodgy. Life's too short to read developer threads. I loved all the blundering and faffing about.
"Does not name a type" is an error every beginner programmer encounters at least a dozen times during his/her life. If you don't know why you're getting such a basic error, and are already *banging your head ferociously against the keyboard*, take a break. Go grab a cup of coffee and study. _What is C_? _What makes C++ different from C_? _C++ is object-oriented. What does that mean_? _What are pointers_? _What are object declarations_? Once you've studied all that, go back and try to solve the issues with your code. You probably meant to define a macro at the beginning of your code, but I won't tell you what was wrong with your implementation. Go search what is a preprocessor macro!
You can never have too many jumpers (fleabay 182047669137)