Particle have provided us with a cellular solution, the Electron. Gone are the constraints of Wifi, your IoT device can enjoy a direct connection to the internet anywhere it has cellular connectivity. In this tutorial, Sam explores the Electron and getting started with it.
Hey Guys, Sam here from Core Electronics and today we’re going to be taking a look at setting up the Particle Electron with the Particle iO Cloud Service. Now if you haven’t already I recommend going and checking out our Welcome To Particle .io tutorial as it covers the broad features of the Particle Cloud Platform and has a bit of a comparison between the Electron which is our 3G Cellular Board and the Photon which is our WiFi board.
But today we’re going to look at getting the Electron set up and going for the first time, writing our first program to it, claiming the device and setting up the SIM card and everything like that. So with your Electron Kit we’ve got the Electron Board, obviously, and here we’ve got the 3G Cellular Module here from the Ublox which handles all the cellular communication, the reset and our mode buttons - they’re for entering different device modes. Theres a USB connector and a JST connector for the battery, header pins here - so they’re our GPIO pins and we’ve got 4 registers of out puts A,B,C,D along with voltage in and voltage out. We’ve got a UFL antenna connector here. So that is the Electron Board, now you’ll get your Particle SIM card - it’s very small, and the antenna which connects via the UFL connector just here, a USB cable and the battery. Along with that you’ll get a bread board and a few components to get you started. It’s really important, you know the Electron is designed for mobile use and alot of people say “oh why do I need to buy the Kit with the battery? I don’t really need that, I’ll just be running it off USB power” and that’s fine but the typical USB port on your computer will only allow you to draw 500 mA maybe up to an amp if it’s a high power USB port and the Particle Electron board when it’s idling it might only be drawing a few hundred mA’s if that, but during cellular communication it’s actually going to be pulling between 800 and 1800 mA. Now that is going to be a big issue if you are drawing it off USB supply. So they include the battery and this is a 2000 mAh 3.7V Lipo battery and it connects into the JST connector just here and now that is actually turned it on because the battery comes charged. So the important thing is the battery is there to help out with that extra current when its connected by USB it will be charging the battery and there is a little indicator LED on the board to let you know if the battery is not connected or whether it’s still charging or if it’s fully charged.
To set up your Electron board you are going to want to go to the Particle.io page and there is a set page which is set.particleio but before we do we’ll look at some of the features of the Electron Board. It’s got an ARM Cortex Processor running at 120 Mhz, it’s actually the same specs as the Photon they’ve just done away with the SoC (System On Chip) here and broken things out underneath here as you can see. It’s got, from memory, 1 MB of Flash Storage so yeah, really abundant storage and heaps of RAM and you’re going to be able to write some pretty powerful applications with this. Yeah it blows a lot of the ATMega chips out of the water, specially for the price. Now we’ll go ahead and we’ll look at getting this set up. So we’ll go on to the set up page here, but I’ve already set this one up with the SIM card so it will tell me that it already has been set up but I’ll go through the process as well. Something to keep in mind is because it does use a SIM card you’re going to get billed from Particle to use the SIM card. Now they’ve actually got fantastic data rates, so we can go in to the Particle Console which is here and you can see the billing here and as you can see it bills in MB which if you are used to a data plan on your phone or home internet a MB! You might be thinking that they are pretty stingy but the thing to recognise here is we are not streaming Netflix or watching YouTube videos of funny cats! What we are actually doing is just sending individual Bytes and data packets and strings which doesn’t really use a huge amount of data when you think that 1 byte is 8 bits and in a kilobyte you’ve got 1024 bytes and in a MB you’ve got 1024 kilobytes so you can actually transfer quite a bit of data just using 1 MB. So it starts of at AU$2.99 per MB and then you can get additional MB for AU$1.99 after that and it just automatically bills to your account. Now the great is that Particle have actually developed a soft SIM network for the Electron which means that you can plug it in and it will recognise which country you’re in and it’s designed to work all around the world and pretty much every country in our 4 separate zones with their own different billing rates but I can take this guy anywhere in the world with me and I know that this SIM is going to work and going to be connected to a great network and the billing rate is going to remain roughly the same which is pretty cool.
You can use third party SIMs with this and we’ll be doing a separate tutorial on that. There is a little bit of set up to go through if you want to use your own carrier SIM with that, it’s very doable but we won’t be covering that in this tutorial because this SIM is plug and play and it makes it very easy to get started.
So we’ll go to the device Set Up, you can set up a SIM card by itself or you can set up the Electron with the SIM card. So we’ve got the Electron Board, SIM card which we’ve already punched out of our card carrier, Lipo battery, the antenna and the USB cable. Now you want to go here and put in your Particle SIM number, that number is written on the SIM there and it’s also written on the larger piece of card that you punched that guy out of. You are going to want to put that in here. I won’t because I’ve already set this SIM up, but if you go ahead and do that you’re a couple of mouse clicks away from getting your device set up. So go through and do that and once you’ve got that sorted then we can go back to getting set up and getting our first program done.
So we’ve just got a bit of a note there about the power requirements and with the Photon, it’s a WiFi board which means that if you want to put your application on there, your program, you can flash it over the air (OTA for the acronym types!) and away you go. Now you can do the same thing with the Electron but bear in mind that that is going to consume data and unlike the WiFi Board data is a precious commodity here. You might think, oh my application is only 2 Kbs and it’s not going to use a huge amount of data but along with that you’ve actually got handshake bytes that have to be transferred,all of the communication protocol bytes and if you leave the Electron running then every, I can’t remember but I think it’s 22 minutes it sends out just a bit of a handshake acknowledgement byte to the Particle Cloud to make sure it’s still connected, still live. So you’ve got a bit of overhead data usage but it is kept to a minimum so we’re going to look at actually putting our program on to the Electron via the USB cable using the command line interface because obviously that is going to save our data usage. So we’ve got to do a little bit of set up here, uses the node.js command line interface for this. So we’re going to go ahead and first of all we want to go into the Particle Build section so, build.particle.io and we’ve got our application. So you want to copy the code here, (8.21min) which is really just the same as the blink example but we’ve just broken it down to here using the on board LED. Copy it over in to your program, now the idea of this is quite simple, it sets up digital 7 as an output with the onboard LED, it turns it on, pin high, waits for half a second, turns it off, waits for half a second, loop and repeat. Quite a simple code, that’s the hello world of electronics so we’re going to do it because it is fun. So go to our device tab, device is down here and you want to make sure you’ve got our different devices down here, so what we’re going to do now is plug our device in and get it all powered up. So we’re going to connect it by USB first, it doesn’t really matter what order you do it in, I just like to go USB first. Alright, so you can see it’s not connected to the cloud and we’ve got a few different LEDs going on here. This flashing LED rapidly flashing indicates that the battery isn’t connected and it’s telling us that it should be so we’re going to plug it in here. And when it’s turned off it’s nice and happy. Now you can actually just power it over a USB as I was saying if you’ve got a beefy 2A on a USB supply or using the external Vin Pins, thats fine too, not a problem. So now we’re going to put our SIM in, you might have already done this if you’ve set it up. It goes in this way and you can see there is a little cut out in the corner of the board and that is going to go into the top left , you just slide it in like that and it should be flush with the board. We’re going to want to connect our antenna because it will have a hard time finding the cellular network with out an antenna. So just put it on to the UFL connecter, there we go, so it’s actually in listening mode at the moment which means it’s ready to accept programming via the command line interface (CLI) it does a few other things.If it’s not already in listening mode then you want to see the mode button there, you’ve got your reset and mode buttons. You want to press on the mode button and hold it for 3 seconds and your RGB status LED should start blinking blue which indicates that it is in listening mode. Alrighty so we’ve got that set up and connected and in listening mode so we are ready to go.
Now the first thing we want to do is download the binary for our code so rather than flashing it over the air and just kind of uploading it to the board like we are used to we’re going to download the binary file which is a .bin extension and is literally a lot of ones and zeros telling our microcontroller what to do. So once you’ve got the Electron board, so you want to select your Electron board, the appropriate one. I’ve got two on my account at the moment, go to the code tab, there we go. Now I’ve actually copied and pasted this in to a blank application so I’ll just copy that again and what we want to do is create a new app. So the current app title is Blink-Demo, so we’ve named our app, hit enter, give it a name, put our code back in and there we go. So we’ve named our app we can see that the files in it is blink-demo.ino which is our application file. You’ll see this little button here which says compile and download firmware binary so we want to hit that and it will compile your code and make sure that it is executable on the board. Give it a second and it’s going to download this binary and we’re going to save it on our computer and then send that over our USB cable on to our Electron board. So now we’re going to save it somewhere so we’ll go save, file, now…… where has it saved it to? I’ve got a feeling it will be downloads, so yeah we’re going to grab that and I’m going to put it in the user directory because I know that the Command Line Interface will automatically be in that folder. You can alt navigate to any folder you want in that command terminal but if you’re not used to the folder navigation then it might be easier just to put it somewhere that you know it’s going to be able to instantly see it. So I’m going to go to users, go here and I’m going to whack it in there. Now i’ve just put it as firmware.bin you can rename it to blink_demo, that’s probably a better way to name it so you can keep track of everything because otherwise you’ll have a lot of firmware.bin files. Alright, cool, so we’ve got our binary file now so what we want to do now is get the command line interface all set up. So first we want to install node.js now that is just sort of the command interface that we’re going to be using and it’s very useful. So you can click the link here in the tutorial to get the download and now I’m going to go through and set it up on this computer. I’m just going to go the LTS version because I don’t really need any of the latest features and it’s guaranteed to work, it’s going to be stable build, and I’m just going to save that, open that and we’re just going to go through the installation process - it’s fairly standard. Alright, now I am doing this on a Windows computer and there is a different way you’ll need to do if you are using a Mac, you now OS X or a different operating system. We may cover that in another tutorial, generally we stick to windows for things like this because all of the applications we’re downloading are just going to work with it. So we’ll just go through and install it as you would normally. So now we’re finished the installation process there and we’re going to go through back to here and now we want to open the node.js command prompt - so open that up and we want to actually go into the node.js prompt not the node.js applications. So we’re going to open this up and now we’re going to type in npm install -g particle-cli and you can see that in the tutorial there. Now its just going to do its thing and it may take a few minutes for it to download everything. Pretty much we’re downloading the Particle Command Line Interface here going through node.js. We’re going to install all the functions and Particle things you can do. You can log in to your Particle account, flash firmware, update firmware everything like that just by the Command Line. You might prefer working this way and you can actually do it with your Photon and your Electron, it’s not a problem. I prefer working in the cloud IDE just because I can see everything thats there, I can see all my apps and It’s a bit nicer to flash firmware through that but if I’m working with the Electron I’ll download it and go through here because I don’t want to chew up my data. So we’ll just give this a moment to download and sort itself out - I’m going to time lapse this bit because it will look cool! :-) Alrighty and after some quality twitching of the thumbs we are ready to go. So we want to go Particle login and it’s going to let us log in with our Particle account, give it some time as the first time you do it it might be a bit slow. Put in your credentials here, so thats email address, login in and password. Alright now it’s going to log us in to the Particle Server, login completed thats fantastic. Now you can see that our directory here is \users\coretec that’s where I put my binary file so I don’t have to do any folder navigation inside of the command prompt which just makes things a bit easier and a little bit quicker and it’s the way I prefer to do it and now if we scroll down in the tutorial we’re going to be flashing it over serial which means we’re in listening mode.You can flash it via USB but you need to be in DFU mode and install the DFU utility so there’s few more steps. So flashing it over serial works just fine. So Particle flash —serial (then your file name but obviously we’re going to put blink_demo or what ever you decided to call it, your intelligent file name).bin hit enter and you can see in the screen shots below its going to just prompt us to make sure that our device is in listening mode. So it is blinking blue, fantastic, we’re going to hit enter and it’s going to recognise the device and you can see it quit flashing magenta, showing it’s uploading and it’s just going through a reset process here.Now you can see that my Electron is breathing white which means that it’s not connected to a network and it may just do that for a few seconds after uploading.Now it will take just a moment to search for the cellular network, it’s not quite as quick as the Photon and once it’s connected if you just hit reset it’ll connect really really quickly but if you actually disconnect power completely it will just take a few moments to connect to the network so again we’ll just wait until it does that. Now you can close your command prompt if you like, we don’t need that so we’ll just minimise it, either ones fine and once it’s done we should be able to see our LED blinking. Now there we go, so it’s connecting to a network and we’ll wait until it starts breathing cyan and there we go and we can see our code running, so it’s just blinking the LED on and off, the ‘hello world’ of electronics,marvellous, cool! Everything is AOK, it’s breathing cyan, we’ve got it connected to the cellular network, antenna, battery, and now we can disconnect the USB cable and the battery life is 2000mAh so that is going to last you quite a bit if you are really careful with your power management on your Electron. There we go, there you have it - we’ve set up our Electron, we’ve got it connected to the 3G network, we’ve flashed our firmware to it using USB so we don’t chew through our data so yeah, that is pretty much the basics of getting your Particle Electron board up and running.
Check out our other tutorials for awesome projects, great ideas and more info on how you can use some of the extra features on the Particle boards and I’ll see you next time, thanks guys :-)
Makers love reviews as much as you do, please follow this link to review the products you have purchased.