Get Started with Cellular IoT on the Raspberry Pi 4, Zero, and Pico - On Demand Webinar
In celebration of Pi Day, Blues Wireless presents a 101-style video for anyone interested in getting started with cellular IoT in the Raspberry Pi ecosystem. We show how to relay data from a Raspberry Pi 4, Zero, and Pico to the cloud (and back) using the prepaid cellular Blues Wireless Notecard available at blues.io.
Webinar Transcript for Get Started with Cellular IoT on the Raspberry Pi 4, Zero, and Pico
Speaker: Rob Lauer - Director of Developer Relations 00:00
All right, hello, everybody. I think we are about ready to get started here. TJ, throw up the flag if there are any problems with the slides or anything that I'm showing. First of all, welcome. Thank you so much for taking the time to sit with us today and discuss cellular IoT on the Raspberry Pi platform. So today, we're going to break down the usage of low bandwidth cellular on the Pi 4, the Zero and the tiny Pico microcontroller, all from Raspberry Pi, of course. Oh, and happy Pi Day, by the way, as well. I thought we would start with our mantra here at Blues Wireless, and that is complexity kills. While I don't really like to read text off slides for you all, I am going to read this one: “Complexity kills. It sucks the life out of developers, it makes products difficult to plan, build, and test.” Now this quote is from our founder and CEO, Ray Ozzie. I mentioned this quote because I think it's easy for a lot of us to relate to in our lives as software firmware engineers. This idea of complexity kills is really in our DNA. So, the goal is to solve this problem with simplicity, which I think you will see demonstrated throughout our talk today, and which I think we can all, or we all, have experienced using the Raspberry Pi platform.
So, let me introduce you to the speakers quick. First up is me. My name is Rob Lauer, and I'm Director of Developer Relations here at Blues Wireless. With me today is TJ Van Toll. TJ is our Principal Developer Advocate at Blues. We will be splitting up the demos today to give you a really good overview of using our wireless IoT solutions on a variety of Raspberry Pi hardware. Now a big part of our jobs at Blues is to create kind of fun, silly, yet somewhat pragmatic tutorials on Hackster. We address some key use cases like a lot of machine learning stuff, asset tracking, and remote monitoring, many of them on Raspberry Pi devices as well. You can see all of our amazing projects at hackster.io/blues-wireless. Some quick logistics before we really get started: If and when you have any questions for the speakers, either TJ or I today, please type those into that Q&A panel that you're provided. I think it's on the right of your GoToWebinar interface. We will be answering questions as they come in, as best as we can, whoever's not speaking. Please stick around for the end, and we'll do some live Q&A with some of the best questions for the entire audience. Likewise, if you have any audio or video issues today, or you just lose connectivity, or you have to leave for some reason, just know we're recording this, and we will have a full recording available within a few days, probably one or two days, on YouTube.
We'll send you an email with all that information with some additional resources and maybe even a discount code. Speaking of YouTube, you can find our channel at bit.ly/blues-youtube. We do have some really great content up there, all of our past webinars, you get some short-form videos there as well, and you can browse some very entertaining bits there. So okay, let's get to our high-level agenda today. First up, I know we have all types of people here—I know there's some invested Blues customers all the way through to people who have never even heard of us before. To level set, I want to start with a very high level holistic overview of wireless IoT from the Blues Wireless perspective. TJ is then going to build on that by showing how to get started with our hardware and services on a Raspberry Pi 4. I'm going to be back then to show off the Zero and the Raspberry Pi Pico and edge computing situations that tend to be lower power and not necessarily in the range of Wi-Fi.
Now I've said our company name numerous times so far without explaining what we really are. Blues Wireless is not a cellular service provider. We’re not the dudes at the mall hocking cell phone plans in those kiosks. Rather, we are an IoT company that is focused on making wireless connectivity easier for developers. We were founded and led by the aforementioned Ray Ozzie, who is the former Chief Software Architect at Microsoft. He kicked off Azure and made his name at Lotus Notes back in the day. Ray has a quite the track record. At Blues, so we do provide hardware and services that really do backup this message of making wireless IoT easier for developers and more affordable for all. This is really our core mission, and I think we demonstrate that in a few key ways. One is that our focus is really on securing your data from the moment it's acquired by a sensor or whatever on the device all the way through to landing on your cloud application of choice. All our hardware solutions are low power out of the box to the tune of about eight micro amps when idle. When we think about the Raspberry Pi, we don't often think about low power because the full single-board computer is generally on the grid. But when you talk about the Zero, when you talk about the Pico, that becomes a lot more interesting. We are also very much a developer-focused company; our developer experience is very much a top priority. Hence, you'll see that through our elegant and easy-to-use JSON-based APIs. To zoom in on the hardware that we provide, the Notecard is really the core hardware product that we provide. It is a low power system on module measuring a tiny 30 by 35 millimeters. It does have that M.2 edge connector at the bottom for embedding in your project. This will make more sense as we go along. There are both cellular and Wi-Fi variants of the Notecard.
The cellular version also includes a GPS module as well and that API I just mentioned. The API, so the way you interact with the Notecard is all JSON. It's all JSON in, JSON out. When you're managing the cellular modem, there's no archaic AT commands that you have to send anymore. Blues offers SDKs for Python, which you'll see today. Also, for Go, Arduino, C, C++, our community has even put together libraries for .NET, for some proprietary .NET microcontrollers, basically, and Rust as well. There are also Notecard varieties that work globally, so they use the NB-IoT, LTE-M, and/or Cat-1 cellular standards. Now to make it easier to use your Notecard when you're prototyping, or even when you're ready to embed in a more permanent solution, we provide products called Notecarriers. Now these are primarily development boards that let you snap in a Notecard and connect it to virtually any scenario you can dream up. To start with, the Notecarrier AF includes a Feather-compatible socket. The A model includes headers that let you hook it up to any microcontroller you want, including the Pico, you'll see that when I do my demo today. The B is a small form factor Notecarrier—these images are not to scale—so this one's actually quite tiny. Most importantly, today is the Notecarrier Pi, which is a Pi HAT for working with any Raspberry Pi-compatible single-board computer. It's got those pass-through headers on the top that just fit right on your 40-pin connector on your Pi 4 and Pi Zero. Finally, Notehub is the Blues Wireless cloud service that receives data as a proxy from the Notecard and in turn securely routes it to your cloud app of choice. Also within Notehub, you can manage fleets of devices and you can update both host microcontroller and Notecard firmware over the air. This bullet point really also includes file transfers, like if you wanted to remotely update Python scripts on your Pi. I wrote up a project that updates a machine learning model on a Raspberry Pi over cellular. Also, everything about Notehub is really all about securely transmitting data, both from the Notecard and to your cloud. I mean secure as in with the cellular Notecard, all the data is transferred off the public internet via private VPN tunnels and it can optionally be encrypted as well, so there's no certificate management or key rotation required. The cool thing about the Notecard is it knows exactly where to go the moment it is powered on.
Speaking of that JSON API, again, everything is JSON in and JSON out. As an example, if you wanted to get your Notecard’s GPS location, you would simply call this request card.location, and it will return in the response the requested location with the latitude and longitude and some other metadata as well. Now the rest of our API is set up in a very similar way to this.
Now that you have at least a rough idea of what's going on here, to help visualize where the Notecard and Notehub sit in your IoT solution, let me walk you through this diagram. You're going to bring your microcontroller, your single-board computer, like the Pi, you're going to use your sensors, your own programming language, really everything that you're already working with—we want to work with your existing workflow, if you will. You're going to compose packets of JSON data that we call Notes. Now these Notes are queued on the Notecard. We provide about two MB of flash on the Notecard, so you can store quite a bit of data on there. Then at a cadence you specify, these are going to be securely synced either over cellular or Wi-Fi with our cloud service Notehub. Now, we don't want your data to live on Notehub; we're not trying to trap you into our service here. We want you to route that data to your cloud app of choice, meaning AWS, Azure, or Google Cloud, or even an optimized IoT provider like Ubidots, Losant, or Datacake.
Now likewise, it's important to note that communication with the Notecard is bidirectional, so you can also start on your cloud app and send a JSON-based request to Notehub using the APIs we provide. Notehub is going to securely deliver that JSON payload to the Notecard, to one Notecard or many Notecards, an entire fleet if you want to. The Notecard will then deliver that back to the host, the single-board computer or microcontroller. You can really see how you can handle, in this scenario, like remote control scenarios, or updating fleet variables all remotely over cellular or Wi-Fi. But a good question here is to pause and ask why.
Speaker: Rob Lauer 10:52
Why would you want to use cellular on a Pi that already has Wi-Fi? Well, the most obvious is if you don't have access to Wi-Fi, and therefore you have a need for low bandwidth cellular, if you're building a machine learning application, and you want that inferencing to happen on the edge and be delivered immediately to the cloud.
Security is important too. So cellular, especially on the Notecard, is far more secure than Wi-Fi, and if you really want the turnkey cloud integration for syncing and routing sensor data. I want to drill into this more, just to make sure we're all totally clear here. It might be interesting to look at when this makes the most sense. I'm going to repeat myself a little bit here. But you know, if you don't have access to Wi-Fi, and therefore have a need for low bandwidth cellular, the Notecard makes sense. Again, if you're building a machine learning application and want that inferencing to happen on the edge and be delivered immediately to the cloud, again, security. If you want that turnkey cloud integration. Just to be clear, don't think of the Notecard as a drop-in replacement for the Wi-Fi that you have on the Pi. It's really meant for low bandwidth data transfers. Likewise, if you're looking for low latency communications, the Notecard— and really this is for cellular in particular—is not that ideal for it right now. If you're looking for high bandwidth data like video streaming, the Notecard is not going to be for you. I don't want to turn anybody off here, I just want to be very clear on what we do and don't support. That's kind of my spiel. I think it'd be great now to look at this from a more hands-on approach and start with the Raspberry Pi 4, and then we'll look at the Zero and the Pico and see how the Raspberry Pi 4 and the Zero use the Notecarrier Pi HAT. Again, we'll get smaller as we look at the Pico with a different Notecard entirely. To do that, let me switch presenters over to TJ, and he's going to show the Pi 4 getting started experience.
Speaker: Rob Lauer 12:31
I think it'd be great now to look at this from a more hands-on approach and start with the Raspberry Pi 4, and then we'll look at the Zero and the Pico and see how the Raspberry Pi 4 and the Zero use the Notecarrier Pi HAT. Again, we'll get smaller as we look at the Pico with a different Notecard entirely. To do that, let me switch presenters over to TJ, and he's going to show the Pi 4 getting started experience.
Speaker: TJ VanToll - Principal Developer Advocate - Blues Wireless 12:53
Yeah, I went ahead and switched over my camera because I always like to start by, I mean, Rob showed some of the hardware off in slides, but I think it's just helpful to see what they physically look like. I know some of you also have purchased Raspberry Pi starter kits too, and you have some of this hardware around. If you want to follow along, that's great as well. If I do go too fast, I'll remind you that this is being recorded, so you can always refer back to that later. I'll start by just showing the Notecard, so hopefully you can get a sense of how big this is compared to my hand. It's 30 by 35 millimeters. It's a system on module. It's something that you can embed in pretty much any IoT project, but what you'll probably want to use, especially with the Pi, is one of our Notecarriers. This is what the Notecarrier Pi looks like. You'll see that it accepts a Notecard here. It has a little connector there for that ITC connection. We also include in our starter kits a Molex antenna—which is what you're seeing here—that's going to help with cellular communication. I've also got a sensor hooked up here that we're going to be using later in this walkthrough, but we'll return to that in a minute. You'll see that the Pi HAT does have these pass-through headers. What you'll want to do is just quite simply—and I'll see how good I can align this with a camera—line up with the headers and attach this. Now we do ship spacers that you can put it in here that I'd recommend if you're going to be putting this together for a long period of time. But for today's demo, I'm trying to keep things as simple as possible, so I'm just going to toss it in there and go from there. Now with that, really all you need to do is power things up. I've got a USB-C cord ready to go for my Pi to give that power, and then the very last thing I'm going to do is the Notecarrier Pi also has a micro-USB connection. I don't know how well you can see it, but right there. I've also got a cord that I'm going to run to connect that—you got to figure out which way it goes in, there we go—connect that to my laptop that I'm using to run this presentation. As you'll see, now I'm going to switch around both my camera and my screen. You should be seeing my screen, and then I'm going to switch it back so you can see me as well. That's the hardware setup. That's really all you need. It's simple setup: You get a Notecard, you put it in the Pi HAT, or you attach the Pi HAT to the Raspberry Pi 4. From that point, you're basically good to go from a hardware perspective. When you do have things hooked up, the place to go next would be dev.blues.io. This is our hub for all things documentation Blues: You'll find guides, tutorials, reference documentation, API documentation, all that good sort of stuff here. When you're first getting started, I'd recommend heading to the Quickstart section of the docs and to the Notecard and Notecarrier Quickstart, because that's going to walk you through the steps that you need to just get up and running with the absolute basics.
You can configure this tutorial for the different carriers that we offer here at Blues. We're going with Pi today for our Pi Day celebration, and we'll use them to go through this. You'll see the rest of this mostly looks like any other tutorial you'd find for really any sort of technology, software, hardware, etc., where it walks you through the steps you need to go to set up—except—notice this section over here on the right-hand side of the screen, where we have this sort of in-browser integrated terminal. What's cool about this is that you can actually connect to the Notecard through what's called the web serial API that's built into some browsers like Google Chrome that you can use to actually connect to a Notecard. That's why I plugged in that micro-USB to USB cable to my laptop, so that I'm able to make this connection. So, at this point, I'm connected to the Notecard directly in my web browser, which I think is kind of cool. At this point, I can start communicating with it.
If I scroll down in this Quickstart—if you're following this later, there's pictures to help you set up exactly what I just showed earlier for setting everything up—what I want to do is run my first command. I’ll pull this up a little bit. That's a command called card.version. I'm going to run this and then talk a little bit about what's happening. The first thing to notice is—Rob mentioned this in the slides—the APIs that we have for everything for dealing with a Notecard are JSON based. You'll see to send the card.version request, I'm sending a JSON payload that I'm telling it to run a request of card.version. The response is also JSON as well, so the information comes back in a JSON structure. I'm getting some metadata like firmware version and such through it as well. Now this is the easiest way to get started with Notecard, to just send commands through the browser, because you see I connected and set that up within a matter of seconds, but there are other ways of interfacing with the Notecard as well. There is the Notecard CLI, which we have available for Windows, for Mac OS, and for Linux; you can also use that to connect to a Notecard and to send requests. You can use this approach if you want to go through all of this setup and do everything directly on the Pi itself. Basically, what you'll need to do is install the Notecard CLI on the Pi, and then there's APIs for interacting and sending requests like this through that approach. You can follow these links from dev.blues if you're interested in trying that out, because today, I'm going to stick with the browser. The other thing you can do is we have SDKs that are available for interfacing with a Notecard as well, things like C++, Arduino, Python, Go, and such, you can use those for sending these commands as well. Later on here in a few minutes, I'm going to show—we're actually going to write a quick Python script where we're going to automate some of these requests as well.
Lots of different ways for interacting with the Notecard depending on your situation. The easiest, and what I'd start with, like your 101, is just doing it through the browser, because it's easy, it's also really cool and fun to do that. I'm still amazed that this sort of thing is possible. It's a lot of fun to use as well. That's the hardware setup. We sent our first command, chances are though, you're interested in the Notecard because you want to get more than the version number. Usually, the next logical thing you want to do is get some sort of data. Maybe that's sensor data, location data, motion data, or something, and send that up from your local system, from your local Pi, up into the cloud where you can do something with that. With a Notecard, your next step to setting that up is to set up Notehub. Now Notehub, as Rob discussed, is sort of our thin cloud backend that makes it easy to integrate with Notecard and then take that data and send it basically wherever you want that data to live.
Now the first time you go to Notehub, notehub.io, you will create an account. I've already created one to save us a little bit of time, and then you'll need to create a project. Okay, so a project can be whatever, I'm going to keep things basic and just call mine “Getting Started.” A project is nothing more than a logical grouping of data and devices that you want to store, that you want to associate with the Notecard. When I create this, it's going to give me an identifier that identifies the project I just created, which I'm going to copy, because the next thing I need to do is I go back into the Quickstart, which again, if you're trying to follow along and I'm going a little too fast, keep in mind a lot of the steps I'm showing here, I’m just going through the Quickstart, and you can look back onto this later.
The next command I need to run is the hub.set command. For this, I'm basically saying which Notehub project I should associate with this Notecard. I've got a placeholder in here, and I need to take that value I just copied with this new Getting Started project I ran and run that to essentially create that connection. Now there is one additional step that I need to run. I need to run this hub.sync command as well. The reason for that is we designed the Notecard to be very low power friendly by default to the tune of eight micro amps while this thing is idle. We do that because a lot of people use Notecards for a wide variety of things, and lots of those are in situations where battery is extremely important. Think about a location tracker that you're shipping around: You have to use battery power for that sort of thing, and it might be quite limited, and things like initializing a cellular connection, using a cellular modem does use up a decent amount of battery. The Notecard does try to be a little bit conservative in how often it makes that connection. A sync is the explicit way you can tell the Notecard, “Hey, go ahead and do this, take any changes that have been made locally like such as running a hub.set request, and go ahead and send that up.”
Now I will note that the Notecard is incredibly configurable. If you do know that you're going to be on a hard power connection the entire time, you can set various flags to make things sync essentially immediately, so you can get as low latency as you can with a cellular connection. But the defaults are very battery friendly, so that's why I'm running this hub.sync. All right, since I did run the hub.sync, I should be able to come back here and refresh and see my device. There it is, last seen just a minute ago, that I have up here. I have now established the connection between the Raspberry Pi that is sitting on my desk and the Notecard I have running in here and this backend that came into Notehub. Rob, do we have—this might be a decent spot to stop. I don't know if I'm missing anything or if we had any questions that have come in, and if not, then I’d encourage people to ask some as we're going.
Speaker: Rob Lauer 22:51
No, a bunch of good questions. I was going to say too, one thing you could show off is we have a little hidden shortcut in the terminal as well to turn on watch mode, it’s just a W. It’s not documented, so I can't guarantee it's always going to be there, but it's kind of handy to use. Like if you're running another hub.sync TJ, you can get a high level overview of what's going on with the Notecard in the background. But yeah, I can cover a couple of the questions we've had so far.
Question about MicroPython and CircuitPython support. Yeah, this is really valid. MicroPython, especially when you start talking about microcontrollers like the Pico, and I will be covering that a little bit. I mean, I'll be writing, technically, I guess writing MicroPython on the Pico even though it's I think 100% exactly the same as Python that you would write anywhere else. Another question about external SIMs. In case we weren't super clear about this, there is an embedded SIM on the Notecard, so it's all burned in when the device is manufactured. But if you're in a country that does not have one of our first class network partners’ support—that tends to be either India or China are two slightly big countries that don't have support—we do have on every Notecarrier the opportunity to slot in your own SIM card. For instance, I've done this before with the Twilio Super SIM, when I sent an asset tracker to India and beyond, and it worked great. Just know that there are options there for if your country is not explicitly supported.
Speaker: TJ VanToll 24:41
Cool. Yeah, good questions. Make sure to keep them coming in as we go through. Are there more you're going to cover too?
Speaker: Rob Lauer 24:48
There's so many more coming in.
Speaker: TJ VanToll 24:51
Let's pick one more, and then we’ll keep the rest for the next step.
Speaker: Rob Lauer 24:56
Yeah. This is an interesting one. I've not heard anybody ask this before, but it's a valid question: Can you link to more than one project in Notehub at the same time? With Notecard and Notehub, there are a million different ways to approach this problem. In this person's example, they say maybe a microcontroller would have a pressure sensor and temperature sensor, but a group of users only care about pressure but not temperature. To answer your question explicitly, yeah, you could have more than one project associated, but you'd have to programmatically switch that hub.set request, which feels like a little bit of a hack. There's also on the backend different ways you can do this. TJ is going to show this off, and I'll do a little demo of it as well. Really, probably the most important feature in Notehub is the ability to route data, and you can route different chunks of data to different people, different clouds, or whatever you want to do. Yeah, there's definitely ways to accomplish that. All right, I’ll stop bugging you TJ.
Speaker: TJ VanToll 26:03
Oh, no, that's cool. Those are good questions. Just to… where we've wrapped up is we had sent data from our Pi, from our Notecard up to Notehub. I did want to quickly show that the communication is bidirectional. Rob quickly showed this in slides, but I just wanted to show a concrete example. The previous time I took some… well actually, we got to show data one way up first, because all we did was the sync. I'm getting ahead of myself, Rob, you throw me off.
Speaker: Rob Lauer 26:31
And I can throw you off even more. I just realized that I don't think GoToWebinar when it does it's recording, I don't think it records our video. If you want to, when you get a chance, just swap video and show off your setup.
Speaker: TJ VanToll 26:48
I started it on the video. I don't know, I'll show it again on the camera when I'm done.
Speaker: Rob Lauer 26:53
Just for folks who are watching this later. Anyway. Sorry.
Speaker: TJ VanToll 26:55
Yep. No, we're good. The next thing I want to do is actually send some data. We're going to actually, I'm going to show both directions: I’ll show data going from Notecard to Notehub and in the opposite direction. To send data up, I use another request called note.add. The body can be any arbitrary sort of data payload, and we're going to start with some hard coded data, and we're going to switch that over to some live data here in just a minute. To start, I want to send some hard coded data, and I'm going to run another hub.sync because just adding that data doesn't mean it's automatically going to appear in Notehub. I have hard coded data, I'm going to sync it, if I go back to Notehub, if I go to the Events section, you essentially see a running log of all different data, all different activity that's happening with your Notecard. You'll see because I ran that sync, I see my hard coded data as it sort of made a pass through here into Notehub. I did want to show that it's bidirectional. If I go back to my devices list, I can add a Note. Remember, the add Note is the same command we ran over here, but in this case, I'm going to run it in what we call a .qi request, which is a weird acronym. You kind of to read it backwards, IQ, inbound queue, inbound, incoming to the Notecard… don't worry too much about the conventions, the abbreviations. What it really means is just I can send the data both ways. In this case, I can say I want to send this JSON payload from my cloud into the Notecard. On the Notecard, if I again, run a hub.sync… and if I find the right button in my keyboard.
Speaker: Rob Lauer 28:41
I apologize if you already mentioned this, TJ, but what you, what TJ just showed is also possible through the Notehub APIs, so you can do this programmatically and not through the UI.
Speaker: TJ VanToll 28:51
Yep, the UI is good for testing, but in a real scenario, you might be, I mean, you might have your own web app or mobile app that you're using as a remote controller of your device. You might just be changing settings on the fly. There's lots of different ways or lots of different things you can do when you can communicate in both directions. I just want to show there's a separate request called file.changes. That's a way of getting any changes that have come from Notehub. In this case, I'm getting a data.qi request; that's the one I just queued up. There's a separate request called note.get that I can use to get that data, and I can get the values that I hard coded up in Notehub. But again, I just wanted to show you that this is possible. The actual use cases, remote control is one big one, Rob and I have a co-worker that built a robot that you could control. You could essentially send commands, and it used this sort of approach to send commands down to the robot to have it do things like move its arms and whatnot. You can change settings on the fly; Rob mentioned earlier that he's built a location tracker and sent it around the world. He was able to change the settings and some of the configurations as it was quite literally travelling, which is kind of slick that you can do. That's one of the cool things that's enabled about using cellular as a backing for this is, put your Pi, put your Notecard out, quite literally anywhere that has cellular connection, and interact with it in multiple ways, which is kind of cool. All right, so with that, we now have our Notecard, our Pi setup, we're sending some data. The next thing I want to show—so when you get to this point, I think the next logical thing to do—we talked about the Quickstart, we essentially showed very quickly the steps that go into that, if you go to this guides and tutorials section. The next two things we recommend completing are our sensor tutorial and then our routing tutorial. The sensor tutorial will help you kind of take those hard coded values and switch over to some more real values that you're actually collecting and sending up to Notehub. I'm not going to go through every step of this, but I will show you my sort of development workflow and how I approach that. I'm going to bring up Visual Studio Code. For me personally, the workflow I like to use for interfacing with my Pi is using Visual Studio Code’s remote—I think it's remote, let me get the exact name for you—the “Remote Development Extension for Visual Studio Code.” I think it's a really, really awesome way of providing well, in that case, I use it to SSH into my Pi, and then I have both a terminal as well as a code editor that I can use on my Pi. But while it's just sitting here, I can remote into it from my main machine. All the steps I'm showing, if you'd like to just work on your Pi directly, all of these steps that I'm going to be showing are going to continue to work exactly the same. I'm going to open up a little project, a little script that I started called sensors.py. I mentioned earlier that I had a sensor hooked up to my Pi. It's very specifically a BME280, which is a really common temperature humidity air pressure sensor. This script is a script that I basically just found on the internet and copied and pasted it, so if you looked up the BME280 documentation, it's going to tell you to use this syntax to do the connection, and then here's how you get your data.
Then if you run this thing, just Python, three sensors, I'm going to just be spitting out the humidity, pressure, and temperature readings every 15 seconds to my console. Now, I like showing this example because I think this is a common scenario where the Notecard can be quite useful. You have some sort of sensor, some sort of data, and you want to take that data and actually get it from your Pi into a cloud backend where you could do something more interesting with it. I thought I'd show how to add the Notecard into a situation like this. It's really just a handful of steps. The first thing you need to do is install our SDK: It's going to be pip3 install. This will be in the sensor tutorial, so don't worry about necessarily remembering this or anything. You need to install two dependencies: Note Python, which is our API or SDK for interacting with Notecard through Python, and python-periphery, which is a library that just makes IO communication through a lot of different protocols really simple. I'll show where we're going to be using that. Once you have those two things installed, the first thing you need to do is import them. I'm importing the Notecard. I'm importing periphery, because we're going to be connecting to actually interface with the Notecard through what's known as I squared C (I2C); you don't need to know the details about that. That's just the sort of implementation details of how you access the Notecard. Once I have the imports done, the next thing you need to do is—again, this is code that you can find on our sensor tutorial that's pretty easy to copy and paste—just to actually perform the I2C connection to get access to the Notecard, get this object here so we can start to do interesting things with it. Then from this point, that's really the entirety of the setup. From there, you're just going to run the same sort of commands that we were just running in the browser. I'm going to take and set up a connection here, but I'm going to build up a Python dictionary object that's going to connect to a Notehub project. I have a separate one set up for this. Then there is an API that's part of Note Python for actually sending transactions through the card, essentially sending these requests up to Notehub. I'm going to run a hub.set and then down here when I collect this weather data, I'm going to add one more step that actually sends that data using that note.add command, the very same one that we ran in the browser, but just doing it through this Python script. For the body, instead of using hard coded data, I'm actually going to take the live data from my sensor and push it up as well. I'll save this and run this. I think indentation matters in Python, so I got to fix that. I'll run that. Then every 15 seconds, I'm going to take readings. I'm going to send this up to Notehub. Back in Notehub, I used a separate project for this, I use a project called “Weather,” so I'm going to head into that. I'm going to look at my events list. What I should see is the newer data coming in—I think it's, let's see if it's—one of the things you can tell by when Notehub runs. Part of the reason I'm printing out the results of this is this total is basically telling me how many Notes the Notecard has queued up and is waiting to send to Notehub. This is the one thing about using a cellular connection and this is why Rob had on this, the Notecard isn't a solution for things where you need completely instantaneous bandwidth, since you are working over a cellular connection and it could sometimes take time to initialize the cellular modem and send your data over. In this case, it's collecting the readings, but it hasn't actually synced them to Notehub quite yet. Once we see that total goes down, it does.
Speaker: Rob Lauer 36:17
I was going to say, we've all been very spoiled by our smartphones and not appreciating what is actually going on behind the scenes because cellular is very, very tricky, especially when you're using protocols like LTE-M and NB-IoT. These are very, these are not the forgotten portions of LTE, but they are, I don't know, deprioritized in many ways.
Speaker: TJ VanToll 36:45
Yep. Well, it, it's cool too—apparently I screwed something up, we'll see if it actually came through—the cool thing to remember is that this is all happening over cellular. It's sometimes easy to forget that this Pi could be sitting out in a field somewhere and continue to operate correctly. Although I might have typed something wrong in my demo. We'll see.
Speaker: Rob Lauer 37:11
Yeah, can you scroll up on your code? It all looks good.
Speaker: TJ VanToll 37:20
I don't know, I'll probably look back at this later and find out I put in the wrong snippet into the wrong place, but I can still show you. You can pretend that this data came through the magic of demos. The data is getting queued up here, but I do have some readings from earlier when I was testing this out that appear down here. Because the last thing I want to show—we'll see, maybe that'll fix itself, we'll let it run in the background—the last thing I want to show is how to route your data. Once you have your data in Notehub here, the real question is then how do you take that data and do something interesting with it? Routes and the routing tutorial will help walk you through this, can help you provide several different places that you can send your data. That can be a big cloud like AWS, or Azure, Google Cloud; it can be something like MQTT, it can be an IoT platform like Datacake or Ubidots, or you can just say, “Whenever I get an event in Notehub, just fire it to some HTTP endpoint that I have set up to accept and do something interesting with that data.” The routing tutorial will help you with the details on that, so I'm not going to go over everything. I just want to quickly show that I do have an integration of route setup for Ubidots, which is an IoT platform that helps you build visualizations around your data. Let's see if we have, oh, it did fix itself. Okay. I don't know what's going on, but we should have like 12 readings queued up, so we should have a bunch of stuff that shows up here. Yeah, there we go. See, it didn't lose any of those readings; it just sort of queued them up. You'll see actually, too, they should be about 15 seconds apart when they happened, and they came through. Then because these events are all being routed, I can head to Ubidots. If I get data for the last hour, you're now essentially seeing live data points coming from my office and feeding into this dashboard, and it's real time so I can refresh this and see updated data as well. I like showing this because I think at this point, this is kind of the full path. When you actually get a starter kit, a Raspberry Pi starter kit from us, that is the path I would recommend—going through the Quickstart so you can see how to set up the communication in both directions. Then going through the guides both for collecting sensor data and the sensor tutorial too is something you can configure based off your hardware based off whatever things that you have send data up and then routing it to whatever end destination you have in mind for your data, whether that is building something like the dashboard I showed or maybe your own database or whatever sort of thing that you have in mind. That's the full flow. I'm happy that that worked. Rob, I don't know what I did at first, but it looks like data is flowing through fine now.
Speaker: Rob Lauer 40:12
Magics of—magic of cellular.
Speaker: TJ VanToll 40:13
Yeah, and I'll go back to showing because you had asked, now that that's working.
Speaker: Rob Lauer 40:17
Oh, I just made myself presenter here. Let me…
Speaker: TJ VanToll 40:20
You're ruining it, Rob. You wanted me to do this. This is the Pi, just in case it didn't come through on the video earlier. You can see, depending on how good I can get it to focus, how it's just a Pi HAT for the Pi. The Notecarrier plugs in there, and then Notecard slots into that M.2 edge connector in there as well.
Speaker: Rob Lauer 40:43
Cool. Thank you, TJ. I did want to mention a couple of quick things about the Raspberry Pi HAT that TJ just showed off. First of all, it is compatible with the Raspberry Pi 4 and the Zero 1 and 2. I didn't say the Raspberry Pi 2 and 3, because some of those models include a current-limiting fuse that can power cycle the device when the Notecard’s modem is on and transmitting. Your mileage may very much vary here, because I've heard of some folks who have had no problem at all. But just, you know, we recommend the 4 or the Zeros. There are also some dip switches on the back of the HAT, and those enable usage of an active GPS antenna and serial access as well. I think I've mentioned this before, but there's an external SIM slot there if the embedded e-SIM on the Notecard isn't supported in your country, and there's a Grove port on there for connecting to external peripherals. Again, finally, that 40-pin HAT is stackable, so you can add other Pi HATs as needed.
Speaker: Rob Lauer 41:51
I did want to shift focus a little bit into the Raspberry Pi Zero. This is easily my favorite tiny little Linux single-board computer. I'm going to be honest with you: Using the Zero with the Notecard is just not really any different than what TJ showed with the full-size Raspberry Pi. Since the Zero does have that 40-pin connector, you just slot the HAT on top of it, but this does make the Zero a great option for these lower power edge computing scenarios. I did want to walk you through a quick story with how I used Zero with my home's hot water boiler system. I decided to build a project that used a Zero with the Notecard and built out a machine learning solution that used a thermal camera to perform anomaly detection on thermal images. To do this, I wired up my Zero with an MLX 9640 thermal camera. It produces these really tiny but still pretty cool looking, no pun intended, 32 by 24 resolution thermal images. I wrote a really simple Python script on the Zero to take those thermal images every, I think it was 5 or 10 minutes, to see what my heating system looked like under various conditions. I was able to classify three really high-level types of images. So, cold, the system is off; warm, it’s either heating up or cooling down; and hot, it's actively running.
Now since my system wasn't acting up in any anomalous way, thankfully, I did have to create some anomalies of my own, which I did with a little help here from Photoshop. But this really gave me the start of an image classification ML model, and I built this out with Edge Impulse. Now I don't have time to dive into Edge Impulse here, but if you're really looking for, frankly, what I think is the easiest way to build a variety of machine learning models and deploy them to numerous types of MCUs or Raspberry Pis, Edge Impulse really is the way to go there. I ended up pulling in all these images to properly create an ML model and classify the images as cold, warm, hot, or anomalous. I think I started with like 120 images, which gave me this fancy looking gif here. Then I got this, you know, ML model built out of it. I use the Notecard to actively relay this data, these inferences to the cloud. In this case, similar to TJ, I built a super simple Ubidots dashboard. This is really a great example of the opportunity of machine learning: Instead of uploading all your accumulated data to the cloud for processing, which can have logistical and privacy concerns, you're creating these inferences locally and just sending what you need, right, the final result, to the cloud. I could have easily added on an alerting system here as well with Notehub and Twilio to automatically send me SMS alerts when anomalies were detected. You know, a lot of great use cases here.
You're not meant to read this code, but I did want to demonstrate this was all pretty much accomplished with just a few lines of Python code effectively. This is not the full script, but it's pretty close. This is again one of the many tutorials we have on Hackster, but I just wanted to really quickly show this off as an example of where the Zero can fit into a scenario where cellular and machine learning overlap, for example.
Speaker: Rob Lauer 45:14
That brings us to the Pico. The Pico is a dramatic shift from what we're used to with the Raspberry Pi 4 and Zero. The Pico, if you're not familiar with it, it is a tiny little microcontroller, meaning it doesn't run the full Raspbian OS, but it does allow for way more low power, low cost, really targeted applications than you could ever imagine performing on the 4 or the Zero. Drilling in on the Pico just a little bit, as mentioned, it is not a single-board computer that runs Linux, it's a very low-cost microcontroller. Think about $4 or $5 US dollars last I checked. It is built around the new RP2040 microcontroller chip, developed in house by the folks at Raspberry Pi. It has a fair variety of IO options, lots of GPIO, I squared C (12C), URSPI, and so on. It also actually has a programmable IO, PIO, which these are effectively like state machines for custom peripheral support. It's really pretty cool outside of the scope that we're going to talk about today, but I did write about it on the Blues Wireless blog, if you are curious. Again, a pretty flexible board that supports both MicroPython and C or C++ development. With that, I would like to show a demo of how this Pico can be used with a Notecard. Let me stop showing this and show off my, oh, let's see, I want to show Thonny, but also show my—oh I love GoToWebinar, I’ve got to go back to preferences to start showing my—
Speaker: TJ VanToll 46:58
All the menus. Fabulous, good. We see your Python code.
Speaker: Rob Lauer 47:04
There we go. I think. I hope.
Speaker: TJ Van Toll 47:09
Yeah, we see your setup as well.
Speaker: Rob Lauer 47:13
I'm not here to insult anybody's intelligence here in any way, but I do want to kind of walk through the wiring diagram or wiring of what's going on here with the Pico and the Notecard and Notecarrier. Okay, so here, of course, is my Pico. It is wired up, as you can probably tell, to three different LEDs here. These lights will make more sense when I show you the code. They all have a common ground, with the Pico through the little yellow cables here and then the orange one here. The Pico itself is wired to Notecarrier A. The Notecarrier A has a black Notecard on it, which if you remember from the slides is a Wi-Fi Notecard. I just wanted to show off this Wi-Fi Notecard, frankly, just to do it, but also to demonstrate how the APIs we provide are perfectly matched between cellular and Wi-Fi. You can actually have a mixed deployment between cellular and Wi-Fi in the same project without any code changes. Those are connected. We got power and ground here, and then it's connecting over I2C. I've got the SDA and SCL on the Notecarrier hooked up to the equivalent pins on the Pico. I keep moving this around, but you can still see it there, so, pretty simple wiring here. Let me plug this in with my micro-USB cable, and we'll see the Notecard boot up there. Then back in Thonny, I'm going to restart here and make sure this one is actually open. It is. Again, this example I'm going to show you is embarrassingly similar to what TJ just showed off—why can’t I resize this window, that's interesting, okay—but I did want to just walk through really quickly here what's going on and what these LEDs are all about. One thing I wanted to mention, one thing I'm going to mention is—that’s interesting, now I can’t click on anything in here—I am going to reestablish the connection here. You know what, I'm going to quit Thonny.
Speaker: TJ VanToll 49:27
Visually it came through fine. We were able to see the code okay, but I’m guessing the UI seized up a bit. Yeah. All right. It’s one thing about working with some of these microcontrollers actually. Thonny is like the good example. It can get even crazier.
Speaker: Rob Lauer 49:46
Yeah. Thonny is really nice for MicroPython development. I’ve got to say, generally, when it doesn't freeze up. Basically, I'm performing a variety of initialization code here that we don't really need to dive into, but you can see that the LEDs are connected through the GPIO 13, 14, and 15, the red, green and blue. There's an onboard LED as well on the Pico itself, that's pin 25. Like TJ was showing, I'm simply associating this Notecard with this project I set up in Notehub. Again, like TJ showed, I'm sending the hub.set JSON request with that product UID and setting it into continuous mode. I've got three different quick methods here: One turns all the LEDs off, one turns them on, and one flashes them. Pretty dead simple. I confess that I actually stole most of this code from Jeff Girling; he wrote a really nice little Pico project on Hackster. He actually developed this really simple board to show off the temperature, show off LEDs, for a nursery—he had a baby not too long ago. Green is obviously a comfortable temperature, red is too hot, and blue is too cold. That's all that’s going on here. We're just looking at the temperature onboard sensor of the Pico and lighting up the appropriate LED based on that. Again, similar to what TJ just showed, I'm sending temperature data up to the cloud. I'm sending it in this temp.qo Note file. Again, remember that one Note file can store multiple Notes. If you're in more of an offline scenario, you might want to queue up 10, 20, 30, 40, 50 Notes in a single Note file and then sync those all to the cloud later on. I'm going to sleep for 20 seconds and perform that loop forever and ever and ever. Let's just run this, and we'll see all the debugging output here. You see the temperature comes through in Celsius and Fahrenheit. We've got our note.add request with that temperature, and we're syncing that data immediately. You'll see red; it's way too hot in here for a baby, technically speaking.
Speaker: TJ VanToll 52:01
But even in your basement, Rob, that's a warm, it's a warm basement.
Speaker: Rob Lauer 52:07
I think it'd be way cooler. Good. My data is being gathered. Again, as TJ was showing off, that total one means there's one Note ready to be queued. It looks like my data is going through the Notehub immediately, so let's just prove that out by reloading my Notehub project here. Of course, we're seeing that data, oh sorry, we're seeing the device come through here. We're seeing those events right here. I can drill into this event. This is nothing that you haven't already seen from TJ, but just to prove out that this data is coming through. Finally, I did want to show off the creation of a very simple route, and what I want to do is slightly different than what TJ showed. I want to use, really my favorite testing site is webhook.site. This makes it just dead simple to test out these routes. If you go to webhook.site, you just get a unique URL that you can use. I can copy this in, I'm going to create a route, it's going to be one of our generic or general HTTP request response routes. This is as simple as it gets. I'm just going to call this Pico Route. I'm pasting in that URL from webhook.site. There's a lot more I could do in here in terms of adding headers for authentication purposes, maybe. You can choose which Note files you actually want to send. You probably don't want to send all of your session metadata; you just want the data itself. You can also transform your data with JSONata, which can be really, really powerful to optimize that payload. I'm just going to keep the defaults here and create a new route. It's been created. I can hop over to webhook.site, and there, some data just came through. It shows you really how easy this can really be to get data, obviously, in my case over Wi-Fi, but I could swap in a cellular Notecard and do exactly the same thing. Really just in a matter of minutes. With that, let me pop back over to our quick recap here.
Speaker: TJ VanToll 54:20
What I like about using the Pico too is it really does make these sort of low power situations totally possible. Like you could run that sort of thing off a battery 100%.
Speaker: Rob Lauer 54:33
Yeah, so we just wanted to really thank everyone for attending here. Before we get to the Q&A, make sure you visit dev.blues.io for all these technical resources like our Quickstarts or API documentation and some of the tutorials. Also even more importantly, just for being here today, you can take 15% off your first Raspberry Pi starter kit at bit.ly/pi-day-15. With that, I think we can safely jump into some questions here. I know we're running up against the top of the hour. We’ve got so many questions here I don't even know where to begin. Let's see.
Speaker: TJ VanToll 55:14
Well, we should say, if we don’t get to your question because we want to respect your time and that’d take all day as well, the Blues Forum, which you can get to by just going to the support link in dev.blues.io, is a great place to ask any questions that you have. Rob and I both work there, as do a lot of other people at Blues. If we don't get to yours, sorry, we're going to do the best that we can, but that's a great place to ask if you have any questions about, yeah, literally anything.
Speaker: Rob Lauer 55:40
So many good questions in here. I'm not afraid of any negative questions either. As an example of a “negative” question, somebody asked about the accelerometer on the Notecard. We do have an accelerometer on the Notecard, which is really great, because it allows us to dynamically turn on or off the GPS module if there's movement that's been detected. But somebody's asking, “If there’s an accelerometer, why is it not exposed?” We do not expose accelerometer data through the API. It is on our roadmap, but it is surprisingly complicated to do so, for reasons that I cannot remember. Anyway, just wanted to put that out there. There is an accelerometer, but it is not exposed through the API.
A question came in about how long it takes to get a GPS position fix in clear sky. This, you know, GPS is kind of the bane of my existence, because it really depends on so many things like, are there any obstructions? Is it cloudy, and blah, blah, blah, you know, what kind of antenna are you using? In really ideal scenarios, you should get a connection in less than a minute. It can take longer, again, depending on where you are in the world almost and how good your antenna is.
A question came in, “How much data can you send to the Notecard at a time?” This is a really valid question. I mentioned in the beginning of the slides that we do support file transfers with the Notecard. Really, our general rule of thumb is that you can send about eight kilobytes at a time over even the worst cellular connection. To accommodate file transfers, which obviously are probably going to be a lot larger than that, in the API, we bake in the ability to chunk up the data into like eight kilobyte chunks, or whatever you specify, and send those to the cloud one at a time, and then reassemble that file in the cloud. All the capabilities are built in, but we have to make some accommodations for how, you know, cellular may change.
Speaker: TJ VanToll 57:53
Yeah, and I'd also say, that sort of thing is possible, but keep in mind that the Notecard isn't intended for any sort of high bandwidth situations. If you are talking about… well, small files are fine. We have people that do things like sending images over using the Notecard, but any sort of higher bandwidth situation, it's going to be rough, because remember, this is a cellular connection we're talking about. So just something to keep in mind.
Speaker: Rob Lauer 58:22
A good question came in about powering the Pi for cellular access. Yeah, I mean, I've had luck with, for example, the Pico here, we do have a LiPo connector. If you have any kind of lithium polymer (LiPo) battery, you can connect that to the Notecarrier and it'll power the Pico. You could connect, I mean, you don't need much, frankly. Any LiPo battery, or in the case of a full-sized Raspberry Pi or Zero, I've even used like a big USB-C power bank for those too, if you really want to go the overkill route, but there's a lot of options there.
Somebody asked about the code difference between sending data via Wi-Fi and cellular. It is one of the beauties of the Wi-Fi Notecard is that there are no code differences: It’s the same note.add syntax. There are Wi-Fi specific APIs for setting up that connection to your Wi-Fi router, but that's about it.
Speaker: TJ VanToll 59:23
Yeah, really, for the Wi-Fi Notecard, you just run a card.WiFi request and you provide your SSID and password, and then from there, it's quite literally identical from everything else.
Speaker: Rob Lauer 59:37
Another question about power: “For the Notecarrier A, is there a specific brand of solar panel and battery recommendation?” Solar panel, well, you could do, there's so many options out there. I have one in particular that's stuffed somewhere that worked fine. Battery, again, any LiPo battery should work. I always recommend people go to Adafruit.com to buy their LiPo batteries. They seem to have the best quality ones.
“Any plans about offering a LoRa Notecard?” No, but we do have a LoRa product that we're—or a reference design, I should say—that's coming out shortly called the Sparrow. It’s definitely outside of the scope of what we're going to talk about today, but the Sparrow effectively communicates, is a LoRa gateway—sorry, not a LoRa gateway—it acts as a gateway to LoRa sensor nodes. Then it uses either a Wi-Fi or cellular Notecard to then back haul that data, relay that data, to the cloud. Kind of a deep conversation to get into at the very end here, but we do have that option coming out soon. I know we're over time, so I appreciate y'all hanging out here. Let’s see if there's one more question in here. Oh boy, there’s just so many to look through here.
Speaker: TJ VanToll 1:01:03
Pick the best one.
Speaker: Rob Lauer 1:01:04
I know. Let's see. Okay, one just came in, I'm going to do this one. “Wi-Fi will fail over to cellular and vice versa?” No. The Notecards, there are two separate Notecards. The one you see here—I think I’m still showing this camera—is the Wi-Fi Notecard. That's Wi-Fi only. There is not a Notecard that has cellular and Wi-Fi in one. You'd have to develop your own PCB effectively to include both Wi-Fi and cellular and then get kind of fancy with doing failover yourself, but it's a very good idea. I think with that, we will shut things down here. Thank you again everyone for attending. Hit us up. You can follow us on Twitter, or you can reply to the email that we'll send out shortly with the follow-up resources.
Speaker: TJ VanToll 1:01:57
Yeah, and I'll remind people one last time, discuss.blues.io is our forum. If we didn't get to your questions, I'm sorry, but that's the best place to follow up and we can continue the conversation there.
Speaker: Rob Lauer 1:02:08
Excellent. All right. Thank you, everyone.
Speaker: TJ VanToll 1:02:12
See ya, everybody. Thanks for coming. Happy Pi Day.
Recommended Videos
Monitoring Legacy Analog Systems with TinyML, Edge Impulse, and Blues Wireless
Using Machine Learning and modern IoT, we can modernize by tracking and reporting on existing systems in previously unheard of ways.
Rapidly Prototyping Environmental Monitoring IoT Devices
We dive into challenges and solutions for adding wireless connectivity. Between cellular, LoRaWAN, and Wi-Fi there are a myriad options and potential pitfalls. Walk away with real advice for building your next IoT device thanks to the experiences of Clean Earth Rovers and LimnoTech!
How to Create IoT Asset Tracking Applications with Drag-and-Drop Tooling
Datacake and Blues Wireless team members showcase an end-to-end technical demonstration of actively tracking assets with GPS and cellular, securely delivering tracking data to the cloud, and building a robust cloud-based reporting application.
Global Asset Tracking with a Cellular Notecard and Datacake
Asset tracking is a common, useful, and pragmatic IoT use cases. Whether simple journey tracking or complex monitoring of global medical supply shipments, it is key to implement an accurate, low-power asset tracking system.
Getting Started with Blues Wireless and the Notecard
Join us to learn the basics of Blues Wireless and the Notecard!
Lightning Fast – From IoT Concept to Pilot With Additive Manufacturing
In this webinar, we discuss innovative ideas that reduce time and risk in hardware product development. We’ll explain how you can get your IoT product to pilot phase much faster and cheaper than your competitors.