
M5Stack UiFlow for Beginners – Lesson 12 – Lego RC Car
So we scan the qr code on the device. Then it creates a link to the control page and then voila. We can control it and you’d be surprised how simple it is to create this remote control. Car let’s get started first up, let’s start to assemble the device. So this is what we get out of the 360 servo kit. We need both servos. We need the two wheels with their rubber rings around the outer edge and first we’ll attach wheels to both of the servos okay that’s good. Nwo. What we want to do is attach both of these wheels to the chassis, and we can do so with these little black pins. The typical lego, technic connectors so first we’ll pop a few of these into the chassis or into the motor itself and then pop them in to the chassis and i’m, putting it on the back here, okay and then we repeat the same for the opposite side and We’Re all good: now we can tuck the wires in underneath, try and keep it nice and neat, and then from inside the kit we’re going to need this servo to grove adapter. So we’ll grab one of these and then you can see on the connector. We have the letters g b and s so g is for ground, so the brown wire on the servo is ground. Once we’ve got the ground lined up, then all the others are in the correct position now to attach the m5 go from your kit or your m5 fire, depending on what you have to hand and we’ll slot that into the central hole on each side of the M5 coil base, Okk, now it’s sort of flopping on one side, Oczywiście, if you have a bunch of legos lying around, you could add an extra wheel, but my intention is with this kit to only use what we have available and it’s very possible to make A little car it drives around on a smooth surface without a third wheel, so let’s go back into our m5 go kit now and you’ll see.
We have our grove cables, which we’ll need to connect up to our motors so pop those in and then it doesn’t matter which ports you use on the m5 go. Zasadzie, you just need to remember that when you start programming in ui flow make sure to select the correct port which you’ve connected the servo to okay, I'll, try and tidy these wires up a little bit it’s a little bit messy. Oczywiście, we don’t want these wires. Trailing along the ground, slowing the car down so um. There is a little cable tie in the kit, so i’ll just grab that from the usb charger, and then we can just tie this up here. Make things nice and neat let’s! Hang it off to one side and there we go okay, Nwo, Jestem, just going to make a little bit of a frame that sticks out to the front just to raise the front of the m5 go up and we can use all of these small plugs that Are included in the m5? Go kit just slide them down there on the side. You’Ll have to take the wheels off so that we can put those longer bars in there, but they’ll just pop back on afterwards and there we go, looks a bit like a wheelbarrow or a rickshaw, or something like that, and do the same for the opposite side. Popping the wheel off put the girder on and then finally, we can use these smaller bars to basically act like stilts, propping the car up off the ground and repeat this step for both sides and there we have it all ready to go now.
Let’S get to programming, so we’ll need to remember that we should be in version 1.4.5 of ui flow, not the better version. There seems to be a little bit of a hiccup at the moment with the remote blocks, so make sure both your device is flashed with 1.4.5 firmware and that the website is on 1.4.5. We must use the website for this, as the remote function requires an internet connection. Okk, so let’s now go into units, go to the servo and select the ports that we connected it to remember. Port. The red port is port, a black port port b and blue port is port c okay and then first up we’re, going to do a little test program to test the duty cycle that we need to use to get our motors moving backward or forward, Itp. So i’m, just going to drag a button, a was pressed block and then another make it button b pressed and what i’ll do is basically set a variable um, which we’ll use to control the motors okay and then on our program start. We want to make sure that we set that variable to zero, so the motors don’t start automatically. Turning when we flash the program and then i’ll use button, a to decrease the value of that variable and button b to increase that volume, then we’ll drag a loop along create a text label because we are going to want to know the current value of that Variable so that we can make a note when we see our motors speed up or change from turning clockwise to anticlockwise and then also in that loop we’ll.
Add two servo blocks for each of the servos and then we’ll use the variable that we created pop it. In place there so that our button presses will control the speed of those motors, Okk, we’ll go ahead and flash that now let’s have a quick test of this okay. You can see now once i press the b button to increase the motor start to turn and if i tilt it to the side, you can see here. The left one is moving clockwise well, as the other one is moving counter clockwise that’s, simply because of the orientation of the motors they’re, both moving clockwise but they’re, set on a different angle to each other. So we’ll need to account for that. So we’ll keep hitting that b button to crank up the speed notice. The speed is increasing here, but it’ll get to a certain point where it starts to slow down. So if we want the car to move around at a slow pace, we can make note of that value, but let’s go all the way until the motors stop and you’ll notice. Now that once the motor is stopped, if we increase that value any further, we can see that the motor will start to rotate in the opposite direction and we increase and increase the rate again you see it starts to speed up now, so during this process, make Sure that you mark down the values of the motors and which value causes the motor to rotate in the desired direction, and then next we’re going to write our remote control program and input those values.
Okk. Więc teraz, once we finish with this program testing the monitors, we can either delete this or open a new tab and start to create our remote control program. Okk, i’ll create this variable again: okay and then i’ll add the units and then we’ll set both of those servos to zero on start. So this block what what it basically does is changes the duty cycle of the servo, so we’ll set these to zero, so they don’t start moving before we’ve started to control our vehicle, okay and then, if we scroll all the way down here, we can find the Remote blocks, Więc, if you like, you can set a title, something like lego, Rc, Samochód, okay and then in order to scan the qr code on our phone. We’Ll need to make sure that that qr code shows up on the screen. So we’ll pop that there and now we start to add in the remote buttons so there’s various features we have here. We have a switch button which is like a light switch. We have an on or off. If you wanted, you could add one of these uh but i’m going to go with these remote buttons, nie ma, also a slider which we could use to increase the speed or dim or brighten the rgb lights. There’S an example of that up in the demo section. Okay and then this final one is for displaying values, but we’ll go ahead and drag this one in here so i’m going to create four of these with each of the directions, and we need to remember that we have to change the index uh for each button.
That we add this will basically dictate which position in the list it appears at. So you might want to tweak around with these okay, but for this section, we’re just going to be focusing on the servos, so we’ll drag out those blocks duplicate these okay and then i’m gon na use the values that i’ve marked down. You can use the same as me um or you can choose your own values so that’s for going forward at a slow pace and for back. We just need to reverse those numbers so copy that change the servo to zero duplicate this one and for stop that’s, easy peasy. All we need to do is set it to zero, Okk, so for turning right, i’m going to duplicate this value here and for turning left same again and for turning left. The values should be like this: okay that’s, the basics done for our program. You can alter it and modify it as you like, but let’s go ahead and test. That best bet is to download it to the device. Now let’s have a quick test of this. How simple was that, and here we have a little remote control robot that can provide hours of fun, but we’re not finished there in future. Lessons we’ll have a look at how we can use sensors to combine with this robot to give it more functionality. If you had any issues with this lesson, make sure to leave a comment down in the comment section make sure to like subscribe and i’ll.
[compare_prices_deals]
Źródła
How about a video on how to build apps for the M5STACK without UI-Flow with something more appealing to coders like Python or C?