Tip:
Highlight text to annotate it
X
Hello again, Rowland O'Flaherty here, robotics PhD candidate, Georgia Tech.
Today is our seventh and final hardware lecture
and our continuation of Physical Computing, part three.
So as promised, today I will be talking about Serial communication with, really
any micro controller, but specifically the BeagleBone Black because
maybe many of you have purchased it, purchased it for the
quick bot. So let's get started,
so you already saw in last weeks lecture, and actually on the quick bot, interfacing
with sensors using reading raw analog values.
But many sensors provide a much easier way to
communicate with them using serial data. So this allows what the sensor does is it
transmits and receives raw characters from your device.
So there are three standard serial communication protocols.
First one we'll talk about is just known as serial, which is used via the UART.
What stands for Universal Asynchronous Receive and Transmit.
This is actually a device on your micro-controller,
which will receive and send the serial data asynchronously,
so it doesn't. Kind of think of it in the background.
And this uses two wires, the receive and transmit wire.
And, there are many different protocols for
which serial data is sent, using the UART. At the most standard is known as 8N1 which
stands for eight data bits, no parody bits, which is like a
check bit, and one stop bit. And then you pick what's
called the baud rate, how quickly the bits are
being sent, and a standard baud rate is 9,600.
So, what's nice about Serial, it's very easy
to set up, you just have two, two lines. Receive and transmit.
The next one is known as I squared C, this stands for Inter-Integrated Circuit
protocol. It also uses two wires, but instead of a
receive and transmit it has a data and a clock.
So the serial you can kind of think of it as two people talking over a cell phone.
So they can talk at the same time but they only can talk to each other.
What's nice about I squared C, it's more like a conference call.
Where you have one person conducting the call And
everyone can hear what everyone says at the same time.
That's because all data is sent over the data line.
But it's coordinated with the click line and the,
the person conducting the call is known as the master.
And they ask each person, specifically, the data that he wants to send or receive.
So you can't sent data at the same time, because there's only one data line.
But you can easily add new devices because you
just daisy chain them along this data and clock line.
The next one is SPI, Serial Peripheral Interface Protocol.
This kind of combines both of the best things of I²C and, and Serial.
What this uses is four data lines. So, a clock, what's known, then, what's
known as a master out slave in. A master in slave out, and then a slave
select. So you can kind of think of this as
someone who can talk directly to someone else via
a cell phone. A regular conversation over a telephone.
But they can call different people if they would like to.
So that's what you use the slave select for.
So it's all choreographed with the, the clock line that makes
the switching happen in the, in the correct time and you
receive and send data over the master out, slave in, slave
out, master in and then you select which device you want to use.
So for example GPS a lot of times will use a serial, so it just streams
as a protocol in that the serial data is coming in that has all the information.
And then a lot of other sensors will use both I²C, SPI, or even analog, all three
of them, so you can choose, for example an accelerometer, a gyro, a temperature
sensor, pressure sensor. Many different sensors.
And so they're very easy to interface with.
Using Serial communications. So on the BeagleBone, you actually have
four UARTs, two I²Cs, and two SPIs that you can use.
For example, here you can see the lines that are used, or the pins
that are used for I²C, and then, that's just one of them, and then another one for
SPI and then, you can see that serial data is
on, listed here, so you can just go look up.
The, pin information, and see what pins you
have to use for each one of these protocols.
Now, you have to remember, again. The BeagleBone Black's GPIO pens run at
3.3 volts. So if your sensor runs at five volts,
you're going to need to use what they call the logic level converter to
convert that 3.3 volts to that five volts. because you want to be very careful not to
burn out your BeagleBone Black. Okay, so what I what I'll be showing you
today, is how to use serial communication, on the BeagleBone black and we'll actually
be communicating with an Arduino. So, here's the circuit shown here and like
I just said, the BeagleBone black runs at 3.3 volts and araiuno runs at five
volts, so you need to use a logic level converter, what
this does is basically. Will take any data coming in on, these
other data lines here actually. The yellow and green ones.
[BLANK_AUDIO] These are the transmit and receive lines.
Take any data coming in over those and have it be 3.3
volts on the BeagleBone black side and five volts on the arauino side.
So that it's, it's pretty simple to set up, it has a low and high voltage set,
so you just connect one to five volts and connect to one to three volts and five
volts. So, pretty simple circuit
but first we have to set up the BeagleBone Black to, be able to use Serial.
And so instead of going through the whole tutorial, what I'm
going to do is point you to a great tutorial online Adafruit has.
And that you can easily work through to set it up.
Let me go ahead and navigate that, to that.
You can see they have an overview of how to set everything up, for Angstrom or
Butu, and then actually I²Cs, and SPI, and the UART.
So if we take a look at the UART, they list all the pins that are used for the
Fouriers, and how to set everything up. So the basic overview is, you're going to
*** the BeagleBone Black, and then install
some Python libraries. The commands are listed here, they're also
listed on the, Adafruit website. And then you're, you're pretty much set to
go. So, you have to also run this code here,
so let me just go through this Python code.
And the first line tells you to use a Python interpreter and then, import
those libraries. You just download it from Adafruit and
also import the serial communication. And then you're going to do a serial
setup. And you're going to say, you want to use
the fourth UART on the BeagleBone Black. And then you're going to create a serial
object. And you select the baud rate.
And again, it's for the fourth UART. And then you, just open that, and send.
You do a write to, to send out whatever string you want to send out over
those lines. So let me demonstrate this on the circuit,
I have it set up here. I have my BeagleBone Black connected
through a logic level converter, to an Arduino, and they're both connected to the
computer via a USB. So let me demo this Serial
communication for you so, the first thing is, you'll need to download the code.
It's on the [UNKNOWN] repositories. And the code is both there for the Arduino
and the BeagleBone Black side. So here, you can see the, Arduino ID's
opened up, and the code is copied into that.
So just upload that to your Arduino I've already uploaded it.
Once it's uploaded, just hit the serial monitor, and you should see.
It says it's ready to read and write from, it's using a soft serial.
Because the built-in Arduinos connected also to
the USB which used to upload the codes. So it's nice to have that on the soft
serial so you can upload code without having to unplug it.
Then, open up a terminal and you'll need to *** your BeagleBone Black.
So it's connected over the USB, so that's going to be at 192, 168, 7N2.
Connect here, no password, so again, you will need
to clone your the BeagleBone black, or the Quick Bot repo has the code in it, so
let's just go ahead and change into that, and then you should see a serial test
folder in there so go ahead and change into that.
And then I have a set-up script in there that
you can run, it sets up the, the serial data.
Now you still have to run those commands through to download the libraries, it just
sets up the, this, the yurts after each that you need to do after each reboot.
So serial setup, run that and then, you'd run the serial test.
Let's just look at that real quick, serial test.
And that's the code, that same code I went through.
So let's run that, serial test and what you should see, over
on the, the Arduino side is that it says hello from BBB.
Now let's go ahead and set up a two way communication
in real time, so we're going to use a program called Minicom.
So, Mini Com, and we're going to set the baud rate to
9,600. And the device to, we're going to
communicate over the fourth UART. Now recognize that this is a capital O not
a zero here, So O4. [SOUND] You should open that and then what
you can do is type directly in here, you can see as I press keys
they're showing up over here. So I can
say hello from BBB and the enter doesn't go through it looks
like. Or I can come over here and talk from the
Arduino and send messages. Hello from Arduino, and that shows up
here. So this is not going through the commute,
the computer this is communicating directly over that
transmit and receive lines. To exit this you're going to hit control
a, z, x enter.
The command is listed there. Alright, so that's the quick demo.
On the out of fruit website you can also go through how
to use I²Cs and SPI, they're pretty much the same and similar.
So, I'm not going to go through those right here, what I'd like to say,
this is the final lecture, but what I would like is for the discussions
to continue on past the course. There's been some great.
Threads that are taking place in discussions on the Coursera forum,
and I would like there to be a place for that to
continue once this course ends, so I have created a GitHub organization
and a new website, both called O'Botics, which stands for open robotics.
And these are supposed to be places where everyone
can contribute, and edit, and see everything.
It's all open, so let me, for example show you the Get Hub repository.
Now, move the repositories over from bit bucket to Get Hub because Get Hub is more
widely used and, a better place for collaboration from what I've heard.
So, for example here you can see the Quick Bot Local, Quick Bot BBB.
repositories, all the code is in there. What you can do if you don't already have
a GitHub account is you can create an account, and then come
right here and fork it. That will copy all of this whole
repository to your account. You can make whatever edits, you can
do anything you want to it, everything's open.
And then if you actually want those to be included back into The
this repository, you can then do a pole request and then those can be included.
There is also a website, O'Botics, which is
actually hosted from GitHub, so that's another repository.
You can see all the source code that's used for this.
And this is a place to, to, show every all the details for the quick bar or any other
platform. This is being created right now, It's
brand new, so there's not much on it right now, but I have, maybe the place for the
Quick bot so more robots can be added. And so if you want to add your own robot,
go ahead and fork this repository and do a
pole request. Boom, it'll be online for everyone to see.
There's a place that you can make comments.
This is run through discuss, so this whole website is using Jackal,
so the content, these are static pages. You, you create the static pages offline
and then you just do a, git push, to have them
published. So, yeah, this is the last lecture.
I want to say thank you, for all the participation,
that the students that you have done in the course.
It's been really exciting to see the pictures and videos.
Had been posted at the Quick Bot working, and I hope this activity continues past
the course. So, thanks again.