U 60 56 degrees of freedom, breakout board, which features a three axis accelerometer and a 3 axis gyroscope, so I’m going to be walking you through the entire implementation of this particular integrated circuit I’m, going to be showing you exactly which registers I’m pulling the data from Exactly exactly how to wire and write the software to be able to read the values, what to do with the values? What you can possibly modify in the program to kind of get something relevant more than just the pure raw data of the accelerometer and the gyroscope, and as a very quick demonstration of the data that’s currently being sent back to the hard we know serial port. You can look on your screen right now and, as you can see, you have the gyro readings in the grease, as well as the accelerometer readings in G’s. So let’s take a look first of all at the gyroscope. It is the speed at which you rotate above a certain axis, so imagine my z axis is going straight into the table. So if you look at your screen right now, those that is about 0.4 degrees or so so that’s the air that we’re getting as soon as soon as I start rotating the board. You see that number decrease because I’m going in a clockwise direction. If I go counter clockwise, that number is going to go up until I release the board. As far as the accelerometer goes, this is currently reading the g force that is being exercised by earth.
So once again, this is in the z axis. You have 1g going down. If I tilt the module along the y axis, you can see this force is being spread evenly at 45 degrees on the Y and the z axis so that’s, just a very quick demo reading some raw data and sending it back to the Arduino. This is still quite a bit of an intricate method, so I’m going to be discussing how I do it over I, squared C I’m going to be showing you the registers, as I’ve mentioned before, and walking you through the entire process. You can use this without any fear in all of your or any of your project. All right so let’s cover the connections. First, so very simple circuit. You have your power and your ground going to the breakout board, as you can see: it’s labeled as VCC and ground, followed by SCL and SDA pins. So these are going back to the Arduino Uno, two pins, a four and a five. If you refer to the picture that you have on your screen right now, those are the pins which are SCL and SDA respectively, on the Arduino, so we’re going to be configuring. Those for the I squared C communication later on in this in the software followed by the a d0 pin. So this is a pin once again, I’m going to be posting a reference in the manual which specifies the reason as to why it is pulled down to ground.
This is actually internally pulled down to the ground, but just to be safe, you want to pull it down as well. You can either pull it down or pull it up, depending on which address you are going to be using in your software and once again, I’m going to be making a reference to that once we get to that part. But it is important to know what your ad0 pin is in order to address this particular mpu, alright, so here’s, the software I have written for this particular tutorial. It starts starts off by including wire that H library. This is the library which is used for the. I squared C communication notice that this is the only library that I am using. There is a library available for the 60 50 MP you. However, it is very important to know how to access the registers on your own, therefore I’m, going to be explaining it from ground up without using that particular line. So the first thing I’m doing is creating three Long’s for the acceleration x yampz. Those are going to be storing the values or the data read from the MPU itself, creating three floats, which are going to be used to calculate the G forces acting in the three directions: long gyroscope XYZ, just as I mentioned this is going to be storing the Raw data read from the gyro of the MP, you float rotation, XYZ we’re, going to get into that a little bit further, but essentially is going to be storing the rotational speed or velocity around those axes.
In my setup function, very simple: serial dot begin 9600. I’M doing this purely for troubleshooting purposes and for demonstration purposes, you might be doing something different with your data wire. That begin, so this is the command that you will need to initialize your I squared C communication. Absolutely a must, before you start a reading and writing any data frame from your. I squared C enabled modules setup, mpu, let’s jump right to that function before we discuss anything else, alright. So the main purpose of the setup mpu function is to one establish communication with the mpu and number two set up all the registers, which we will be using in order to read the data back from the NP you into the arduino. So the first line is beginning by wire dot begin transmission at 0 B. 1. 1. 0. 1. 0. 0. 0. So what is this? What does this address mean? So this is the I squared C address of the MPU and I’m going to be showing you in the datasheet, where it is specified to be as such. So if you go to the datasheet itself in section 9.2, you’re going to have a section on I squared C interfaces, so obviously I screwed C’s a two wire interface comprised of signals. Serial data, sdn serial clock, SC l, which we’ve connected on our board right here. If you go down below, you will see that the slave address of the mpu is B, 1, 1 0, 1 0 0 X, which is 7 bits long.
So what is the? What is the X stand? For so the least significant bit of the 7 bit address is determined by the logic level on pen a d0. So if you remember there in our connections, you had a pin 8 D 0, which you connected to ground. If you followed my instructions, then your X will be equivalent to a 0, so this allows to MPU 6 0 X 0 SS to be connected to the same I squared C bus. So essentially, what they’re saying is: if you wanted to chain a second MPU, if you wanted to have a second reading, you would set this particular address to a high and you would be really easily able to integrate that as such. So when using this configuration, the address of the one of the devices should be be one one: zero one: zero, zero, zero, then 80. Zero is logic lobe, just like we did here, and the address of the other should be beef. 1. 1. 0. 1. 0. 0. 1, then 80. Zero is logic high, alright, so coming back to our program, the next a line is wire that right 0 X, 6 B as I’ve notated. Here it is accessing the register 6 B, which essentially deals with power management and c section or point 28. So let’s take a look at the data sheet which a rely which essentially specifies the register map and, as you can see, I have it pulled up right here.
So the register map for this mpu is quite extensive. On the left side, leftmost side, you will see the address of the register in hex, so that is exactly what we’re looking for. So if you scroll down you can you can look through these registers and I absolutely encourage you to do so kind of understand what they’re going, but essentially we are going to be first of all interested in the register. 6B. So let’s keep on scrolling down here. 6B, as you can see, there is a sleep mode. There is a cycle mode there as a device reset. The first question that comes to mind is how do you know that you need to work with this register in the first place and if you scroll down in the datasheet, you will see a note which tells you that the device will come up in sleep mode Upon power up so this is a very important note to kind of take care of, because you do not want to stay in sleep mode if you’re going to be constantly pulling the data from your device. So this gives you an indication that you should be going to the register 6e. So let me just quickly search for that and, as you can see, it brings us to this section 4.28, as i’ve mentioned before so here’s the description of the register and you will have the full data sheet that you can go through and it have a description For each and every single register on this mpu, so this register allows the user to configure the power mode and clock source.
It also provides a bit for resetting the entire device and a bit for disabling the temperature sensor, so that’s something to pay attention to. If that’s, what you want to do by setting the sleep to one the npu six oxo can be put into low power sleep mode when cycle is set to 1. While sleep is disabled, the MP, you will be put into cycle mode and cycle mode. The device cycles between sleep mode and waking up to take a single sample of the data from the accelerometer at a rate determined. So if you want to do something that is required to kind of only have a reading at a certain time or if you want to save battery power, if you have such an application, that is absolutely something that you need to look into so upon power up. The MP: u clock, source defaults to the internal oscillator. However, it is highly recommended that the device be configured to use one of the gyroscope gyroscopes or an external clock source. So if you want to use a different clock source, it is highly recommended by the datasheet, but we’re not going to be dealing with that right now. So our goal is to pretty much set all of these bits to zero, to make sure that we are no longer in sleep mode. So let’s take a look at the write that we are doing so the write and I’ve simplified. You can do this in hex or you can do this in binary.
So when you want to do it in binary, you put a 0 B in front and then you write to the bits that you, like you write the bits that you want to write to this particular register. So imagine, first of all you have to select which register you want to write to, and then you write the value that you would like to write into that register. So, in this case, I’m, writing all zeros to make sure that we’re on the we’re, not in the sleep mode, we’re not in any of the external clock modes and followed by that I’m ending transmission. So once again, I highly encourage you to go through the shift register and make sure you fully understand what is going on there all right. So the next step in our function is to be setting up the accelerometer and the gyroscope parameters and where these values are coming from are from the datasheet. So let’s go back to the datasheet and take a look at the features of the gyroscope as well as the accelerometer. So, in the first line of the specifications you can see that there is a digital output, XYZ axes, angular rate sensors with a user programmable full scale range of plus minus 250 plus minus 500 up to plus minus 2000 degrees per second for the accelerometer. You have a similar line which says that there is a digital output based on a programmable full scale range of plus minus 2 G’s up to plus minus 16 G’s.
So what does this really mean? Is that you will need to select a range so let’s start with the gyroscope? You have plus minus 150 up to plus minus 2000, so let’s very quickly. This discuss these numbers so, first of all, it is in degrees per second, and what this means is that your module will be able to detect how many degrees per second of a rotation are you doing around this particular axis, so you can read it about the 3 axis, if it’s doing a weird rotation, but if it’s only about one axis, you can detect that particular speed and what this boils down to is or what is the best setting for. You is essentially what is going to be the limit for your project and let me quickly break this down to you into something you can understand a little bit more so 250 degrees per second equates to 250 divided by 360 times 60, and this number is going To be in rpm, so imagine you are doing 250 out of 360 degrees in a second and you’re, multiplying that by 60 seconds to give you a value in revolutions per minute, so 41.6 rpm. So what this really tells you or what the datasheet is telling you? If you select this particular setting so plus or minus 250, you will only be able to detect up to 41.6 RPM revolutions, and this is something to pay attention to because, depending on which setting you are going to use number one, you will either gain the RPM.
So at 2000, obviously you’re going to have a higher RPM let’s quickly do that math 2000 divided by 360 times 16, so 2000 divided by 360 times 60 330 3.3 rpm at this particular setting. So, first and foremost, you are going to be limited in your rpm, but also as you go higher up, there is no. There is a trade off, because if you refer back to a to the specification of the gyroscope, you will see that your sensitivity will be decreasing as you increase. The full scale range, so you need to be. Essentially, your goal is to select the most optimal range for your particular project and the way to go about this. If you know you have something that will be rotating at around let’s, say: 25 rpm. You want to go absolutely with the highest sensitivity you can get, so you would select plus minus 250. If you have something that’s rotating 300 rpm, then you must, or if you want to detect that range. You must select this particular setting so that’s, something that you want to pay attention to as you play with the registers I’m going to be mentioning in it in just a moment. The other thing that you also want to consider is: are you going to have spontaneous movements? Are you going to have a continuous reading of rpms, or do you even care? For example, if you have spikes over 100 rpm – and you can you know – you only want to detect if it is moving or not moving.
So all of that needs to go into consideration for your project, alright, so let’s get back to into the software and take a look at the next section which is going to be the implementation of the accelerometer registers. So, as you can see, it begins the same way wire that begin: transmission, 0 B, 1, 1, 0, 1, 0 0, which is the address of the amp you as I’ve mentioned a couple of times. I am going to be writing to the register 0 X, 1 C, so once you register I’m going to be taking a look in that on that register in just a moment and I’m going to be, writing all zeros to this value in order to set the Accelerometer to plus and minus 2 g’s, so let’s take a look at the this particular register. As you can see, it is the accelerometer configuration register. The description is the stressor is used to trigger accelerometer self test and configure the accelerometer full scale range. The register also configures the digital high pass filter where I’m going to be going into the self test settings in depth. But I encourage you to read up on them as you go along, but essentially you have 8 bits in this register. Just like you do for the gyroscope, you have a X, a underscore SD self test Y and the school’s self tests at a self test, and then you have the af s, select bits which, which are the ones that we are interested in.
If you scroll down this, you will see the AFS select, selects the full scale range of the accelerometer outputs according to the following table. So, depending on what you set those bits to 0 1 2 amp 3, you can select a different full scale range plus or minus 2, G’s, plus or minus, or plus, or minus 8 or plus or minus 16, and how you do that I’m, going to give You a quick demonstration so, for example, let’s say you wanted to select plus or minus 16 in binary. Your 3 is going to be a 1 1, so let’s scroll back up. You will need to set the bit and 3 amp. 4. 2. 1. 1. So if we go back to the program, if you want to set this to plus or minus 16 let’s, take a look, this is bit 0. 1. 2, 3. So 3 amp 4 will be set to a 1 1. So if you were to write this to your register right now, you would be setting the accelerometer full scale range to plus or minus 16 and G’s, just for the purposes of this demonstration, we’re going to be going with plus or minus 2. But I wanted you to know how to do that. Should you desire to use that particular setting for your project let’s very quickly, discuss what the accelerometer is actually reading on the amp EU itself. So what it is this detecting, essentially, is the forces acting on it in the three axes that we’ve discussed so X, Y Z and right now, because it is lying on a flat surface, the only force that is acts acting on it is the force of gravity Going downwards into the z axis of a 1g, for example, if right now I start moving this in the X direction.
I am exerting a force right so I’m exerting a force on this particular module and it will detect a certain certain force on the x axis. If I was to push it on the side, it would detect something on the y axis. One important thing to note that if you were to tilt something tilt the module, for example, you can you’re going to start acting that you’re going to start exerting. This gravitational pull on the x axis or y axis, depending on which way you tilt the module or both ways. If you desire to do so, but essentially you can calculate the angle from the purpose from the perpendicular to whatever angle from the g force. That’S that’s a very important thing to know I’m not going to go too much into trigonometry, but with a few sines and cosines you’d be able to figure out that particular angle. Should you desire to do so so that’s pretty much all for the settings of the accelerometer and that would terminate our setup MPU function so again, if you have any questions, any doubts feel free to post them in the comments down below alright, so scrolling back through Our software, through, where we left off so setup the NP, you should be fairly clear for you right now. We have the loop function, which is going to be recording the accelerometer registers, the gyroscope registers, printing, the data to the serial port and then creating a delay of 100 milliseconds, so let’s scroll down to a record accelerometer registers function and take a look at that.
The beginning of this function should be very familiar to you wire that again transmission. This is again the address of the MP. U yr that right, 0 X, 3 B, so the starting register for accelerometer readings. So what does this refer to? Let’S? Go back to our register map and look up 3 B I’ve referenced this before, but once again you should be going through this on your own and kind of looking at what you want to see, but accelerometer measurements so description. These registers store the most recent accelerometer measurements. Accelerometer measurements are written to these registers at the sample rate as defined and registered 25. So if you want to change anything there, you want to make it quicker slower feel free to do so. We’Re not going to be playing with register 25 in this particular tutorial. The data within the accelerometer Center sensors internal registers set is always updated at the sample rate, so feel free, like I said to play with that, as you need each 16 bit. Accelerometer measurement has a full scale defined in Excel underscore FS register 28 for each full scale. Setting the accelerometer sensitivity for LSB in Excel X out is shown in the table below. So I want to address what this really means. So as the example for this tutorial, I went with the plus or minus 2 G’s range as specified below and, as you can see, the LSB sensitivity is 16384 part G, so 16384 LSB per G.
So what this essentially means is that the value that you will get back from this register will need to be calculated to actually display you a number in G’s, so you will get so. For example, let’s let’s say you read something like twenty thousand from your shift register, which we’ve discussed here. You will want to obtain the value in G, so question mark G’s, for example. So this question mark is going to be calculated as such. You need to divide 20000 by your 16 3 8 or – and this will give you a value in G 28000, 16384, and this would be equivalent to 1.2 to G’s of force. Acting on that particular axis. So this is a very important concept, because a lot of people I’ve seen online are confused by what they are. They are getting exactly out of the accelerometer and gyroscope readings, but essentially you’re getting a value which you will need to translate to something meaningful to you. But this datasheet is specifying what this translation needs to be essentially so, depending on which full scale range you have selected. You will need to do a different division and calculation in order to get the correct value in G’s. So let’s take a look back at the program, so we’re writing to this register 3b and transmission, so we’re, essentially starting a register request so we’re writing something to the register and we’re ending the transmission and we’re requesting from the register again here.
It’S the address of the MPO and we’re requesting six of those registers 3b through 40. So if you refer back to the datasheet 3b through 40, the there are six of them and it’s X, X Y. Why is that zetsu? We will need to recombine the x yampz respectively, but essentially, while right, that available is smaller than six. We store the values in the XY and z values, so the first two bytes are stored in X, middle two bytes, our story and Y, and the last ones are stored in Zed. So very simple read function on our IC and, as I mentioned before, I am going to be processing the accelerometer data in order to get something meaningful, so process accelerometer data – and here you have the function which is doing exactly what I’ve explained on the paper right Here so it is dividing the reading that you get from the register by 16384 that’s zero to make sure that it is a long and not a truncated, two and in processing all the accelerometer data and getting that to a meaningful value for us. The next step is going to be reading the gyroscope register and this is I’m not going to be going in depth in this implementation. But it is exactly exactly the same thing as I’ve explained for the accelerometers. So why are that? Right 0, X, 483 and there’s going to be six bytes for this particular reading, as well.
So it’s going to be XY and Z for the gyroscope and then I’m going to be processing the gyroscope data very similarly to what it was with the accelerometer. Except that now we are dividing by 131 and you can refer to the either the datasheet or you can refer to the sensitivity. So, as you can see, it is LSB per degrees per second that you need to divide to in order to get the rotation in degrees, so that’s, something that you want to pay attention to. You want to get something that is meaningful and once again, if you have any questions post in the comments down below. And lastly, if you remember we’re calling a print data function which is going to be displaying all of our data, XYZ axes or the gyroscope, as well as the accelerometer, should be fairly explanatory at this point I’m not going to be going through this too much. But let’s take a look at what we are seeing on the serial monitor. So once again, as I’ve explained, we are currently getting all of the data from the MPU and we are translating that into degrees for the gyroscope and G’s for the accelerometer. So let’s first start again with the gyroscope and let’s create our rotation around this particular axis. So, as you can see, it is the y axis and it is changing from just a simple, zero or very close to zero it’s kind of oscillating back and forth.
A little bit but as I rotate up and down it goes all the way to to 250 and then goe goes back down, as you can see. There’S, no there’s absolutely no way for me to kind of make this go above 250, which was the setting that we had used for this particular register. Similarly, on the x axis, you can detect this rotation rotational movement and the same for the z axis and obviously you can do a combination of all three and you. You will be detecting something that you can process if you desire to do so. If you want to balance, for example, a quadcopter, if you want to do something like a plane balancing for example, scheme that is a very feasible for the accelerometer, as I mentioned, it measures the force that is acting on the MPU. So, for example, if I start bringing this up, you will see that the Z will go up and if I drop it, then it should go slightly below zero. I don’t know how noticeable it is, for example, does that if I start moving or jerking the the module back and forth and you you should be able to see that force. Similarly, as I mentioned before, if you tilt the module, you can see that the g force is acting right now on the x and the z axis. So what this allows you to do is to calculate the angle at which your module is being positioned and use that data, as I mentioned, to control a quadcopter to control an airplane and other applications like a robot arm.
For example, if you want to go that route, but you can very easily see that if both values are matched right, the force is equally distributed before between the two of your axes. That means you are at 45 degrees if it’s zero, then obviously it’s. Only in the side axes, if we put it on its side, let’s take a look so right now, all of the all the forces on the y axis, along with this module – and I believe I mentioned this – but there are markings on which axes are going in Which direction on the module itself, so it makes it very easy, very convenient for you to see and yeah. That would be all for the demo. I would like to come up with some projects for you. I am planning to do a stop kind of detection system with this particular MPU, but let me know what would what would you like to see where you’re going to apply this for what kind of other questions andor projects you would like me to address with regards With this to this particular module, thank you guys for watching.
arduino 6dof Video
arduino 6dof news
Posted on Tuesday April 28, 2015Build a Kickass Robot Arm: The Perfect Arduino Project for Beginners Lifehacker … Continue Reading »
Posted on Tuesday January 23, 2018Building A Better Kerbal Space Program Controller Hackaday … Continue Reading »
Posted on Thursday October 04, 2018Homebrew Linear Actuators Put The Moves On This Motion Simulator Hackaday … Continue Reading »
arduino 6dof Social
🔬 Now that you’ve gotten your feet wet, dive into the kit and enjoy all nine experiments. Order yours today: http://bit.ly/2MnQ7fr
Originally posted 2018-01-03 22:21:06.