 Continuing with this series on hooking your computer to your car, I'm going to show you how to use some shell devices to communicate with your OBD-2 USB to serial port adapter. So this is the second video. Last video I showed you how to use a GUI interface, a GUI, called Scan Tool to get information, read error codes, and just read diagnostic stuff. Well today we're going to be looking at doing stuff in the shell. That way you know how to do stuff to write your own programs. So if you want to write your own programs to display stuff or log stuff, we're going to be able to do that. So I'm going to hook up this again. Today we're going to be using a USB device. In the future video I'll talk more about Bluetooth devices. Luckily I'm going to hook this up, hook it to a computer here on my computer, here on my computer, hook it up to a computer here on my car, and then I'm going to go inside in the air conditioning where you don't hear bugs and I'll just SSH into this machine and do the tutorial that way. So hopefully audio quality and you'll be able to see stuff on the screen better this time around. So let's go ahead and get started. I guess I should mention for those of you who did not watch the previous video, the OBD2 connector usually will plug in somewhere down here to the left of your pedals. It's pretty much standard where the ports are and the plugs are all standard. So you plug that in, plug it into USB, and then we'll get into the software here, but that's where you plug it in if you missed the previous video. But I recommend watching it. So here we go. Okay, I am logged into my machine which is hooked to my car. My car is on outside by itself. I hope it's still there when I get outside. Let's check a few things. First things first, is the device hooked up? It should be a serial device. It's a USB serial device. So if we list dev, TTY, USB0, it is there. So that would be that device. Next, to be able to access it, we have to be part of the dial-out groups. So let's just type in groups. My user is part of the dial-out group. If you're not, you're not going to be able to access without running pseudo, which you really don't want to do. You can. It's your machine if you want. But add yourself to the pseudo or to the dial-out group. I've taught you how to do that a couple of videos ago. So check my videos for adding a user to a group. Remember, once you add someone to a group, they have to log out and log back in for that take to take effect. So now we should be able to access the serial device without having to be pseudo with this user anyway. So there's a number of tools you can do that. You can use Socat, Minicom. I like when it works, but I've had some issues with it recently. Screen is a very common one. Screen is an application that's used for a lot of things. Splitting your screen so it's very readily available. So we're going to look at that. Doing it this way. I can't figure out how to get it to give it a new line character properly. I could with Minicom. But let's go ahead and look at Screen anyway, since that is the option I have set up today. So I can just say Screen. And well, here's the command here. And I'll be sure to put the link in the description. Not a link, but yeah, link to the notes on this in the description of the video. I have lots of options here. Really, most of these are not needed. You should be able to just, in most cases, type in Screen, forward slash dev, forward slash TTYUSB0, remember that's case sensitive, and then your broad rate. The other stuff, again, I'll have a link in the description. Once I run that, I'm now connected. And now we can use some AT commands to communicate with the serial device. AT commands are used, have been around forever. They're used to communicate through modems and other devices. So I can type in ATZ, and I will hit Enter. And right there, you can see what I'm saying is that Screen isn't giving me a new line character properly. This should say ELM327 version 1.4. But the E is getting cut off by the prompt. And so, but we know that we're connected to the device. Now my car could be off, and I can still see that. That's just telling me what device I have hooked to my car. That's not information from the car. And the car does give that device power even when the car is not on. But let's grab something, some information in the car. Again, the car has to be on for this part. We have to give it some hex code. And I'm gonna say 010C, and I will hit Enter, and it'll return some hex code. Now, you saw, for a second there, you were able to see that it said 410C. Those first four characters are telling me what type of code was returned. And then the next part is a hex of the value. So I asked it for the RPMs. So this part, 410C is saying, here are the RPMs, and then this is the value of the RPMs. So I can take all of this, and what I'm going to do is I'm going to copy that. I'm gonna go to here, and I just searched online. I'll put a link to this in the description. This is just an online converter. So I can paste that number in there. Again, remember the first number was four, even though my shell was cutting it off. And it wants you to remove the spaces. So we're manually doing this. You could code out decoding this. But when I hit enter, it's gonna tell me that this is RPMs. It gives some information. But here's our value, 731, which normally in my car, when it's just idling, it's usually somewhere between 700 and 800. So we were able to grab the RPMs. If we were to run that command again, 010C, we're gonna get another value here. So we'll just copy that, go back here. And again, those first four digits aren't gonna change because it's RPMs, remove the space. And you can see it just went from 731 to 762, it's gonna constantly be changing. Again, all these things are documented. I'll put links in the description to all this sort of stuff. We're gonna say 010D instead of C this time. And that will be our speed, our current speed. So again, it's gonna start with a four. We know that. We're gonna go in here. We're gonna paste this. Again, these first four digits is telling me what type of value was returned. And when I hit enter here, it tells me here, vehicle speed, units, kilometers per hour. I'd have to convert that if I wanted to go miles per hour. Yeah, I'll put a zero because the car's not moving. I'd have to actually be in there for driving for that to be. So if that number wasn't zero right now, I'd have to be looking out the window and watching my car drive away. So that's great to sit here and type stuff. But if you're going to actually write a script to that's gonna constantly be grabbing information, your best option is probably not to just use bash or shell, this is great for sitting there typing. By the way, to get out of screen, it's usually control A then backslash. Since I have Tmux running and that's my shortcut key for Tmux, I actually have to hit control A, control A, and then backslash, oh, I messed that up. Control A, control A, backslash. There we go, and they will ask me, yes, I wanna close that window. Let's try again, backslash, yes, there we go. Okay, now there are libraries for Python. If you just Google search Python OBD, this is probably the first one's gonna come up. It's up on GitHub, it's free, it's open source. To install it, you do PIP install OBD, and that will install the library for you. They have some information here about Bluetooth stuff, which we'll get into in a future video. And then it has some example code here for miles per hour and it has notes on other things. But again, we'll grab our speed in kilometers per hour and miles per hour using this example code and we'll also look at RPMs. So I already have put those into two scripts here, RPMs and speed, if I cat out RPMs, you'll be able to see the code is very simple. Basically, we're saying this is a Python script, that's our shebang line. We're gonna import that library, the OBD library, and then we're gonna say, okay, we're gonna connect OBD. Now, this is gonna auto connect, it's gonna look for different devices in an order. If you wanna speed it up a little bit, you can tell it specifically to look for a certain device, in our case, it would be forward slash dev forward slash TTY USB zero in our case. But it's gonna auto connect if you don't put anything in there looking for, I think it looks for wireless devices first and then USB. Next thing we're gonna do is we're going to create a variable and in that we're going to put the output of our connection query and we're going to say, library OBD commands and the command is RPM. And then we'll just print that output. Pretty simple, let's go ahead and run that. I've made it executable. So I'm gonna say RPMs and when I hit enter, it takes a moment, it's gonna communicate with the device and output 710.25 revolutions per minute. Now, again, if we clear the screen, I'll type out or I'll cat out my speed script here. Again, this is just the example from the website, which there'll be links to in the description of the view if I don't forget, just under our notes. Again, this is a Python script using Python three. That's important for this library. Import that library, connect to the device. Again, it's gonna auto connect if we don't specifically tell it what device. Then we're gonna create a variable called command. You can call it whatever you want using the OBD library commands speed. These are just notes over here. And then we're gonna get the response of that command. So this example was written out a little bit different, but then we're gonna reprint out that value, which is gonna be kilometers per hour. And then we're going to convert that to miles per hour and print out the same thing. So all I have to do now, let me clear the screen. I'm gonna do dot slash speed, dot PY, hit enter, give it a moment to communicate. And then we'll get the information. The car is not moving. Again, if the car was moving, I'd be in trouble right now since I'm inside my house, wirelessly connected to the computer in my car. But that's it. That's a couple of ways. And again, there's many more ways to do serial device stuff. But if you're gonna try to code it out and script it out, I love bash. I love using just shell commands. But Python is a little bit better for communications like this. And there's libraries for it. So why not? But we, I might do a video. I've done video, because it's just a serial port communication. So you don't need this library to communicate using Python. You just need the serial library, which is in your repositories already. Problem is you'll still have to convert all those hex codes yourself for the RPMs and the miles per hour. And you'd have to look up all that stuff. Where this is all embedded in this very small library that's easy to install using PIP. Again, if you just search or look in the description of this video at the notes, PIP install OBD, and then you'll be good to go. So thank you for watching. Please visit filmsbychrist.com. That's Chris the K. There's a link in the description. And as always, I hope that you have a great day.