Hi I’m Tomi Mester from Data36.com and this is the second episode of this new series where I document a new hobby project of mine that I call “Growing Strawberries with a Raspberry Pi, on autopilot.”
In the previous episode, I told you that I don’t know anything about Raspberry PIs. But that’s the beauty of a hobby project: you have to learn new things.
The first thing that I have to figure out, and that I’ll show you in this video, is:
How to connect to the raspberry pi at all?
I don’t have a keyboard, an extra monitor or a mouse, so my only option here is to access the raspberry using my wifi connection in the office — and once I have that, I can control this small computer from my Mac. I’ve Googled it so I know it’s possible.
So let’s do it!
Okay, when it comes to learning new things, I usually follow these steps:
>> I start to search for practical examples and tutorials – preferably in video format, so I useYoutube or I take mini online courses, and so on.
>> I try to discover the official documentation of the project, so in this case it will be raspberrypi.org.
>> And then, simply: trial and error. I just start to do things, write code and so on — and whenever I get stuck, I either look at the documentation or I Google stuff.
Just a quick comment, that anything I mention in this video: tutorials, get-started materials, articles or anything else that I’ll use for learning myself, I’ll add the links for them in the description below. Probably, there’ll be so many that I won’t mention this all the time, but remember, anything I talk about will be linked in the description.
Now in this project, luckily, I found a good starting point really quickly, because I knew that I wanted to use *Python* for my project. And so I went to Youtube and searched for “Python Raspberry PI” and immediately the second result is one of my favorite Youtubers, sentdex, who happened to have an hour-long tutorial on the topic.
So I’ll just go ahead and watch that tutorial.
Okay, it was a pretty good introduction. And you know the project in sentdex’s tutorial is pretty different from what I want to do in my project… still, it feels like a good start that I watched it, because it gives me a sense of what exactly I’ll have to do here. And also an estimate about the size of the project.
And one thing I realized is that the things that really scare me are these pins called GPIOs… since you know I’m more of a data analyst type of person, I write code on my computer, so I am used to USB cables and stuff like that — but these little pins, that all look similar but do different things, and the fact that if I wire something wrongly can kill my Raspberry PI, scares me. But not too much anyway.
And that won’t be an issue in this video because as I said, right now, I just want to connect to the Raspberry via wifi, nothing else.
And that takes us to the second step.
I’ll just go to raspberrypi.org and check out the documentation and the get started tutorials of Raspberry.
And I have to be honest here, when I started this project, first, I didn’t want to go with a Raspberry PI, I actually borrowed a small microcontroller instead, from my brother-in-law. I won’t name the brand or the hardware itself — but the point is that I didn’t go with it because the producer of that microcontroller just didn’t provide enough get-started-materials. You know, it was very poorly documented, it wasn’t easy to find working examples, the tutorials were messy. So I just decided to go with something that it’s easier to get started with. And this is how I ended up with the PI.
Now, getting started is pretty straightforward here, I need an SD card, that’s something I actually knew, so I ordered one already, that I’ll have to plug into my computer and just follow the 40-second video tutorial on raspberrypi.org/software.
Okay, I’ll go ahead and choose the right OS.
Okay, so in theory, the operating system is ready, and I just should plug this SD card into my raspberry pi.
But as I said, I don’t really have a keyboard, a monitor or a mouse, so I have to access my PI via wifi using the command line and preferably an ssh connection. I won’t even bother with the graphical user interface of the raspberry pi, I know it exists, I just won’t need it. Everything I need can be done in the command line.
And a quick comment here: if you don’t know what the command line is or how that works, or you don’t know the ssh command, go ahead and check out my bash tutorials that I linked below this video.
So I’ll have to ssh from the command line. And for that, I actually searched for a tutorial on raspberrypi.org… And I found a few that are not too bad… But everything I found here, sort of assumes that I have a keyboard and a monitor and so I can turn on the PI, configure it locally, and I can access it only after that remotely via wifi.
But in fact, what I need is to access the PI remotely via wifi *in the first place*, so I want to pre-configure the OS on the SD card before I place it into my raspberry PI — so it’ll automatically connect to my wifi and I’ll see and access it on my local network.
Now, after some Googling, I found the keyword that I’ll have to Google for… and that’s pretty typical in a hobby project. When you don’t know what you don’t know, you can’t even Google things. But after an hour or so I found this one, and so for a raspberry when you want to connect to it remotely without a keyboard or a monitor, it’s called “headless mode.”
Now, knowing this, things get easy because on raspberrypi.org there is actually a tutorial for headless mode and it’s pretty straightforward, too… Well, not really. So I edited out from this video my trials and errors — that took another hour at least — and I’ll just show you the actual solution.
Following this tutorial:
I’ll have to add a file with the wifi configuration… And when I turn on my Raspberry PI, it will automatically connect to the wifi in my office — that is the same wifi that my personal computer is connected to. The Internet is not even needed, only being on the same network is the prerequisite of being able to ssh to the Raspberry from my computer. And the file should look like this:
And it should be added to the /boot folder on the SD card — and the file should be called —-.
By the way, you can do this from any basic text-editor on your computer, but I recommend using Sublime Text which is my favorite editor for coding. If you don’t know it, I added a tutorial about it in the description.
But as it turned out, and that’s the part that I struggled with a little bit… So as it turned out, you can’t connect to the raspberry automatically via ssh even if it’s on the same network as your personal computer because you’ll also have to *allow* ssh connections. Which is pretty simple, well, if you find the right part of the tutorial which is here.
I just have to add an empty file called ssh to the boot folder.
And from that point on, I can ssh to my microcomputer using wifi.
Now of course, the next step is that I’ll remove this SD card from my computer and put the microSD card version of it into the PI. And, I’ll also have to turn on the raspberry which is as simple as plugging it in.
Okay, it’s working, so in theory, I should be able to find and see the PI on my network.
For that I’ll just have to open a terminal window on my Mac and type arp -a. Which lists the available devices on my network, and one of these is called raspberry.
And as I learned from sentdex’s tutorials, I can ssh in like this:
ssh pi@[IP address]
And pi is the default user name for all raspberry PIs… And actually the password is default as well, which is raspberry. So I typed that in.
And here we are. I’m in, right now this is my raspberry pi from the command line.
And this is a beautiful Linux-based operating system that I can interact with using simple command line commands. Again, if this is very new for you, check out my bash tutorials in the description because I don’t want to spend too much time with the basics. The point is that from now on, I can control this raspberry pi using my personal computer and the wifi.
All I need to do is ssh in every time I want to do something.
Before I finish this video, I’ll change some settings.
For instance, I’ll change my password to make this a bit more secure than a simple default password.
And I’ll just discover what’s on this raspberry.
Let’s see, I don’t know what folders we have. None. Cool.
Do we have Python3? I know we do, but it’s good to see, it’s working.
Also, let’s see what Python libraries we have access to, by default. I’m pretty sure I’ll have to install a few more in the next episodes. Okay, we have `numpy` installed — I don’t think I’ll use it in this project though. We don’t have pandas but that’s understandable, it’s a very data science specific library.
I’ll close the connection.
And I’ll try to log back in. Cool, it works.
And just one last thing: to turn on the PI, I just had to plug it in. But to shut it down, well, there is no button for that. So, I’ll just do it from the command line using the sudo shutdown now command.
And it shuts down.
And with that this is the end of this episode.
I managed to access the raspberry pi via wifi — without a keyboard, monitor or mouse. And as it turned out it’s called headless mode.
But the point is that it’s working. So in the next episode I’ll focus on making the moisture sensor work.
It’ll be exciting because I’ll have to use these GPIO pins that I’m so afraid off. But hopefully it will all work out okay. More about that in the next video.
If you liked this one, please subscribe, leave a rating or a comment.
And don’t forget to subscribe to my newsletter at data36.com/newsletter. This is the only place where I really communicate to my audience right now, so this is where you can get notified about new content, as well. And if you do subscribe, you’ll get access to a lot of free data science learning materials, too, like a Python cheat sheet, an SQL cheat sheet or a free mini course called How to become a data scientist.
Thank you for watching, I’m Tomi Mester from Data36.com.
See you in the next video!