- On today's "Maker Mashup", we're controlling everything
with 3D printer G-code.
(funky ambient music)
Welcome Makers, when I started 3D printing,
one of the first things that I wanted to do
was to be able to control something else
with my 3D printer.
Maybe that was lighting or a button
that would possibly actuate something on my printer.
What I found out fairly quickly
was that there was no good way to do this.
And no way to control anything
other than the printer itself.
So back in 2019, I did a video
where you could use the second serial port
on your SKR version 1.3, along with a WeMos
to work over the serial connection
to get some basic functionality.
Now ultimately, I wanted a greater level of control
of my 3D printer, and other objects around it.
This left me with only one good option
and that would've been to modify
the 3D printer's firmware.
And I never went down that path
because it was far too proprietary
and I would've constantly had to upgrade the firmware
and my code with each new firmware release.
So I abandoned everything
and didn't take that project any further,
but that was until about six months ago
when I came across the Teensy 4.1.
Now if you're not familiar with the Teensy 4.1,
this is a small little 32 bit
Arduino compatible micro controller.
It's got a really fast 600 megahertz clock speed.
Now while the speed was impressive,
that wasn't the thing that caught my eye with this.
It was the fact that it supported a USB host controller
and this host controller would allow me
to plug just about anything I wanted into the Teensy
and interact with it.
So a lot of people use these for keyboards
or MIDI keyboards
and this was something in my opinion
that has been lacking in the Arduino space
for a while.
Sure, you could get an UNO
and it might have a shield that would fit on top
but everything that I had seen as really either
some sort of very proprietary solution,
and I wasn't really able to find a plug and play solution
until now.
And this is where the Teensy 4.1 comes in.
It allows me to connect a PC into the USB connection here
and then also with this cable right here,
I can go ahead and add another connection
for the 3D printer
and use this in a host mode.
So ultimately, it allows me to connect the computer
and a 3D printer, with a Teensy in the middle
and this was exactly what I was looking for.
It was really a way, by placing a Teensy in between
the computer and the 3D printer,
I could intercept G-code
and do basically anything I wanted.
And you can see that
because now Cableroot is born.
And Cableroot is some software
that works on a Teensy,
that allows you to inspect all of the G-code
and perform any actions that you want on it.
Now you could see here, I've got 300 neopixels
and another strand of neopixels,
each independently running.
But it doesn't end there, I'm also controlling a relay
with a fan, and this small display,
and it can power the 3D printer
and send all the G-code there.
All of this I can change with a simple command
of the G-code, turn lights on and off,
fans on and off, everything.
So today, what I'm gonna be showing you
is how this little small micro controller
can allow you to take complete control
over your 3D printer, G-code,
and control outside objects outside of your printer.
So with all that said, let's get to work.
In most of our 3D printer workflows,
we use a computer, Raspberry Pi,
or SD card to transfer data to the 3D printer.
With Cableroot, we change the workflow
to place Cableroot in the middle.
This allows Cableroot to inspect G-code
and perform actions, writing code to do all of this
would take a lot of effort,
so to simplify things, we use the Teensy Threads Library
to provide preemptive multi-tasking
on the Teensy itself.
This enables background tasks for communication,
lighting, and events, simple to implement.
So let's take a look at how we put all of this into action.
Our first step is good planning.
What do we want to control
and what hardware do we need?
Is this a relay? Is it neopixels?
Putting a plan together is really the most important part
of this entire process.
Once we have a plan in place,
we're going to need to do our basic hardware setup.
Now one thing to note about the Teensy
is that it does not handle five volts.
So we're gonna use a BOB-12009
to shift our 3.3 to five volts.
Today we're gonna be using a breadboard
and our plan is to control a relay.
So we'll do everything on a breadboard,
however, there is a Cableroot breakout board
that I've made, and I'll talk about that
a little bit later in the video.
Once we have the hardware all set up,
we're gonna need to write some code
and flash the Teensy.
Now the core Cableroot code has a relay example in it
and we're gonna be using that in our demo today.
So now that we have our plan together,
let's move on to the hardware setup.
Here I have the Teensy 4.1 on a breadboard
and the first thing we're going to do
is install the BOB-12009
onto this breadboard.
I've already attached pins on it
and we're gonna set it up right here.
Now what this device does
is it converts 3.3 volts
and this logic level converter
will then output five volts here.
It's bidirectional so it works both ways.
You don't need a BOB-12009
as long as this is bidirectional.
Ultimately, with a relay, we only need one direction
but if you're going to purchase one of these
you might as well get one that is bidirectional
in the case that you want to read something,
you can use the same device.
So what we're gonna first start off by doing,
because we've got five volts here,
we're gonna put some power to this rail up here,
and I'm gonna draw that right from the USB power
of the USB port that we're gonna plug this in here.
So we're gonna put our first jumper right there
and then we're gonna do the same thing
with the negative,
and we'll attach that right here.
Now, something to note is that although
there are ground markings on the BOB-12009,
it doesn't actually use it.
The one thing that I thought was really crazy,
when I was putting together the breakout board for this,
was that the ground lines, although they're marked here
are not actually hooked to any of the traces
so you don't have to worry about
hooking up the ground on these.
Now that we have our power here,
we're gonna go ahead and attach the high voltage
which is the five volt side,
and we'll connect this to our power here.
Now we need to supply power to the low voltage side.
And the easiest way is to get that from the Teensy itself.
If you look closely here, you can see
there's a ground and directly across from it
is the 3.3 volts
that we're gonna use to supply this here.
So all we have to do is attach this
over to the low voltage side
on the Teensy.
So you can see, we have high voltage power here
and 3.3 voltage here.
The high voltage is only five volts.
Now we're gonna attach our signal pin.
So we're going to use pin seven on the Teensy
and we're gonna hook this
to the LV1 on our logic level converter.
Now that we have our signal wire attached
we're ready to attach this relay.
What I've got here is a 10 amp 250 volt AC
or 10 amp 30 volt DC relay.
This should be powerful enough
to power just about anything
and these are very inexpensive.
This runs on five volts
so we'll need to send that signal across over here
and we'll also power this with the five volts
that we're getting from USB.
All right, I'm going to attach here
the positive line of the relay
which was our gray wire.
Our negative is the white wire.
And then finally, we have here our signal line
and this goes to the HV1
on the BOB 12009.
So right here, we have the minimal setup
that you will need
to operate this relay from the Teensy itself.
Now that we have our relay installed
we're gonna install the USB cable.
The way that the Teensy works
is that the positive is the far left most pin
or the one closest to the USB connection here.
And most of these cables come with the wiring exposed
so you can see the positive line there
and then what we're gonna do is just plug this in,
make sure you've got a solid connection.
This end now goes to your 3D printer.
Now that we have everything set up,
we're just gonna plug in our USB cable
and this goes to our computer.
Now ultimately, you can also
get rid of this connection entirely
and we can wire this up with power,
I'll cover that in a separate video
because you do have to cut a trace
on the Teensy 4.1
if you're gonna use something like a breakout board
where you need to supply this with more power,
or as I did in this demonstration
with my LEDs for neopixels.
But for just testing this out,
the five volts here is plenty of power
to trigger this, and there is an LED right here
that we will go ahead and be able to see,
triggering that when we turn that on and off.
We have our hardware set up
and now we need to flash the firmware
onto the Teensy.
You'll need to visit the PJRC website
and download a copy of Teensyduino.
Teensyduino is a software add-on
for the Arduino IDE.
You can use other IDEs, but this is the simplest method
to get up and running.
Once we have Teensyduino downloaded and installed
head on over to the Cableroot Bitbucket page.
From here, we can either clone the repository
or download it to get a copy on our local machine.
Next, open up the Cableroot sketch
in the Arduino IDE.
Now our last step is to add the Teensy Threads Library.
You'll go to sketch, and add library,
and add ZIP library.
From there, we'll navigate to the same folder
where we downloaded the repository.
And then we'll go inside the libraries folder
and you'll click the ZIP file for the Teensy threads
and click open.
After that, we're ready to start coding.
Inside the IDE, the first thing we'll want to do
is confirm that the board is set to Teensy 4.1,
all the rest of these settings
can be pretty much left alone.
One thing I do want to note
is that the Teensy does allow you
to overclock it.
So if you want more horsepower
and you want to add your own cooling,
you can have up to one gigahertz of processing speed
on the Teensy 4.1.
I'll be covering this in a later video.
Today we'll be focused on the main Cableroot sketch,
the configuration.h file, the hook sketch
and the relay sketch.
I'll cover the other functions in a later video.
The main cable Cableroot sketch
controls the main threads.
The setup function calls the setup routines
in other child sketches
and I did this so you could work
with only the pieces of code
that you need for your application.
The main loop starts all of the threads for communication,
lighting, and display.
And for today's video, we won't need to modify this at all.
So let's head on over to the configuration.h file
which controls pin assignments for the base code.
You could also enable and disable functionality from here.
For our example, we'll verify
that the relay is set to pin seven.
Now we'll open up the hook sketch
and this is where we can add hooks
when we see a particular G-code.
Most of the time, you'll simply need to add
your own function and call it from the hook sketch.
You could see here, that we call toggle relay
which is in the relay sketch,
and this sketch contains simple code
to toggle the relay.
I tried to keep everything as simple as possible.
Once we have verified everything,
simply upload the sketch to your Teensy
and we're ready to test everything with Pronterface.
All right, so here we have everything set up.
And I have now loaded Pronterface.
I know that this is on comport 8,
so we're gonna connect,
and you can see that the printer is now online.
Now the reason why is because I do have the printer
hooked up here through this USB cable connection here.
If you find that Pronterface won't connect,
it's because you don't have a printer attached.
Now, from within Pronterface
I'm gonna execute a G101 command.
This was just an arbitrary command
that I had created, and attached to pin seven
and it is in the default Cableroot code.
So this is all hooked up and ready to go
and I'm gonna execute this G101 command.
And you can see that it turned on the relay.
So our relay lit up here,
and if I had this attached to a fan or something else,
it would go ahead and turn that on.
And you can execute this as many times as you want
and it will turn on and off that relay.
So this really gives you the ability
to do anything that you want
and it doesn't send this command to the 3D printer.
So the 3D printer doesn't see that command
but Cableroot does.
So this is the most basic of the examples
that I could use
to show you how Cableroot works overall.
The rest of this is really just an expansion
of what I just showed you.
And that is, you can hook multiple things
to these pins, you can use it through the level shifter here
or what I'll be covering in a future video
is this breakout board.
The first version here had a couple of small bugs
and I am creating a second one of these.
But it already has the level shifter on there,
so that way, it converts the 3.3 to the five volts.
So let's see Cableroot in action.
(funky ambient music)
Okay, so we covered a ton in today's video,
getting set up with Cableroot
and controlling a 3D printer.
I personally liked how I had that little surprise there
and turned on the fan at the end.
You can control servos or just about anything
with this device.
It's really a cool way
for you to take your 3D printer G-code
and expand it into more real world objects.
So it's a project that I wanted to work on
and I'm really, really glad I could finally get this
to come to fruition.
So with that, it's gonna bring the end
of today's video, if you enjoyed it,
make sure you mash that like button
and don't forget to share and subscribe
so you don't miss any of the upcoming videos.
I'm looking forward to doing more videos on Cableroot
and some really cool exciting ideas.
What I would love to hear is what your thoughts
for Cableroot are.
What would you control outside
of your 3D printer with Cableroot?
Let me know down in the comments,
I think it's pretty exciting that we can do this now.
And I'm really looking forward to seeing
what the community does with Cableroot.
So with that, I'm gonna say thanks again for watching
and we'll see you next time.
(funky ambient music)