STM32 Microcontroller Experiments Livestream 5
Share
[[YOUTUBEVIDEOBOX(1QrJH0HB5LU)]] So, I'm going to, I have a thought. I'm not sure if you guys want to do this or not, but, and I'm kind of scared to do it. It's a, let's see. It is an update and you might not be able to see it. Well, here, let's see. Now, you can't see it. Let me see if I can move this. Huh. It doesn't show. Well, there's an update for the STM32 Cube IDE. And it might be helpful for some people to go to learn the update process, but I think I just lost the update. Yeah, I lost it. So, generally when you turn on or when you start the STM Cube for the first time, I guess maybe after a certain number of minutes or hours have passed, you'll get that little notification on the bottom right that there's an update. So, maybe I do that because it could help some people and I'm not getting it now. So, maybe later on in the stream, it'll happen and I can update it. Because, you know, the updates in the IDE, it's almost like installing the program all over again and it would be nice to show that. It would be kind of an experiment all on its own because you don't know what's going to happen in an update with the STM Cube. Because it is based, it is a layer on top of the Eclipse IDE. And things can break, I guess, but I'm sure it's been tested. But what I found is when you do an install, the project folder is kind of lost or it gives you the option to put the project folder into the next version of the software. Okay, cool. Let me do that. Let's go to Help. Thank you, Skeptic. Appreciate the heads up there. All right, Help. About. Installation details. So, let me look. I don't think I've ever done this before. So, this is the Eclipse. Eclipse.org IDE. Eclipse Modeling Project, the MX. This is the Cube MX, I guess. Eclipse PTP. I have no idea what any of this stuff is, actually. All right, so where would the Check for Update be? I guess it's one of these. I am afraid to do this. Let's see. I'm going to wait until the... Well, I see it. I see it. I see it. It's on the bottom. All right. I don't think you're going to be able to see this. Yeah, it doesn't show up on OBS, but it says Update Available. Updates are available for your software. Click to review and install updates. You will be reminded in four hours, but there is nothing to click here. Oh, wait. I just clicked on the box itself. All right. So, let's see. Can you guys see this? Yeah, you can see this. You see, even though, like, I say I'm afraid to do things, because I truly am and I'm doing this live, if I wasn't doing this live, I probably would just be clicking randomly or just going through it very confidently. But because I'm live, I know things can break and it could make for a train wreck. It could make for a very short stream. So, it's probably good for me to do this on stream. So, you can see sort of my mindset. I can sort of tell you my mindset while I'm trying to do it. Go for it. Yeah, let's do it. All right. So, we got the SPMCube IDE. I'm going to click this. I guess I could just select all, press next. I mean, it's not giving you much opportunity to mess up here anyway. All right. So, finish. And it also goes to show that, like, this whole thing with the bare metal, you know, I'm programming bare metal, bare chip programming, you know, just on something very low level. And if I'm afraid to do an update, it just shows you how, you know, you shouldn't be afraid to get into this, like, development, you know? At least that's the conclusion I'm going to give. I'm using the STM32F030R8T6. But if you just use the F030, that's probably enough. There are maybe different packages, like, different number of pins. I don't really know because I have to, I'd have to go back to the datasheet because the datasheet actually covers all of the versions of the F030. All right. So, I guess it's select all, trust selected. I guess I'm trusting everything here. Do I have a choice? Here we go. Trust selected. I'm trusting you. I should probably get out of this. I'm going to exit the S, yeah, well, it tells me to restart anyway. So, I'm going to restart it. I think it's Cortex-M0. At least I think I said that in one of my previous videos. Okay, so it looks like we, it's, it restarted. So, let's take a look. It still says 1.14.0, so I don't think it's actually changed. You can probably see that right here. So, I'm going to, oh, look at that. It opened something. I don't know why. All right, so I'm going to exit this and I'm going to, because this is the one that I'm using right now, I'm going to search for maybe what's installed, the latest installed. It still says 1.14.0 as the latest one that I have. Let me see if I can, and it didn't install any, let me see if I put something on. No, maybe it was just the cube monitor. No, that's not it. Huh. So, I've got the, yeah, that's the latest one. It's the one that I've been using. That's weird. Maybe it's an update on other parts of the STM32 cube IDE and not the whole cube IDE. Hmm, interesting. Not sure what happened there. All right, so let's go ahead and go in and see if it still works. I have not worked on USB drivers yet. This specific controller, I've done the USART where you use an FT232 chip and you can communicate using USB with that. But I haven't, this, you can find the STM32s with the USB built in and I'll probably go over that much later, but I haven't done that specifically, you know. Yeah, I'm unfamiliar with the RP2040. Okay, let's see. Let's go ahead and, anybody have any thoughts on what I should put on the display? Get a little closer here. Last time I ended with the inverting the pixels and we put it in the never ending loop just going back and forth inverting the pixels. So, that was the last command that we looked at is the pixel inversion command. Oh, interesting. So the RP, it makes sense, I guess, Raspberry, the Raspberry Pi. The RP2040 is the market controller for the Raspberry Pi and for the Pico. So that's, I guess, the smaller version. I was into Raspberry Pi a while ago when I was trying to think of ways to use the Raspberry Pi for, or as a CNC controller. And I was going to put a Linux distro on it and just use Linux CNC to control, but I didn't really follow through with that project. But I have like Raspberry Pi is just unused in my drawers. All right, so let's see, what should we put here? Who has a suggestion on what I should put on the display? I'll probably stop the blinking because that's probably going to annoy everybody. I'm going to go ahead and try to do a flash and see if it works. And it does work. Okay, so I'm not really sure what happened with that install. It didn't give me a new version. If anybody else has the... Oh, look at that. I have it inverted. So let me change that inversion. That was the A6 right here. And it says set normal display, so I'm going to rename this as... Pixel inversion command. So A7 is inverted. Or I should say A7 equals... Black on white. I can't do that. What would I call this? Anybody have any suggestions? A7 would be inverted, I guess. And A6 is normal. I was trying to be more descriptive, but that would be very difficult to do. So what does set multiplex ratio? I want to mix things up a little bit because it could get a little bit monotonous to just constantly talk about OLED over many sessions. I would like to go back and forth a little bit because for one, I think it sets... For at least me, it makes things more concrete when I don't do just one thing at a time. I would go back and forth to two different ideas. And then when you go back to the other idea, it kind of makes it more concrete because you're forcing your mind to exercise a little bit more. I don't know if that's a good way to say it, but what I'm thinking is trying to put the accelerometer ADC in the mix here in this program while I'm also working with the OLED. So we can learn how to use the ADC while we're trying to show something on the display at the same time. So I think that's what I'm going to do. If anybody has any objections to that, let me know. Pranjal asks, "How library or low-level programming?" Which one is good? They're both good. In my opinion, I believe that I personally like low-level register level programming because it's more comfortable for me. But Hal is going to give you a hardware abstraction layer, so you should use that when you know that you're going to be needing to change the microcontroller for the project that you're programming for. So if you're working for a company and they've decided to use a particular microcontroller, but maybe later on it doesn't have the features that it requires, then you may... If you're doing register-level programming, the features may not be compatible. They're generally going to be because the register level uses the same masks. They use the same macros and defines. But if, let's say, you're working with a microcontroller that has... Let me switch something here. If you're using a... Can you hear that sound in the back? The vacuum? Okay, let me tell that person to turn it off. Hold on a second. I really, really apologize for that noise in the back. I asked my wife to stop, and I don't think I was very nice when I was doing that, and I probably am going to have to do some apologizing later on, but I'm hoping she stops very soon, and I really do apologize for that. (Laughs) Yeah, well, I don't think she'd be wanting to do that. All right. I'm hoping she stops very soon, and I really do apologize. Maybe if I turn my... This way, maybe it makes it a little bit less, because it should be omnidirectional, and you should still be able to hear me. Is that better? I really like that question, though. I'm going to try to speak maybe a little bit louder so you can hear me. Yeah, she should stop pretty soon. She at least knows the urgency. Okay, earlier it was better? Okay. So I'll just go get back to this. (Music) So the question with the HAL and register level, I like that question because I think it is important to understand this, because... There we go. The hardware abstraction layer will allow you to change chips a little bit easier. In fact, it might actually be able to... Because I don't have any experience with this, but the way the HAL works is it works with the ARM architecture. And it may not even matter which chip, which manufacturer you go with. It shouldn't. Because the whole idea of hardware abstraction layer means that you shouldn't have to worry about the hardware. It is a programming layer above what hardware you're using, so it should just work with from one manufacturer to the other. I don't know if that's absolutely the case, but that's how I understand it. But for sure, if you're doing register level, you'll be... Unless you're using... Let's say if a microcontroller has three ADCs on it, or three I2C's. And you use the third one on a more advanced chip with more features, and if you try to go down like you need to save money on a lesser feature chip, and you're not using all the features of the other chip, you would have to change the program to use the I2C1 instead of I2C3, or maybe use the I2C2. So that's the only place where you're going to have problems, I think, in my opinion, with microcontrollers, and also the clock speed. So if something you require needs more than 48 MHz, for instance, you'll have to work with that limitation as well. How making programming easier? I think that's a little bit subjective, for me at least, because I learned using register level from the AVR series. Because when I learned AVR, and I learned the register level, I was easily able to get into the STM32 without a problem. I mean, it was like, switch the chip and learn just a little bit of the way that you work with the STM32, and everything else is easy. Understanding bitwise operations, shifting bits in registers and things like that, was relatively easy. How, I think because I started with the AVR, I didn't learn how. At that time, I don't think there was a how type of layer that existed for the AVR. So, alright, so, yeah, and it might make the programming easier because you have, well, if you've learned how in the beginning, it's going to be easy. But you still have to know the commands, you still have to know what parameters that go into the functions, you have to know the functions, obviously. And there's probably a lot of documentation, so it might be easier in that respect, finding information. I do know that when you're getting into, like, using LLMs to program, it wants to show you how programming rather than register level programming. You have to explicitly say, please show me a program in register level, and it will show you that instead of the how base, but it always goes how first. So, maybe that's an indication of where things are with the internet as a whole, because they're trained on the internet. And Prenjal is correct in saying what's going on in the microcontroller, but I still think you have bit level ability to change bit level in how as well. So, I think both are probably good. I don't think there's any reason to pick one or the other. Both are fine. It just depends, I think, on what you start with. And I've done how tutorials in the past. Another thing is when you're learning from the data sheets, or when you're learning from the reference manual, you learn the register level, because all of the program examples in the appendices are all register level. They don't have any how programming examples. So, I was kind of forced to learn register level just because I was learning through the reference manual initially. Yeah, I'm more apt to ask the LLM to program for me these days, because I like to... I think that's the way I learn from example, and that's the way I learned also from the programming references. Let me go ahead and change this display because it's kind of making me a little bit nauseous. I think I changed it to a6. So, it should just show the text and not the background. Okay, that's good. Now I can actually do a better focus on this. Alright, so let's change what's on the screen. There we go. Alright, that worked. All in yellow. Alright, so what do you guys think about the idea of mixing in the ADC stuff at this point, or should we just wait until we fully explain what the OALED is doing? And if anybody wants a review, I can probably do a review of what we've talked about so far. Let me go ahead and do that. So, we've gone over the... Well, let me start with the main. I'm going to do this as quickly as possible. We've talked about the system clock config. We are running in 48 megahertz. We talked about enabling the PLL clock to do this and the HSI. Or the... Actually, what is it? It is the HSI. And the I2C initialization, we went over enabling the alternate functions for the two pins that we're using. Right over here, the 58 and 59. Enabling it. This one I was unsure about what it was doing, but this is required because we're going into fast mode plus and I apologize for the dogs barking. My wife was outside. She was doing the vacuuming. And if she comes back inside, it's like the dogs haven't seen her in a year. And they're angry at her for leaving. And in here, we're managing how fast the I2C is going to be communicating with the OLED display. This OLED display apparently is able to communicate at 1 megahertz. Yeah, I can't catch a break, can I? Yeah. And you know, it's... Oh, Jesus. They're getting closer. Okay. So I was unsure while I was doing this... Well, I wasn't doing this programming. Claude was doing this programming. But I was unsure at the speed we can... I could communicate with the OLED. But fortunately, I was able to do the fast mode plus and which is above 400 megahertz or 400 hertz, 400 kilohertz. I was unsure if I could go above that because that's a... I2C runs either 100 kilohertz, 400 kilohertz or fast mode plus. And I'm not sure what fast mode plus, what the actual speed is, but according to Claude, at least, it's 1 megahertz. So I'm going with that. So this is required for fast mode plus, and this is enabling fast mode plus and using the Sys configuration, which is enabled here. Yes, 400 kilohertz. Yeah, 1 megahertz is the... is what is fast mode plus, I believe. Right here is where we're enabling the I2C, and we also talked about the write command or the write function, where it's using the address. It sends the address along with the data, and it specifies the length or how many bytes, which in... if you look at the reference manual, you'll see that that is a specification within that register for the control register. You can specify number of bytes, and it does everything essentially automatically. You just have to specify the length, making sure that you have a loop of that number of bytes, and it will automatically, essentially, transmit those bytes over the I2C lines. I did not add resistors, pull up resistors between these two lines, and that was a question in the beginning, because there... we already examined the back of this OLEB, and there are resistors already pulling those up. And I believe there are 10K resistors. Generally, what's recommended is 4.7K, but even in my past experiments, when I was... when I was connecting the accelerometer of like three or four years ago, accelerometer through I2C, I think it was actually about six years ago, I used 10K resistors, just like this one is using. Okay, let me read the comments. Bob says... oh, you're talking to Pranjal. Okay, yeah, nothing new here. Still don't have any chat in Twitch, so not capturing anybody in Twitch. I just put in the schedule for Twitch and to see if that made any difference, but nothing... Okay, so... so we've gone through the write, the OLEB command, which we're going through right now. So since we've already looked at the OLEB command and how that works, and it uses the I2C write, we started going through the OLEB command, but we took a break from that, and we looked at character creation. So we started out with how to create a character, one of the ASCII... one of the characters in the ASCII character set. And by the way, does anybody know the... what that acronym means? A-S-C-I-I? I knew this when I was like 10 years old. It's funny. When I was programming BASIC on the model 1, TRS-80. So this is how we determined how to form a letter. This is the letter A, actually. And it took a few iterations, but we figured it out. The first one was kind of gibberish, then the second one was upside down, or mirrored, and then the third one we got right. Yeah, ASCII. American Standard codes, I believe, for international interchange. I think that's what it is, if I remember correctly. As you can see, I'm not looking it up. That is completely useless information in my brain. Yeah, American Standard code for information interchange. I always thought it was international, because it does have international capability, but yeah. Information interchange. Yeah, I think I remembered that too. Oh, you looked it up. I was close. The information I didn't get right. All right. So that's the review. And then what we did was we did experiments with this. We would change these values to see what happens with the OLED, and we're continuing with that. And the last one we did was the A6. We tried A7, and it inverted the display. But Claude gave us some very obfuscatious information here, which just says set normal display. And that was not very helpful. So what is this set multiplex ratio? I haven't seen anybody say anything about wanting to go into the ADC stuff in this, so I'm going to go ahead and continue, unless somebody says otherwise. So set multiplex ratio. And that is also very not very clear, not very lucid. So let's take a look and see what we can find on the data sheet. So I'm going to bring the data sheet back up. This is the SSD 1306 controller. And if anybody wants to know, that's the controller that drives the display. It's not the display itself. It seems like it's out of focus. That's better. Okay, so let's take a look at what was the number here. It's A8. So what does A8 do? See what the actual definition is. All right, here we go. A8. I hope that's a good enough review for you. So set multiplex ratio. Set MUX ratio to N plus 1 MUX. So it looks like there isn't any variances here. You can't change the number. It's like this is what you get. So that's not something we can actually change. So let's see what the more explanatory explanation is. Yeah, so it looks like that's the only value that it will accept anyway. So do we actually need it? Maybe it's already default. We may be able to just turn that or just like not use that at all and see what happens. This command switches the default 63 multiplex mode to any multiplex ratio ranging from 16 to 32. So there must be a command right after that. Okay, so this is it right here. So this is setting that ratio. So we have one 64th duty. I'm wondering what that duty is a duty cycle. What is that? So 16 to 63. So 64, I guess is the max. Yeah, the SSD controller on the back of the OLED. I think that is yeah, you can't really see much back there. It's extremely thin, but you can see this, this set of cables generally on a let's see if I can find one. On a standard. And this is a see if I can get this as much on camera as possible. This is a standard LCD display. This is a 20 by four. So you have 20 characters by four lines. And on the back, you can see there are a bunch of chips. And there may be some more stuff in between, but I don't think there is. But this is generally the one of these is the actual processor. And the processor, it starts with an H. I can't remember what it is. But you look at the data sheet for the processor rather than the data sheet for the display because the size of the display doesn't actually matter. This is just RAM. The display is just memory addresses. And it's non volatile, I believe. So when you set it, unless you you turn it off and it'll disappear. But while it's on those that RAM stays on there and you can change the RAM addresses that's on the on the display. So if you had like a 16 by two or 20 by four, the addresses are actually the same. It's just where like you have a starting point and you just keep going and you may have characters like off the edge that you don't actually see. But it's still, you know, just because the display doesn't show it doesn't mean it doesn't actually hold it in their RAM. Or it may have internal controlling that doesn't allow to use that particular memory address. But probably the former, not the latter. The I squared C multiplexer. That's a good question actually because how does it convert from the SSD 1306 controller to I squared C and I believe the ice the SSD 1306 should have that built in already. Because the this document here already has commands for the I squared C and it shows information about I squared C. So I believe that's an option for this this specific controller, you could use this more like bitwise type of cable to program it. And you can see on this page, you can see the data zero through seven. That's very similar to how an LCD works. So, you know, you have the data pins, you have all these pins here and seven or eight of these are data pins, just like these eight here zero through seven. And you could just program it very in a very similar way to an LCD. All right, so that's probably more information than why I need to say about the controller on there. Okay, so this command switches default 63 multiplex mode and I have no idea what multiplex mode even means to any multiplex ratio. If anybody knows what multiplex means, let me know. So what what happens if I do change one of that value right now it's 164th duty. So three F is what what does three F mean and binary or in decimal, actually. So let's take a look at that. Yeah, this is the one I was using before. And we get advertisements at the same time. Look at that. See if I can bring that down. All right, now you can't see the advertisements. All right, so let's take the heck number of three F it was it was three F. Yeah, three F. All right. So that's 63. Okay, so what would happen if we change it to 1610? So what would happen if we change that to 10? What does does anybody know? Yeah, it's 128 by 64. That is correct. This display is 128 pixels across 64 pixels down. All right, I'm about to let me get closer, see if we can see anything interesting. I should probably put more more text down here just in case something happens at the bottom. Okay, then the 164th multiplexer displaying one of the 64 rows at a time. Okay, but what is what do they mean by 164th duty or what does Claude mean by because to me duty seems like duty cycle. So that's confusing already, you know, so let's see what happens if we let's I'm just gonna go ahead and press the play button and see what happens. So yeah, I want to put more information. So what else should I put in here? I was thinking about putting the names of the people in chat, but I don't know if you guys are okay with that. Where is this? Okay. I love Bob. Yes, let's do it. For sure. Okay. Third line. All right, I got a ha ha there. I can't do faces, but we could we could always create the emojis. But that would take a little while, as we know from the previous previous session. five? All right, what should be what should be on line number five? I will put out a fruit there. I like out of fruit. Give them a little bit of a shout out. I've always looked up to that company. They've been around since 2005. I started 2007. We kind of have a parallel upbringing, I guess. They're far more successful, obviously, than I am. But I've always looked up to their their stuff. They have so much information. It's just a beautiful company. All right, so funky bitmaps. Okay, we have to one more line to go, I think seven. So 01234567. Howdy. And I'll just put howdy because I know you're saying hello to. JJ or Hehe. Or Ha Hehe. I think it's probably Hehe. I don't know if I'm mispronouncing your name. I apologize profusely. Welcome and thank you for coming in and enjoying the the live stream. Okay, so I'll do howdy. Okay, I'm just randomly trying to put stuff on the display. So let's see what happens. Did I change it to 10? I did, didn't I? Okay, so let's see what the 1 16th duty or 1 17th duty because it was 1 64th before. Okay, look at that. It starts at the oh, this would be interesting to play with if I put this in a loop. And I wonder if it will update on the fly. This may not be one of those things that updates on the fly. You have to do that. You have to do this in the initial configuration. But it will be interesting to see what happens if I put this in a for loop and change it. Or change it as a for loop is going on. So I can put it in this main loop here. So let's attempt to do a for loop and you know how these these go with the me programming in C C++ fiasco train wreck. Alright, so this is the command. I'm going to put this here because obviously I think I need to set this up first and then specify the the duty. Whatever that means. Alright. Yes, very, very, you know, these things only cost what, five bucks. If it blows up, it blows up. It'll make for good content. I've never developed on the nuclear board, but it's not going to be any different from what I'm doing here. You're still with a nuclear board, you're still programming through like an STM or ST link type connection. I don't believe it's through. It might be I know if it's if it is not through an STM or ST link. The ST link may actually be integrated on the board. I'm not really sure. But it's pretty much the same thing. Yeah, no big loss. Even if I blew up my entire system here, even this chip, it doesn't really matter. I don't care. It's fun. It's fun. It's fun experiments. This is what this channel is about experimentation. Okay, it does. Yeah, so on the board, it has the ST link on it. So that's my guess was right. Cool. Alright, so who knows who remembers how to do a for loop? Let's see. For open-clothes parentheses, you have two semicolons. We have the ST link. So who remembers how to do a for loop? Let's see. For open-clothes parentheses, you have two semicolons. We have the initialization of a variable. And I'm going to initialize it to zero. At the end, it's the step. So we can increment it by one. As long as i is less than 64, but it actually has to start at 16, doesn't it? And then I'm going to use the brackets and copy this stuff inside and then make this I. Does anybody see a problem with this? Except for the wild spacing. Feranek, thank you for coming in. Hello, how are you doing? All right, thank you. Oh, yeah, there you go. Bob, thank you for the for the example code. Appreciate that. I think I'm getting better as I do these live streams. I'm going to start getting better at like programming this stuff because I am quite rusty. I mean, I've been having to focus on on CNC stuff for such a long time that a lot of this programming stuff and also I program C sharp. I my entire website is based on C sharp programming. I have probably many thousands, probably 100,000 lines in that program. Yes, let's see. Let's use a delay. You're right. Delay milliseconds. I believe I have that as a. Yep, it signed up as a as a bright yellow. So it looks like it looks like it would be right. So I'm going to do 300 milliseconds. That should be should be good, I think. We should get from 16 to 64 pretty fast. All right. Are we ready? Do you see any problems? I don't see any problems. Here we go. We are running. Oh, look at that. It's unfortunate we have to start at 16 though. That's pretty cool. You can see the the yellow up here. What if we attempt to go from one to 60 to 64 to 63 or from zero to 63. So does multiplexing make any sense in this case, the word multiplexing? To me, this looks like the start line. And if I was going to explain it in a data sheet, sure, an engineer would be able to explain it. He would probably want to use the right want to use the right terminology. It's very esoteric, but there should be some, you know, maybe that's the weed out. Maybe that's the weed out. You know, to keep people from from doing from entering this stuff, like unless they have a college degree. Huh. Power saving. Yes, because the in the data sheet, it specifies that you can only go from 16 to 64. So like over here, 16 to 63. Let's widen that gap. Let's go from let's go from one. I could go from zero, I guess, right? And let's just see what happens. What's the worst that can happen? Okay, let's try. I'm going to go with 63, 32 to 63 first. And go with what Bob's Bob states. Let's try it. Well, it's just going to start from the middle, I think. Yeah, it'll just start from middle. So it looks like it's starting from the 16th line and going up to the 64th line. That's why I kind of want to start from the number one line and see just to see what happens. Does anybody have any predictions? See, doesn't that seem like multiplexing doesn't seem like the right word for this? All right, let's try it. Check that out. So is the data sheet wrong? I'm going to go faster. I want to see what it looks like going a little bit faster here. 100 milliseconds. And I'll start from zero as well on the next try. Okay, so I mean, we could use this could be used as a as a reveal. And it's good to know that these commands can be changed. This command can be used on the fly. So like the ones we tried before, we couldn't do that. Or we didn't. I didn't know how to do that. So but we tried and it didn't work. So that was a fail. But this is a success. I think this is a win. I wouldn't call this multiplex. So I'm going to change the comment to start line. Because this multiplex ratio just doesn't seem right. This will probably also depend on see, look, this is set display start line. So and we were not able to get this to work correctly. Yeah, that's a good idea. Okay, let's do that. Bob is recommending it's good recommendation t