Arduino Nano 33 IoT - Getting Started

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today in the workshop we're taking a detailed look at the arduino nano 33 iot an updated version of the original nano we'll see how to use the wi-fi bluetooth imu in real-time clock with some simple demo sketches we'll also look at some important differences between this board and the original nano everything's new around here today so welcome to the workshop [Music] well hello and welcome to the workshop or i should say welcome back to the workshop it's been a little while and what i've been doing in the gap between the last video and this video has been installing a lot of new equipment here in both the workshop and in the office outside of the workshop where i produce all of the videos and articles now this new equipment is eventually going to help me make more videos make them quicker streamline the process but at the current moment it's the opposite i'm learning to use all of this stuff some of these devices have instruction manuals that exceed 100 pages and photography and filming is not my field of expertise so i am learning a lot so i will apologize in advance for a few bugs and things that are bound to crop up in this video i know that the lighting inside this room still needs a little bit of work you're still getting reflections in my glasses etc but one of the upshots of adding all of this new equipment in addition to streamlining things has been that the channel is now at 4k so if you've ever wanted to see a resistor in really high definition then this is the channel for you now obviously a channel of this nature and electronics channel does not really need to be at 4k you could see this stuff just fine in hd in fact you could probably see it just fine in 720p but the upgrade to 4k also came with a number of advantages in terms of the capabilities of the equipment and sometimes even though you've got things working at a pretty good level it does make a lot of sense to move up to the latest greatest stuff in order to add a number of new features and that is my segue into the topic of today's video now we have an older device which is the arduino nano that we know and most of us love a device that is very similar to the arduino uno and it has been upgraded now it has been upgraded with four different arduino nanos and we're going to take a look at one of those nanos today the arduino nano 33 iot now as the name would imply this is a device that has been made specifically for iot projects but can also be used with a number of other different projects so let's go and take a look at this new arduino nano newer arduino nano it was released a couple of years ago and let's see what we can do with the arduino nano 33 iot the nano 33 iot is a member of the arduino nano 33 family other family members include the nano every the nano 33 ble and the nano 33 ble sense the nano 33 iot uses the sam d21g 32-bit microcontroller other members of the family use different microcontrollers this device has the same form factor and pin out as the original arduino nano you should note that this is a 3.3 volt device and it is not 5 volt tolerant so you can't just plug and play for the original nano the nano 33 iot has wi-fi and bluetooth capabilities using the u-blox neenah w102 module it also includes an lsm 6ds3 imu inertial measurement unit now here are the pin outs of the arduino nano 33 iot you will notice that these pin outs are identical to the pin outs on the original arduino nano however a couple of the pins have some considerations one of these pins is the v-usb pin this is the usb voltage out and it is generally 5 volts when the nano is powered by the usb adapter however in order for this to work you need to have a jumper on the bottom labeled vusb sorted out this has been done because the nano is a 3.3 volt logic device and so it's a safety consideration of not immediately sending out 5 volts another 2 pins to become aware of are the analog to digital converter 4 and 5 outputs as with the original nano these are also the sda and scl for the i2c connection however on the nano 33 iot there are internal pull up resistors because the i2c bus is internally used therefore these pins are not going to be very good as analog inputs you should also note that the same pulse width modulation capable pins on the original nano are also pwm capable on the nano 33 iot wi-fi and bluetooth capability is provided by the u-blox nina bluetooth and wi-fi module this module is based upon the popular esp32 chip it provides both bluetooth and bluetooth low energy 4.2 and wi-fi at ieee 802.11 b g or n this device has an internal 2.4 gigahertz antenna and no provision for connecting an external antenna the lsm 6ds3 is an inertial measurement unit or imu this device has a 3-axis accelerometer it also has a three axis gyroscope the device uses the i2c bus and has a slave address of hexadecimal 6a this is the reason incidentally for the internal pull-up resistors on the i2c bus the processor at the heart of the nano 33 iot is a samdi 21g 32-bit microcontroller the same processor that we use in the cduino show this device runs at 48 megahertz it has a built-in usb connection so it doesn't require an external device for usb it features circom to allow for multiple hardware serial ports it also has an internal real-time clock the nano 33 iot is one of the arduino boards that is suitable for use with the arduino iot cloud so let's go and take a look at the nano 33 iot now here i have an arduino nano 33 iot board actually i have two of them this is how they come out of the box you get the board just unsoldered right now because it can also be used as a surface mount board and you also get a set of the dupont pins you can use to solder it it also comes with a warranty card over here and the most important thing of course is it comes with a number of neat little arduino stickers now i've got another arduino 33 iot over here that i've soldered up and beside it i've got a regular arduino nano just so you can see the comparison and they do indeed have the same form factor in fact you could take a device like this one which is just an adapter to let you connect screw terminals onto your nano and use it with the nano 33 iot so all of your prototyping tools that you used with this will be valid for this and they even keep the same pin out now let's take a closer look at one of these boards over here as you can see it's a very nice quality build as you might expect from arduino and on the back of the board over here let me turn this around so you can see it you will see over here we have a little jumper area and that is the v-usb jumper if you want to activate the v-usb which gives 5 volts out when powered by a usb connector you need to put a bit of solder over that but otherwise other than soldering the pins onto it it's ready to go and experiment with and so let's start experimenting with our arduino nano 33 iot okay now that we've taken a look at the arduino nano 33 iot it's time to start using this little module and the first thing we're going to need to do is to set up our development environment so let's go ahead and do that right now now in order to use the arduino 33 iot with the arduino ide you're going to need to install a new board and you do that via the boards manager so go up into tools and go down to where it shows you which board you currently have selected in my case it was an esp32 cam and go to the boards manager and now over here what we are going to need to install is the arduino samd boards now you can search for it up over here but you may notice it's actually the fourth selection down here on the list and so we just have to click install here to install this boards manager now after you've installed this another thing you're going to want to do is install a number of libraries if you recall the arduino 33 iot has a number of different features including wi-fi an inertial measurement unit and a real time clock and bluetooth and all of these will require libraries so we're going to do that with our library manager so we go into sketch and we're going to include library and go into our manage libraries to open the library manager now there are a number of libraries to install i'll do the first installation with you and tell you what other libraries you're going to need now for the wi-fi we're going to need the wi-fi neenah library so type in wi-fi neenah and that could bring the wi-fi nina by arduino library up over here and we can click install for that and our library is installed now as i said we have a number of other libraries to install you'll want to install the arduino lsm6ds3 library that's for the inertial measurement unit you will install the arduino rtc 0 library for the real time clock and the arduino ble library for the bluetooth and of course all of these libraries are listed on the article accompanying this video on the dronebot workshop website once you've done that we're ready to use the arduino ide with our arduino nano 33 iot now that we've installed our boards manager in our library it's time to test out our installation so hook up the arduino nano 33 iot to your usb port using a micro usb cable once you do you should notice this flashing light over here at the top and that is the built-in led on the board the equivalent of pin 13 on the arduino uno and it is flashing the blink sketch because a brand new device has been loaded with the blink sketch we're going to use the blink sketch to test our device but of course since it's already blinking the blink sketch we'll need to modify it a bit to make certain that our modifications are really being picked up so i'm going to change the timing on blink from a thousand milliseconds to 500 so it should cause it to blink twice as fast now you're going to have to have gone already into tools you're going to have to select the arduino nano 33 iot as your board and you're going to have to also select the port that you're connected to i've done that already so i'm going to upload this to the nano 33 iot and as i'm uploading you can see the lights flashing and there we go and we're blinking it twice the speed so we've succeeded in uploading the blink sketch to the arduino now 33 iot using the arduino ide now one way that the arduino nano 33 iot differs from the previous arduino nano is that it has integrated wi-fi another feature of the arduino nano 33 iot is it has a built-in real-time clock and while these two features may seem to be very distinct and they certainly are we can actually combine them and so we're going to look at both of them right now we're going to look at the wi-fi and then we're going to look at how we can use the wi-fi to set the time in our real-time clock so let's get started in order to test out the wi-fi capabilities we're going to run a simple sketch called scan networks now as the name implies this simply scans for all the wi-fi networks in the area so you don't have to give it any parameters because it's not connecting to any of these networks now this sketch is available as one of the example sketches that came with the wifi nina library i found it a little odd as to where it was located so i'll show you where that is you can go to examples and if you go down through examples you will actually see wifi nina down over here it is not considered an example from a custom library so just to be on alert for that and if you go down over here you will see our sketch and that's the scan network sketch over here i've got it open on the screen right now and it's a pretty simple one really what it does is it installs the libraries now one thing i want you to notice is that aside from the wifi nina library it also installs the spi library and we need to use that because the u-blox module is actually connected to the processor via spi so every time you use wi-fi with this board you'll also need the spi library you don't need to define the connections though because the wi-fi neenah library will take the care of that for you essentially we're setting up the serial port because we are going to display this on the serial port we're checking the wi-fi firmware printing the mac address and we're going to go into the loop over here right now where we just scan for networks and we run a function called list network so the real action in our sketch is in list networks list networks is going to scan the networks it is just going to look at the number of available networks and it's going to iterate through those networks and for each one of them it's going to print the ssid it's going to print the signal strength and then it's going to print the encryption type now in order to print the encryption type it calls another function down over here and that just simply takes the encryption type and prints it into a more user-friendly format over here there's also a function down here to print the mac address in a format that is uh very readable and so we'll just upload this to the arduino nano 33 iot there's really nothing more to do that and then we just run our serial monitor at 9600 baud and observe the results here we go we're scanning the networks and as you can see i have a number of networks available to my arduino 33 nano iot of course they're all encrypted so i would need to know the encryption code for them now you'll notice on mine this is not an error i have three networks up over here called dbws net that is my network i'll leave it to you to decide what the dbws stands for and you'll notice there's three of them that's not an error i have a mesh wi-fi system so i have three different repeaters and what you're seeing is the relative signal strength of those repeaters now you'll notice that one of them is very very powerful and that makes perfect sense because it's right here in the workshop with me so it's literally about two meters away from the arduino nano 33 iot but this is a very simple method of determining that your wi-fi module is working and that you've got everything connected correctly and now we can go and do some more interesting things now here's a very simple sketch we can use in order to connect to our wifi network using the wifi nina library and what the sketch does really is it illustrates how we use this library we'll start off by including that library as well as the required spi library and then we need to define our wi-fi credentials our ssid and our password ssid is your network name by the way after that we will go and initialize our wi-fi client now we've got a number of functions underneath here one of them is connect to access points and that simply connects to the wi-fi access point and here is basically how you do that you just do a wi-fi begin and then you pass your ssid and password you wait and you should end up getting connected now another function we have here is to print the wi-fi status over to the serial number and we're just going to print out the ssid and the ip address that we have been given by our router through the dhcp or dynamic host control protocol now we'll go into the setup and we'll show you how we set everything up we start our serial monitor we check the wi-fi status to see if it's okay as long as we have status we're fine otherwise we have to print out that the module has failed and then we call our connect the access point we'll call the print wi-fi status there is no code in the loop because everything is executed in setup so let's go and take it our serial monitor and we'll see what our wi-fi status is over here so i'm going to open my monitor we're connected and we have a wi-fi address that has been disked out by my router or in this case by my mesh network and so this is a very simple demonstration as how you can add wi-fi to your sketches on the arduino nano 33 iot now this is an interesting sketch in that it demonstrates both the operation of the wi-fi and the real-time clock and we're going to be using our wi-fi to set the real-time clock we can do that because our wi-fi signal has an embedded ntp service in it or network time protocol service and we'll use that to determine the current time and display that now the current time on the network time protocol service is actually not listed in hours minutes and seconds in date rather it is an epoch number an epoch number is the number of seconds that have elapsed since the 1st of january 1970 and this is how most unix and linux systems determine what time it is and so on our sketch we're going to start by loading up the libraries now we need the spi and wifi nina library we're also going to use this library as well to get that ntp signal and we have the rtc0 library for the real-time clock now you're going to need to provide your wi-fi credentials over here your ssid and your password now remember this all gets compiled before it goes to the arduino so it's not really a security risk you could also put these into a separate file and just call it from this file and some people like to do that and that's kind of handy especially if you're going to be distributing your code up to a repository like github where you don't want to tell the world your ssid and password and then after that another thing that you may need to adjust is this constant over here and that is your offset from gmt now i am in eastern time in north america so my offset is negative five hours yours of course will differ depending upon where you are in the world and there is a link in the article accompanying this video on the dronebotworkshop.com website that will lead you to a resource where you can determine your offset if you don't know it already now we just have a few functions over here to make things pretty print time this formats the way we print the time and print date does the same thing for the date now print wi-fi status is very similar to what we looked at earlier when we did the scan network we're just going to display that at the beginning when we start everything and print two digits is just simply a function that will add a leading zero in front of a digit if it is less than 10 and we need that in order for our times and dates to look pretty now in the setup we're going to start the serial port and we start the wi-fi establish a wi-fi connection and then we start the real-time clock we did we use this unsigned long to determine the epoch and we get the epoch over here using the wi-fi get time signal and then we print out what has happened over here if uh if we've got the epoch we print out the epoch received and what it is and then we go into our loop and our loop we just call our print date and print time functions we do a carriage return with a print lens so we leave a blank space over here and then we delay for a second and do it again so the net result should be we should just continue the print the date and time constantly now i've already uploaded this so i'm just going to open my serial monitor and we'll take a look at what we've got and it's already gone down to the loop where it is printing out the time now those of you who are very observant might notice the clock up here on my computer and the clock over here and you'll notice it's exactly one hour off and the reason for this is because if you'll notice it is may right now and we are in daylight savings time so we are indeed an hour off but this is a very simple method of showing how both the real-time clock and the wi-fi can work together and it might even be a practical project if you wanted to replace the serial monitor with some sort of a display you could have a clock that is always synchronized to your wi-fi network now one unique addition to the arduino nano 33 iot is the inclusion of an imu or inertial measurement unit now this is a relatively simple imu it can act as an accelerometer on three axises and it can also act as a gyroscope on those three axises it does not however have a magnetometer inside it so you won't be able to measure magnetic field however the library that comes with this imu is very easy to use and really simplifies the operation of this device so let's go and take a look at a couple of very simple examples for using the imu on the arduino nano 33 iot now to demonstrate the usage of the imu there are a couple of sketches that come with the library that we installed for working with the imu and that's the lsm 6ds3 library from arduino you can go and get those sketches just by going into file going into examples and once again it is just right here at the top arduino lsm 6d s3 and you'll see we have both a simple accelerometer and a simple gyroscope and as they imply they are very simple sketches because all of the heavy lifting so to speak has been done from the library so here's a simple accelerometer sketch and as you can see it includes the library sets up the serial port and then it prints out the acceleration sample rate which it gets from the library and then we go into the loop and we simply present the acceleration on the x y and z axis and print it out and again we use read acceleration from the imu library so the library really does everything for us now this is similar for the simple gyroscope as well if we go and take a look at that sketch you'll see it's essentially the same thing we set up our serial monitor we take a look at the sample rate and print it out and then we go and print the x y and z axis on the gyroscope with the read gyroscope command so these are two very simple sketches we'll upload both of them to our arduino 33 iot and we will take a look and see how they work now let's demonstrate our gyroscope we're going to use our serial monitor to get a reading back from it and as you can see we are getting reading of three different axes and as i move the device that reading will change i can rotate it and you can see the different numbers this is pretty fascinating although it's a pretty pretty difficult thing to digest with all these numbers coming in very very quickly so there's another way we can do that and that is to use the serial plotter so let's go and close the serial monitor and open the plotter because you can only have one at a time and as you can see the x y and z axis are now in the plotter and as i move everything it's a much more interesting and more graphical display than the one that we saw at the monitor and it's a little easier to digest how things are moving on the x y and z axis over here so a very simple demonstration of the gyroscope and it seems to work very well all right well the demonstration of the accelerometer is very similar to the demonstration of the gyroscope and here we have the three different axes on the serial monitor and i'll move the board and we can see the acceleration is really being displayed you can notice sometimes the values are negative and that depends on what direction i'm going in and once again this is more easy to digest if we use the serial plotter so here's the plotter the board is at rest right now i'm going to move it i'm going to move it and again i'm trying to accelerate with the board because it's acceleration not speed that it's measuring and again we can see a graphical representation of the acceleration on the three different axis so another example of how easy it is to use the imu on the arduino nano 33 iot now the final feature of the arduino nano 33 iot that we're going to be looking at today is the bluetooth capabilities and these capabilities are provided by the same u-blox module that provides the wi-fi capabilities and of course internally that is using an esp-32 device the bluetooth on the arduino nano 33 iot can act either as a peripheral or as a central bluetooth controller so let's go and take a look at a few examples of using bluetooth with this microcontroller now one very easy way to test the bluetooth operation of the arduino nano 33 iot is to use one of the example sketches and the one that we're going to use is one that scans for any bluetooth peripherals and i will show you where the sketch is and explain it a little more to you if you go down to file and you go to examples and scroll down to get to arduino ble now you'll notice it's divided into two different sections central and peripheral and the reason for this is this is how bluetooth operates with a bluetooth connection you have one device that is the central device and you have one or more peripheral devices that communicate with the central device now when you're using bluetooth the way you usually do with your phone or your tablet or your computer the phone tablet and computer is generally the central device and your peripheral device would be things like headphones or keyboards now we're going to go into the central for this particular one because we're going to scan for peripheral devices and it's the scan sketch over here and as you can see i've already got it open over here now what the scan sketch does is as you imagine goes out and scans for any bluetooth peripherals and there are a couple of parameters you want to bring back first of all you want to bring the peripherals address back every peripheral will have a unique address secondly the peripheral may or may not actually have a name and you can bring back the name and the third thing you want to bring back is one or more advertised services and this is how the peripherals in bluetooth work they advertise the services that they provide so for example a headphone might advertise that it provides an audio type service we're just going to scan through all of these things print them to the serial port and then go back and repeat so everything here is pretty well done in the loop as you can see the only library that we need to include is the arduino ble library so i've loaded that up to my our to my arduino nano 33 iot i'm going to go into the serial monitor and see if we can find anything here and i'll reset the board right now and it's discovered a few peripherals right now and it's given me an address and a local name for some of them it's still looking it's still discovering things it actually goes for quite a while to discover peripherals and there's ones discovered here i found this one amusing the bose revolve sound link i don't really think that's actually mine i suspect it's one of my neighbors because although i own several pairs of bose speakers none of them have bluetooth capabilities nor do i own any bose bluetooth headphones and so as you can see this sketch works very well for determining if we can see bluetooth peripherals and it also demonstrates the operation of the bluetooth on the arduino nano 33 iot our next experiment is actually going to require a hookup and we are going to require two arduino nano 33 iots our first one is going to be the central controller for our experiment and the second one is going to be our peripheral device you will also need a 10k resistor a momentary contact push button switch an led and a dropping resistor for the led which i use 220 ohms but you can use a similar value we'll begin on the central side and we'll connect the 3.3 volt output to one side of the push button we'll connect the 10k resistor to the other side of the push button and we'll connect the other side of that resistor to a ground point finally we'll connect data connection d2 to the junction of the resistor and the push button switch on the peripheral side we will connect output d13 to the anode of the led the cathode of the led will be connected to one side of the 220 ohm dropping resistor and we'll connect the other side of that to ground and this completes the wiring for our experiment now to run our demonstration obviously we're going to require two sketches one for the central device and one for the peripheral device and you can find those example sketches over here go into examples and then go down to the arduino ble and you will see it is divided into central and peripheral as we've noted before now in central you want this one led control and in peripheral you want the one called led i've got led control over here so this is the one that works on the central device so this one has the push button and it establishes a connection with the peripheral and sends information to it whenever the button is pressed now it's a reasonably simple sketch and it's fairly well documented so you can understand what's happening it includes the arduino ble library that's the only library needed and defines a couple of integers and constants here for the button pin and the button state and then in the setup we set up serial monitors we set the button pin as an input incidentally they could have written this to include the pull down resistor and you wouldn't have had to use it on your circuit board but since they didn't i added the resistor we initialized the bluetooth and we start scanning for a peripheral with this huge uuid and while that may seem rather cryptic you will notice on the led side that we use the equivalent address or the equivalent uuid now in the loop we check to see if bluetooth is available if it is we print out the address of the peripheral and everything so we're going through to look for the peripheral and we keep scanning and then we call this function called control led and we pass the peripheral value to it and that is really where the action on this sketch over here is this control led first of all does a number of things to make certain that you've actually connected to the peripheral and it needs to discover the attributes of the peripheral once it has discovered the peripheral with its attributes it's going to get the characteristics and it's looking for the characteristic again of this long string number over here if it does have characteristics we pass through this point over here so a lot of this is just checking to make sure that we have a good connection and this is the actual meat of what happens if we're connected we'll read the button pin over here if the state has changed then we know that the button state has changed and will print out button pressed to our serial monitor and then we go and we write the value to that led characteristic and we're going to write a value of 1 over here it's hexadecimal 1 but it's a 1 anyway otherwise when the button is released we're going to write a value of zero out to it and then print out if the peripheral has actually been disconnected down over here now let's go and take a look at the other side of it the led sketch now in the led sketch again we start a service off with this huge cryptic number so this is how the two of them mate with each other with the two uuids we send out the characteristic we advertise that we define a pin of course for our led and we're just using the led built in so you'll notice i've connected this to pin 13. you actually didn't need an led on the second one you could use the onboard one but i just think an external one is easier to see now in the setup we set up our serial monitor set the led pin as an output of course and we start the bluetooth and we set up our advertised local name and service because this is what a peripheral does it sets this up and then the controller tries to connect to it so we have a local name led we set up our advertised service and we add our characteristic to it and we start advertising all of this and then once we're all set up we go into the loop when we listen to see if we've connected to the central if we have connected to central we'll print out its mac address and then while the central is connected we will take a look to see if anything has been written to it into this switch characteristic and if something has been written we take its value now if the value is anything other than zero you remember we sent it a one but we could have been sending it to two or three it would have been fine we'll turn the led on by setting the led pin high otherwise if we get a value of 0 the led will go off and if we happen to be disconnected we'll print that down over here so most of the activity in this particular sketch happens in the loop so now that we've seen the two sketches let's go and take a look at a demonstration of them in action now here's a demonstration of our bluetooth central and peripheral devices and as you can see i've got them on two solderless breadboards one that i've labeled central one that's labeled peripheral so it's pretty obvious which is which my led here my push button there and if i push the button indeed it does control the led now the serial monitor i have right now is set up to the central one so it's just telling me the button is pressed the button is released i can go and change the port because i've used a usb hub to hook both of them to the computer right now so let's just go in oops and change the port here and now it comes out as the peripheral one and every time i press it of course we just get an indication the led is on or that the led is off so the demonstration itself is very elementary but it does show you how you can use the arduino nano 33 iot as both a central bluetooth controller and as a bluetooth peripheral device now one of the key features of the arduino nano 33 iot is a feature that i haven't really discussed today and that's its ability to be connected to the arduino cloud the arduino cloud is an internet of things service that arduino provides and a number of different boards have been certified to connect into the cloud and by doing that we can control these devices as iot devices now the arduino nano 33 iot is the only one of the new nanos that is certified for use on the cloud but rather than talking about it in today's video i want to do a complete other video and article about this because it is such a vast subject however if you're anxious to get started with the arduino cloud i do have some information in the article that accompanies this video which you will find on the dronebotworkshop.com website there's a link to that article right below this video when you're on the website please consider subscribing to my newsletter i send out newsletters occasionally just to let you know what's going on in the workshop and i'll be sending you one out in a couple of days explaining what i've been doing for the last month also if you want to discuss this video the place to go is the dronebot workshop forums it is ideal to discuss things on the forums as opposed to on the website or on youtube because then everybody can share in the knowledge and the forum is a collection of wonderful people who just love to talk about electronics and if you're not a member we would love to have you join there's a link below the video where you can find out how you can join the forum and of course it is completely free and finally if you have not subscribed to the youtube channel well what are you waiting for just hit that subscribe button and also click on the bell notification and as long as you have notifications enabled on your youtube you will get notified every time that i make a new video so until we get together the next time please take good care of yourself please stay safe out there and we will see you soon here in the dronebot workshop goodbye for now [Music] do [Music] you
Info
Channel: DroneBot Workshop
Views: 89,412
Rating: 4.9537139 out of 5
Keywords:
Id: KjETPxv_VR4
Channel Id: undefined
Length: 41min 39sec (2499 seconds)
Published: Sun May 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.