Arduino Nano RP2040 Connect - Arduino meets Raspberry Pi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today in the workshop we're taking a first look at the arduino nano rp2040 connect an arduino board with the raspberry pi processor we'll see how to set up the arduino ide to work with this exciting new board and how to use its onboard peripherals arduino plus raspberry pi it doesn't get better than that so welcome to the workshop well hello and welcome to the workshop and today i wanted to show off a few things that i picked up recently at the arduino store now the first thing i picked up you can see right now because i'm wearing it i picked up this wonderful arduino t-shirt because i figured it was about time that i had an arduino t-shirt but i really didn't intend this video to be a fashion show because it's the other thing that i bought at the store that i think is going to interest you a little bit more than my shirt i picked up a couple of arduino nano rp 2040 connect boards now these are the much anticipated boards that contain the rp2040 the raspberry pi designed processor that is the heart of the raspberry pi pico board and arduino has added a number of extra features to this like wi-fi and bluetooth and a couple of onboard peripherals and put this into the same size package as the arduino nano in many ways it's similar to the arduino nano 33 iot that we looked at last time so what we are going to do today is run a number of different sketches to examine the features of these boards and we're going to do it with the arduino ide but before we do that of course we are going to look at all the different features and specs of the arduino nano rp2040 connect board so let's go and do that right now this is a development board that is based upon the rp2040 mcu from raspberry pi it adds features such as wi-fi bluetooth an inertial measurement unit a mems microphone encryption and extra flash memory it supports both c plus plus and micropython it has full support for both the arduino and raspberry pi pico libraries this is a 3.3 volt logic device with an internal buck converter to allow a wide range of input voltages however you should note that the pins are not 5 volt tolerant the board has the same form factor as the original arduino nano the board also has the same pin outs as the original nano note that the v usb pin by default is not connected this is a 5 volt output that is only available when the board is powered from the micro usb connector the heart of the board is the raspberry pi rp2040 microcontroller unit this is a cortex m0 processor with two cores it's clocked at 133 megahertz it has 30 multi-function gpio pins it has a 4-channel 12-bit analog to digital converter the rp-2040 can act as both a usb 1.1 host or a device the neenah w102 provides both wi-fi and bluetooth capabilities it has bluetooth and bluetooth low energy at level 4.2 it supports wi-fi 802.11b g and n internally this has an esp32 chip with 24 gpio pins the lsm 6dsoxtr is an inertial measurement unit or imu it has a 3d digital accelerometer and a 3d digital gyroscope this device also has an internal machine learning core allowing it to have some very advanced capabilities the mp34dt05 is a mems microphone module mems is an abbreviation for microelectromechanical systems these are sometimes also called solid-state microphones it's an omnidirectional microphone with a 64 decibel signal to noise ratio the device outputs pulse density modulation or pdm which is a digital representation of the analog input signal the nano rp2040 connect also includes a cryptographic coprocessor this is capable of generating keys for both encryption and decryption this is used for sign verification for iot applications the board also has an ate cc608a 16 megabyte flash memory chip this connects to the rp2040 using the spi bus this is a dual channel device for faster data transfer this chip will retain data for over 20 years the rp2040 also has an rgb led built onto the board this led is not connected to the rp2040 processor instead it connects to the neenah w102 module for this reason you need to use the wi-fi neenah library in order to drive the led you can address the led in your code using the constants ledr ledb and led g the arduino nano rp2040 connect is also capable of using the arduino iot cloud while we won't be using that in today's experiments we will certainly be using it in future videos so now that we've seen an overview of the nano rp 2040 connect let's take a look at this board and set up our development environment now here we have a number of different microcontroller boards including our brand new arduino nano rp2040 connect board and i wanted to show you this in comparison to some other ones just so you could sort of see the form factor now this is the board itself the rp nano 2040 connect board and as you can see it looks very similar to the one we looked at last time and this is the arduino nano 33 iot board they have the same wi-fi module of course a micro usb on the other end the reset switch over here so they do look very similar to each other and they have the same form factor as this board which is the original arduino nano now over here we have the raspberry pi pico and this of course is the board that has the same processor and as you can see the arduino board is substantially smaller and has many more things on it but of course it doesn't have as many pins nor does it have the debug connector and another thing i want to compare to size is this and this is an esp32 board which is slightly larger than the arduino board but again has more i o pins on it now let's take a closer look at this board right now and as you can see we've got as i mentioned before the wi-fi connection over here the micro usb the reset switch right below the switch here this is the microphone here next to it the imu and this is the actual rp 2040 itself and down over here it's a little hard to see but there's an rgb led on the board that you can use as an indicator now if we flip this over we see the same jumper that we saw on the arduino nano 33 iot and that's the v-usb jumper and v-usb is going to give out 5 volts assuming you're powering by the usb connection but only if this jumper has been shorted out and they do that just for safety purposes so you don't accidentally put five bolts onto the input pins because of course it's a 3.3 volt microcontroller there's also a jumper over here which is labeled 3v3 and this is the output of the internal 3.3 volt regulator that you can cut if you want to although i'm not quite certain why you'd want to there's also a few access points for the wi-fi module and again we won't be using those but otherwise this is the brand new board so let's go and see what it takes to hook up our computer to this board via the arduino ide now before we can work with the arduino nano rp2040 connect board we'll need to install that board into our arduino ide so we'll open up our boards manager and we'll search for the term embed mbed now you'll find a number of entries including some depreciated ones but the one you want is this one over here the arduino embed os nano boards and as you can see on the boards that it includes it includes the arduino nano rp2040 connect i've already installed mine but in your case you'll have an install button over here just click that and let it install keep in mind there's a lot of data over here so it may take a few minutes to install especially if you're on a slower internet connection now after you've installed the boards manager you're ready to start using the arduino nano rp2040 connect board with your arduino ide however you may experience some difficulty during the upload process and i experienced the problem with all three linux machines that i installed this on i did not experience a problem with any of the windows machines that i installed it on i have however found a solution for the problem now the problem is that during the upload process the board's boot loader was activated and it would put itself in the wrong mode in other words it was expecting that i would be using something like micro python instead of c plus plus the upload would fail with a message saying that the upload failed and even activating verbose error messages didn't give me any more information however by searching around in a few arduino forums i've found the solution which i honestly think arduino should print in their instructions and perhaps they will in the future or perhaps they'll resolve the issue now the way to resolve the problem on linux is as follows you'll need to go into your file manager and i'm using the nano file manager and you'll need to do a find which in nano is a control f and what you're looking for is a file a bash file called post underscore install dot sh and you will find an entry for that now the location on your machine of course will be different than one on mine now there are a number of ways that you can go about running this file here is what i did i right clicked over here and did open containing folder and that put my file manager into that actual folder then i right clicked anywhere in there and hit open in terminal and now i'm in the terminal and if i do an ls you can see that i am indeed in the correct folder and here is my post underscore install dot sh a bash file that should solve the problem that i was having now you'll also notice there's a post underscore install.bat file and this apparently is for windows machines that run into this problem but i did not run into this problem on the two windows machines i installed on if you run into it though you can try that batch file now you're going to have to be a root user in order to execute this so you'll need to do a sudo and then a space and a period and a forward slash which indicates that you want to run the file and then the name of the bash file which is post underscore install.sh because linux has an autocomplete you should only be able to type the first three letters and hit the tab key and it will print it for you now if you hit enter right now it will run this bash file and it should resolve your problem i'm not going to do that of course because i've already done that to my machine but i wanted to point it out to you that if you're running linux and encounter this problem this solution appears to work also on the forum i was on the user was using linux mint i'm using ubuntu linux and the solution seems to be the same for both platforms and so now that we've got our ide set up the right of passage that we have to go through is of course running the blink sketch now normally when i run the blink sketch with a brand new board i go in and modify the blank sketch because brand new boards tend to already be running the blink sketch so it's a little bit difficult if you don't modify it to make certain that your upload actually worked but in the case of this board we really don't have to because if you look at the board right now out of the factory out of the box it comes running a very interesting version of the blink in which it is blinking not only its orange light but also the rgb led is cycling through its different colors and so it's a very interesting pattern which will be very obviously changed once i run blink and so now what i've done is i've gone into tools and i have made certain that i've selected the correct board the arduino nano rp 2040 connect and also the correct port for that board and so really it should just be a matter of uploading blink and as you can see it's working as you can also see i got an error message but this is kind of a false error message and you will get this when you're working with these boards what happens is it actually disconnects and connects the usb port very quickly and this is part of the bootloader that the rp2040 has because you can also put this into another mode where you're using something like micro python or circuit python and work with it like that so this is a common occurrence and it's nothing to worry about as you can see we are obviously uploaded and successful because our led is blinking so i just wanted to make certain that you didn't get concerned when you saw that because you will see that now and then when you're working with this board okay so now that we've done the mandatory blink sketch it's time to move on to more interesting things now arduino has been kind enough to provide a number of example sketches that can be used with the rp2040 connect and we're going to use a few of those today just to demonstrate some of the features of this new microcontroller the first one we're going to look at is the wi-fi and what we're going to do is set up a wi-fi access point in other words the rp2040 connect is going to be supplying our wi-fi signal and we'll be able to connect to that with a web-based interface and control the rgb led that is on this module now there's no hookup for this or for that matter for any of the things we have to do today all we need is the arduino nano rp2040 connect board and we're all set to go so let's go and take a look at the sketch that we're going to be using and then we'll see how we can control our rgb led via wi-fi now this sketch was provided by arduino courtesy of someone named carl sotterby so thank you very much carl for your work now in this sketch we are going to use the rp2040 connect as a wi-fi access point we will set up that access point and then we will monitor it and if someone connects to that access point we will look for get signals that they will send whenever they click one of the buttons on the web page we're going to dish out when they send those we will use those to manipulate the rgb led that is on the board now for this sketch you are going to need two libraries the spi library which is part of your arduino ide and the wi-fi nina library which is not so you'll need to go into your library manager and look for wi-fi nina now if you happen to have looked at my video about using the arduino nano 33 iot board then you probably have already installed the wi-fi neenah library it is the same library now at the beginning of the sketch you'll notice we have an ssid and password and at first glance you're going to say bill what are you doing you're showing us your ssid and your password you might also say bill you've got a really lousy password over here well actually this is not my ssid and password what this is is the ssid and the password of the wi-fi network that we are setting up so you can call your network anything you want and you can give it any password you want there is one restriction however you need to have at least eight characters for both the ssid and password so i've called my network nano test and a password of one two three four five six seven eight now if we go through this sketch over here let's look at some of the key points one of the first points is addressing the rgb leds and that's what we address using pin modes to set them as outputs the ledr led g and ledb constants now these constants will address the leds which are not directly connected to the rp2040 they're actually connected to the esp32 module that's in the wi-fi module and so this is the way that we address them we'll go and check for the status and we'll go down over here you'll see another area that you can modify by default your local ip address is going to be 192.168.4.1 however you can change it with this line down over here so if you would uncomment this you could set the ip address to anything that you want now over here you'll notice they use commas instead of dots between the decimals on the address you might want to take note about that we're using our serial monitor just to print out whether we've connected to the access point or not but we really don't need the serial monitor if we don't want to now the real action in this sketch is down over here now once we've actually created our access point we need to set up a web page and that's what we do over here with client print so this is the web page that we're setting up for our client and inside our web page we have a number of buttons of the type submit and on a mouse down they are going to send out a url string that is appended with different letters r h r l g h g l and that's for red high red low green high green low blue high blue low now down over here we are going to listen for that so we will listen to see what the client request was and so if we get an rh we're going to send the led r to high the red segment of our rgb led if we get an rl we'll send it low and we do that again for the green and the blue leds and if we use the serial monitor we have a function down over here called print wi-fi status and that just prints out the wi-fi ssid and local ips so you can monitor that if you're having problems seeing the network when you start the sketch so otherwise the sketch is fairly straightforward and all you'll need to modify if you wish is the ssid and password over here otherwise you can leave it as i've left it and run it this way and that will be just fine so now let's go and upload that to our arduino nano 2040 connect board and see if it works okay let's do our web access point demo i've got the serial monitor up and as you can see it's creating an access point right now and we've got an access point and it's given us an ip address for that so we're going to go now to our web browser i'm going to move down over here and first of course we have to connect to that access point so let's go into our networking and select a network and there's our network nano test and we'll connect to that and we'll need our password we'll enter that and we are connected to nano test so now let's go to the ip address and there we have our control and now let's see if it works we'll hit the on button for red the red came on the green was already on so let's turn the red off turn the green off everything's off we'll turn the blue on we can turn it off now let's turn the red back on turn it off and we can turn multiple colors on if we wish and turn multiple colors off so it seems to work we can control our rgb led remotely by creating a wi-fi access point and using a web-based interface now the imu or inertial measurement unit that comes in the arduino nano rp 2040 connect is a very interesting device in that it actually has a machine learning component in it and this is a technique known as edge computing with edge computing peripheral devices are given some intelligence and they can pre-process the data to offload that from the main controller which in this case is the rp2040 now we're going to use one of the examples from the library from the imu to build a rather neat little device and what this does is it senses motion and displays whether you are stationary whether you're walking or whether you're jogging so you could build a practical device out of this that you could carry with you when you go out on your run in the morning and find out at the end of the day how much time you spent stationary and how much time you actually spent jogging and how much you spent walking now i'm not going to be able to jog or walk around the workshop it's just too small and that would be too silly so i'm just going to have to shake it around and try to simulate those motions but nonetheless it's a great demo anyway now the sketch that we're going to be using is one of the example sketches that comes with the library for the imu but it was written for a different microcontroller so we need to make one modification on it in order to use it with our new arduino and when we upload it we will get a warning message saying that it wasn't intended for this processor but that's fine it's going to work anyway so let's go and take a look at that sketch and then i'll simulate some walking and jogging and we'll see how it works now for this sketch you're going to need to install another library and this library has a very very long name and unfortunately you need to search for it by its full name because there are a number of other libraries that are nearly named identical to this with the exception of the last few characters so this is the stm 32 duino xnuclio iks01a3 library now you can just copy and paste that from the article in the dronebotworkshop.com website it's a lot easier put it into the search box in your library manager and then look for that library and install it once you've done that we're going to use one of the example sketches from this library but this library was not actually intended for use with this processor so we're going to find that we need to modify the sketch slightly and that the sketch is actually considered to be incompatible but don't worry we can make it compatible right away so go into file and go down to examples and scroll all the way down to the bottom to incompatible and you'll see a number of libraries over here that are not compatible with this processor and so go over here to this one here at st arduino x nucleo iks0183 and you'll see a number of interesting examples including things like a free fall detector and a pedometer and that we're going to use this one that append with mlc over here so let's open that up right now and this is a sketch that we're going to use now before we go through a few of the points of this sketch we need to modify it for own purposes and what we need to do is we need to put another definition in which you can do anywhere up here i'm going to do it over here i'm going to do a define excuse me i'm going to do a define in the right place and i'm going to define a new constant over here and it's going to be int underscore one is going to be defined as int underscore imu and that's the only change that you need to make to this sketch to make it work with the arduino nano rp 2040 connect now let's go through a couple of the points of this sketch because there's a lot of stuff in here but there's a few things that you might want to be aware of in the sketch now down in the setup over here we're going to go and look at this area over here now the imu is an i2c device and so we initialize it right now to initialize the i2c bus internally and these commands over here the begin enable x and enable g this enables the accelerator and accelerometer excuse me and gyroscope and this enables the accelerometer and this enables the gyroscope so when you're using it you're going to have to have all of those inside there now one key thing down over here is the interrupts and here they are over here now whenever we get movement it's going to create an interrupt so we're going to take an interrupt on int1 which we just defined and we're going to call this and we're going to look at it on the rising and that is just going to simply set a value over here when we call it to the mems event equals one now another end you're going to i just need to move back up over here another thing you're going to see is after we attach the interrupt we put a three second delay in because every time we get an event the internal machine learning is going to process this event but we need to give it some time so we're going to give it three seconds of time and then we're going to get the mlc output that's the machine learning output the decision that it is made on the type of movement that we're using and that output is going to go into an array and then down here at the bottom of the sketch we're going to look at the values in that array and depending on what they are we're going to print out what kind of movement we have so if it's a zero or stationary one we're walking forward jogging and they have a few others as well eight for biking and 12 for driving and otherwise we have no idea what kind of movement that you're making so it's a bit of a complex sketch but when you look at the key components of it it actually is simple to understand and you could use this within one of your own projects now you'll notice there's a second file that's already included in this sketch you can just leave that file alone and you can upload the sketch to your arduino nano rp2040 connect and we will see how it works okay i've loaded our sketch and it's starting to run and it indicates the activity is stationary now it's not going to report anything else until i get this thing moving so let's just see if i can actually do that hey it thinks i'm walking right now that's good and so we're walking i wonder if i can convince that i'm jogging right now maybe if i walk real fast there we go we're jogging and we put it back down and it should report that we're stationary and there we go it reports we're stationary now of course i'm not certain whether those movements i made really accurately simulated walking or jogging the only way to find that out would be to build a small version of this that's battery powered and go out walking and jogging which probably would be good for me but at the moment i'm just going to consider that to be a successful demonstration of the imu and we will move on to our next demo now for those of you old enough to remember the 1980s you might remember a rather cool little device that came out in the mid 80s and it might still be around today i'm not really up on these sorts of things but the device was called the clapper and it had one of the most amusing commercials i'd ever seen with an elderly woman sitting in her rocking chair turning things on and off by doing clap on clap off and it was a really cool device i was a systems analyst for the alberta government at the time and i proposed that we used clappers on all of our servers so that we could reboot them but for some reason they never picked up on that i still think it was a good idea well i've got good news for those of you clapper fans we can build one using the arduino nano rp 2040 connect in this next experiment we're going to be using the built-in microphone the one that gives out pdm signals to represent the audio and we're going to use that audio in order to turn on and off the blue segment on the rgb led by yes clapping on and clapping off so for those of you who missed the clapper and would like to build one of your own this is the sketch for you now the sketch that we're going to be using to build our clapper device is another sample sketch provided to arduino courtesy of carl soderby so again thank you very much and we'll take a look at how it works now you'll notice we're including a couple of libraries at the beginning and the first one may surprise you the wi-fi neenah library it might surprise you because this sketch doesn't use wi-fi but i want you to remember that the led that we're going to drive which is specifically the rgb led is connected to the esp32 in the neenah w102 module it's not connected directly to the rp2040 chip so you need to use wi-fi neenah to address that esp32 and in turn address the led now another thing i will make note of you may already have the wi-fi neenah library installed because you went through my experiments with the arduino nano 33 iot you should check to see that you have the latest version of the wifi nina library because previous versions of this library did not know the constant led b or e d r or l e d g which are the constants we use to address the segments in the rgb led and it'll fail to compile if you have that problem just go into your library manager and make certain that you don't need to update the wifi nina library and you should be fine it also includes the pdm library and this library was included when you installed the board manager for the arduino nano connect now let's go through this sketch over here uh the sketch itself is basically going to read the audio samples and simply look at the level of them and if they exceed a certain level then we will assume that we are detecting something like a clap and we will act accordingly on that so we set up a number of parameters for the audio the sampling frequency the size of the sampling buffers etc we set up a variable for the number of samples we read we initially initialized the blue segment of the rgb led and we use ledb for that constant so remember that's what we're going to be using when we address that led and there are a couple of optional things we can do over here to set the gain in that but we don't need to do that it's fine just as it is right now then we go into the loop and we start reading samples and so if we get samples read we start putting them into the sample buffer and we print them out to the serial monitor now in actual fact although you can monitor this with the serial monitor it looks much better if you monitor with the serial plotter and so when we print the sample buffer level to there you'll actually get a level on to that plotter and you can watch a graph of the waveform of the audio which is pretty neat and then we go into the sample buffer and we take a look at the size of it now we're looking to see if it is greater than ten thousand or and this is the or symbol over here if it is less than negative ten thousand because remember audio waveforms have both a positive and a negative component so if either the positive or negative component exceeds a value of ten thousand then we will assume that this signal is loud enough to constitute a clap and we should act upon it so we'll invert the current value of the led switch so if it was on we'll turn it off if it was off we'll turn it on now if it happens to be on if led switched is the same as if led switch equals one we will go and we will take the ledb and send it high so the blue segment of the rgb led will be turned on we can also print the serial port that something has been turned on otherwise it's the opposite we will turn it off so this is the section where we detect the clap and turn it on and off if it isn't sensitive enough for you you could reduce these values if it's too sensitive you could raise those values and then we clear the samples and basically that's it we have a call back over here to process the data from the pdm microphone and that callback goes to an interrupt that we generate earlier whenever we get data from the microphone and so it's a fairly simple sketch when you break it down into pieces and let's go and take a look at it now and see how our clapper works okay i've got our experiment hooked up and as you can see i'm using the serial plotter so you can see the audio waveform some of that is actually my voice and if i clap there we go you can see the blue led came on clap again and the blue leds off so we have built ourselves a clapper using the arduino nano rp2040 connect board and i'd say that it works pretty well so as we examine the arduino nano rp 2040 connect we can't help but wonder where it fits into the ecosystem of all these different microcontrollers we have now in the last couple of years we've had an explosion of new microcontrollers and instead of just the 8-bit arduino avr boards and the pick boards we now have choices like the esp-32s we have choices like the samdi processors there's even the 64-bit kendrick k10 processors where does this little board fit into that ecosystem after all it isn't necessarily cheap this is a 25 dollar microcontroller and for 25 dollars you can certainly buy an esp32 that can do a lot of the things that this board does well first of all let's remember that this board's wi-fi does indeed contain an esp32 so it's certainly never going to be as inexpensive as an esp32 and secondly this is a board from arduino and arduino products tend to be expensive but that's for a reason they're good quality products and you're also helping to support arduino and if you think about what arduino has done for our hobby using things like the arduino ide all the code samples they provided and the fact that they've put all of their boards out there is open source design so that other people can manufacture them for less money i think you'll find that this board has a place in this ecosystem and one thing that we haven't touched today which is true of this board and also of the previous arduino nano the 33 iot that we looked at is that these boards are compatible with the arduino iot cloud and that can make a real big difference in your project the esp32 by the way is not directly compatible with the cloud but it can be used with it and we will talk about the arduino cloud in a future video now if you need a microcontroller that has a built-in microphone a built-in imu then this would definitely be a good choice or if you want to work with the rp2040 line of products and you want some wi-fi connectivity it's an obvious choice so i think this board is going to show up more often here in the workshop now if you want some more information about this board please just head over to the dronebotworkshop.com website and you will find an article that accompanies this video you'll find all of the sketches that i use today and there's a link to that article right below the video when you're on the website if you'd please consider signing up for my newsletter now i know i've been really bad about sending them out lately there have been a lot of things happening in the background over here but i will be sending out one very soon i've actually got one in the works and you can sign up for that it's absolutely free it's not a sales letter this lets you know what's going on here in the workshop and it's a great way to keep in touch another great way to keep in touch and discuss all of these things is the dronebot workshop forum and you'll find the link to join the forum and again of course it is free and you can discuss this video and all of my other videos plus a number of projects and other subjects that have to do with electronics and microcontrollers and we got a great bunch of people over there who can help you out with any of the problems you might be experiencing with some of your projects and finally if you have not subscribed to the youtube channel please do so i would really appreciate that all you need to do is click on the subscribe button and then click the little bell notification and assuming that you have notifications enabled on your youtube you will receive a notification every time that i make a video so until we meet again please take care of yourself please stay safe and we will see you soon here in the dronebot workshop goodbye for now [Music] you
Info
Channel: DroneBot Workshop
Views: 57,300
Rating: undefined out of 5
Keywords: RP2040, rp2040 arduino ide, arduino, arduino nano rp2040 connect
Id: z8s3nl_C5sg
Channel Id: undefined
Length: 40min 20sec (2420 seconds)
Published: Wed Jun 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.