Friday, May 22, 2015

Cabinet for my Printrbot Simple Metal 3D Printer

ABS plastic can be sensitive to air currents while printing. A cool gust of air from an A/C vent, open window or ceiling fan can cause a part to warp or lift from the bed. Living in Texas we have the ceiling fan running in our home office all the time so it was a must for me to build an enclosure for my Printrbot Simple Metal printer. I also wanted to keep my 3D printer from getting dust build up on it. I've read that dust can get in the hot end and cause clogs.

I started with a wooden platform made out thin hardboard on top of MDF. Then I built the upper part of the enclosure out of plexiglass and aluminum channel. I purchased the plexi and aluminum channel from Lowes. The aluminum channel is 1/16" x 3/4" x 3/4". I bolted the whole thing together with #8-32 screws. The build chamber dimensions are 15"H x 20"W x 22"D.

I 3D printed some screw down feet for my Printrbot so it doesn't move around inside the cabinet. You can download the design for the feet here: http://www.thingiverse.com/thing:724909


The whole front of the enclosure is a hinged door. Magnetic door catches keep the door closed.


The top of the cabinet is also hinged and can be opened. 


My Printrbot has a heated print bed so it uses an ATX power supply from a computer. It has a bunch of extra wires that aren't used by the printer so I made a hollow area underneath to hide all the extra wires.



The power supply is mounted in the corner so it takes in and vents air outside of the enclosure so it doesn't overheat.



I made a spool holder out of a 6" Lazy Susan bearing and a piece of plywood. I put a 3/8" carriage bolt in the center of the spool holder turnable which is used to secure the filament spool to the holder. I used some #6-32 stand-offs and #6-32 screws with the heads cutoff to allow the turntable to sit an inch above the lid so it can rotate. This also allows the turntable to be lifted off when the top lid needs to be opened.





Then I designed a knob and cone that secures the filament spool to the turntable. You can download the design here: http://www.thingiverse.com/thing:829930





Here is a more detailed shot showing the path of the filament into the cabinet. I drilled a .25" hole in the top panel.




Next I added LED light strips around the top of the cabinet to light up the inside. The strips are power by +12vdc so I was able to hook them up to the Printrbot ATX power supply. The lights turn on when the printer is powered up.



Here is the printer in action inside the cabinet:




There one thing I'm still working on. I put an exhaust fan in the upper right corner of the back wall of the cabinet. I don't want the cabinet to get too hot inside but I also don't want the fan to run all the time or run at full speed so I'm designing a small circuit that controls the fan speed based on the temperature inside the cabinet.



UPDATE 2015-08-18

I mounted my OctoPrint print server running on a Raspberry Pi to the side of the cabinet. I also added a 20x4 character LCD display that shows useful info about the printer.




Thursday, May 21, 2015

Awesome tool for getting 3D prints off a heated bed

I have a Printrbot Simple Metal 3D printer with a heated bed. Lately I have been printing with ABS plastic which requires hairspray to get the prints to stick to the bed without warping. While this works great it to keep the print stuck to the bed it can be difficult to get the prints off the bed without damaging the print or the Kapton tape. I've tried an X-Acto knife but it digs into the Kapton tape. Paint scrapers are usually too thick and have a blunt edge that can't get under the print. Some people use pliers to grasp the part and pull it off but I've found the pliers makes marks on the part when you grab it. My wife recommended a tool that we use with our Silhouette Cameo vinyl cutter:


It's made by Cricut and they call it a Spatula Tool. It has a very thin front edge that is good for getting under prints and then it tapers up a little bit to make it stronger.



I slide it in under a corner and work it around the print and then lift up a bit and the print pops off. It looks like the spatula we have is an old model but I did a search on E-bay and there are a several of them for sale for less than $10 bucks. Just search for 'Cricut Spatula Tool' and look for one with a green handle. Cricut's has a new spatula design but is a little smaller and I don't know if it works as well. I might buy one just to try it out.



Monday, February 9, 2015

Arduino, CAN Bus and 29 bit extended IDs

I noticed in my blog traffic stats that people are searching for information about 29 bit CAN IDs and I have been curious about this topic myself. I haven't come across 29 bit CAN IDs in a vehicle until recently and seeing these extended IDs in use in a car made want to understand how to use them with Arduino boards and MCP2515 CAN controllers. I wrote a blog post back in October 2013 that covers how to send data between two Arduino boards using a CAN bus so you may want to check that out if you aren't familiar with how a CAN bus works. That post is available here. This post is specifically about using 29 bit CAN IDs with an Arduino and the MCP2515 CAN controller chip.

CAN Bus IDs


There are two types of CAN Bus IDs. In the first version of the CAN Bus spec (2.0A) the IDs were made up of 11 bits. These are also known as base frame format messages. This allows for message IDs between 0x000 and 0x7FF. Which works out to be 2048 possible CAN IDs.

Binary, Decimal and Hex representation of the max 11 bit ID
 As CAN Busses were added to heavy equipment and as vehicles became more complex those 2048 possible IDs were not enough to handle the increased number of sensors. CAN 2.0B was created which increased the size of IDs from 11 bits to 29 bits. CAN 2.0B allows for over 536 million different IDs. 29 bit messages are also known as extended frame format messages. 18 bits were added to the original 11 bits in an separate field in a CAN message. There is a flag in the message that signals if a message is an 11 bit or 29 bit message. 11 bit and 29 bit messages can coexist on the same CAN bus.

Binary, Decimal and Hex representation of the max 29 bit ID
There are some trade-offs with 29 bit CAN IDs though. The latency is increased, the messages use more bandwidth and error detection performance is decreased. But if you have run out of IDs I suppose these are worthwhile trade-offs.


11 bit code example


Let's take a look at a very simple example of using an MCP2515 CAN controller with an Arduino and 11 bit CAN IDs. I am using a Seeed Studio CAN-BUS Shield but the MCP2515 is just an SPI chip that can be wired up with minimal external components.
In this 11 bit example I am using a CAN ID of 0x07B in hex (123 in decimal).


Here you can see my receiver Arduino is receiving CAN messages with an ID of 123.



29 bit code example


Next let's look at an example of sending 29 bit CAN IDs. In this example I am using a CAN ID of 0x17F8140E in hex (or 402134030 in decimal).


Here you can see my receiver Arduino is receiving CAN messages with an ID of 402134030.



sendMsgBuf format

The key piece of this example code is the sendMsgBuf function. This function is part of the
MCP_CAN_lib. This is where messages are flagged as 11 bit or 29 bit.

11 bit: CAN.sendMsgBuf(0x07B, 0, 8, canMsg);

29 bit: CAN.sendMsgBuf(0x17F8140E, 1, 8, canMsg);


The format for this function is sendMsgBuf(can_id, id_type, dlc, data_buf)

can_id - id number for your message in hex or decimal.

id_type - flag for 11 or 29 bit message id. 0=11bit, 1=29bit

dlc - Number of bytes in the message data

data_buf - The data transmitted in the message.


If you are going to try out these examples you should download Cory Fowler's fork of the MCP_CAN_lib.


Resources

Sunday, February 1, 2015

CAN Bus to UART using an Adafruit Pro Trinket

I have been fighting with the onboard CAN controller on my BeagleBone Black trying to
get it to work properly for months. In the process I learned about pin muxing, bone-capemgr and compiling overlays. I was able to bring up the can0 interface and receive can messages with candump but the interface was unstable. It would randomly hang and stop receiving messages. If I tried to send anything with cansend I would get a kernel stack traces in dmesg and the can0 interface would hang.  I tried Angstrom, Ubuntu and the latest Debian images all with the same results. Maybe my BBB board has a hardware problem. It is one of the early Rev B boards. Or maybe I'm running into some sort of kernel driver bug. Whatever the issue I am done trying to figure out what the eff is wrong with it and I just want to move forward with my project. (and yes I was using a transceiver). I considered bypassing the onboard can controller and talking to a MCP2515 over SPI but that gets into compiling a custom kernel for the BBB and I don't want to use up a SPI port. I mention all of this because I know someone out there will say "why didn't you just use the onboard can controller". I tried and I am done fighting with it.

My attempt at using the CAN controller on
the BBB with an MCP2562 transceiver

What now?

Once I decided I wasn't going to get the onboard BBB can controller to work I started thinking about options. My first attempt at a workaround was an Arduino Uno with a Seeed CAN Bus shield connected to the BBB with a USB cable. I read the data from the serial port created over the USB connection. While this worked it was a bit bulky and fragile. The USB cable is much too big, the Uno with a shield is big and the Uno would reset when serial communication started (though there is a workaround for this).

I took a break from this project for a while and in the meantime I ordered a few Adafruit Trinkets and Pro Trinkets just to play around with. The Pro Trinket has the same microcontroller as the Uno but the board is much, much smaller.

Size comparison between Uno, Pro Trinket and Trinket.
(Photo credit: Adafruit)

Pro Trinket CAN to UART Converter

The Pro Trinket has SPI and UART plus a bunch of digital and analog pins. After playing around with the Trinket I realized I could build a CAN Bus to UART converter that would be able to push CAN data into the BBB over a UART. The BeagleBone is a 3.3volt device so I used the 3volt version of the Pro Trinket so I didn't have to use any level shifters. For the CAN Bus controller I used an MCP2515 and for the CAN transceiver I used an MCP2562. The MCP2515 connects to the Arduino using a SPI connection. Here is the circuit I came up with:



Here is a Fritzing breadboard diagram of the circuit:

The UART serial connection between the Arduino and the BeagleBone runs at 115,200 bps so you might drop a few packets on a very busy CAN bus running at 500kbps. My Digital Dashboard project is only going to have a few devices broadcasting CAN packets so the UART speed will be more than enough for my purposes. The current version only transmits CAN data to the BBB. It should be fairly trivial to connect the BBB UART1 TX to the RX on the Arduino. It would also need a bit of code to parse the message received on the UART and write it to the CAN bus. I'm planning on adding the functionality soon and I'll write up another post when I have that done. I'm planning on changing the Arduino code to use an External Interrupt so the Trinket can perform a few other functions instead of just polling for incoming messages.

The Arduino Code

The way this works is the MCP2515 has an INT (interrupt) pin that signals when a CAN message has been received. The INT pin drives Pin3 on the Arduino low and triggers it to read messages from the MCP2515 buffer. Once a message has been read from the MCP2515 buffer it is formatted into a NMEA-ish string that is written to the serial port and transmitted to the BBB on UART1.

Screenshot of CAN data coming in on UART1

 Here is the Arduino code:



Setting up the BeagleBone

The pins on the BeagleBone need to be configured to be used as a UART. I used Adafruit's python IO library to do this. When you install their library it will create the overlays needed to configure the pins. Follow the instructions on their learn site here: https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black. Here is the code to receive the CAN messages on BBB UART1:


Costs

The price for these parts wasn't bad at all

Adafruit Pro Trinket 3v - $9.95
16Mhz Crystal - $1.12
Two 22pF ceramic capacitors - $0.66
MCP2515 CAN controller - $2.18
MCP2562 CAN transceiver - $1.12

Total: $15.03


Well that's it for now. Next I'm going to work on modifying the code to use External Interrupts and then see if I can get it setup to receive messages over the UART. I also need to get this thing moved from the breadboard and soldered on to some protoboard.




Resources
http://www.embedded-things.com/bbb/enable-canbus-on-the-beaglebone-black/
http://www.adafruit.com/product/2010
https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/uart
http://ww1.microchip.com/downloads/en/DeviceDoc/21801d.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/25167B.pdf

Sunday, October 5, 2014

Speed up screen redraws with a BeagleBone Black and Adafruit TFT

In a previous post I wrote about experimenting with the BeagleBone Black and an Adafruit 2.2" TFT screen. The TFT screen communicates over SPI using a userspace library. Being a userspace library it is expected it will be slower than driver that is compiled into the kernel but something in the code seemed to be causing redraws to be unnecessarily slow.

Adafruit 2.2" TFT with a BeagleBone Black
To measure how long the screen draws were taking I modified the example image.py script to read the time right before and right after the screen draw function call. I also wrapped a while loop around it so it would redraw the screen repeatedly to give me an average of how long it took.

Code to measure screen redraw time

Depending on how much of the screen was being redrawn and the load on the BBB it would take between 0.7 seconds to 0.9 seconds to execute the disp.display(image) function. The following output is for the example image.py that draws the cat.jpg file to the screen:

Output measuring screen redraw time

One of the commenters on my previous post tracked down the slowness to one specific function named 'image_to_data' in the file ILI9341.py. He also supplied a modification that reduced his screen redraw time dramatically by using NumPy. I tried it out and it reduced my screen redraw times dramatically. Screen redraws went from 0.85 seconds to 0.17 seconds. That is an 80% improvement!

Screen redraw times when using NumPy

If you want to make this modification yourself here is what you need to do:

1. Install PyNum. This is easy to install as it is available as a pkg.

Install the python-numpy package


2. Edit the file Adafruit_Python_ILI9341/Adafruit_ILI9341/ILI9341.py

First add the import statement at the top

Add import statement for numpy

Next modify the image_to_data function. Here is the original function

Original image_to_data function

and here is the function after being modified to use NumPy

Modified image_to_data function

3. Save the file and then re-run the installation script.



If you don't want to manually make these modifications you can use my forked version of the library: https://github.com/matt448/Adafruit_Python_ILI9341

I have submitted a pull request to Adafruit for this change so maybe in the future this will be included there. [UPDATE: Adafruit has pulled these changes into the master branch of their library. If you download the latest version here https://github.com/adafruit/Adafruit_Python_ILI9341 you will get the improved screen drawing speed.]


Here are videos before and after I made the change. It's quite noticeable when making quick changes. Before making the code changes the display would lag behind when adjustments were made to the pot.
BEFOREAFTER



[Updated 2014-10-08: Added before and after videos.]
[Updated 2015-03-11: Added note about my pull request being included in the main library.]


Thursday, September 25, 2014

Using the Seeed CAN-BUS shield with an Arduino Mega


The Seeed Studio CAN-BUS shield is designed specifically to be used with an Arduino Uno but with a simple modification you can use it with several other Arduino boards. I sourced this info from a few different forums and thought I would write up a complete post on exactly how to do this. The Seeed website had some info on how to use the shield with a Mega but their info was not complete and did not work for me. In this post I am going to show how to use the Seeed CAN-BUS shield with an Arduino Mega 2560.

The CAN-BUS shield incompatibility with Arduino boards other than the Uno arises from where Seeed chose to access the SPI pins. They used pins 11,12,13 to access SPI on the Uno. On the Mega the SPI pins are 50,51,52. A better design would have been to use the SPI pins on the ICSP header which is consistent on the Uno, Mega, Due and Leonardo but such is life and we have to work with what is available right now. Seeed's site does mention they are working on a 1.1 version of the board that moves SPI to the ICSP header.

Here is an Arduino Uno with the SPI pins labeled
Arduino Uno SPI pins


And here is an Arduino Mega 2560 with the SPI pins labeled
Arduino Mega 2560 SPI pins


Here is what the Seeed Studio CAN-BUS Shield looks like if you don't already own one
Seeed Studio CAN-BUS Shield v1.0


The mod

Here is how to modify the CAN-BUS Shield to work with a Mega. The basic overview of the mod is that we need to change the SPI pins that the CAN-BUS Shield is using. There are two ways to do this modification. One one is reversible and the other is more permanent. First the reversible method.

The reversible method is to bend three pins on the CAN-BUS Shield like this:


When you plug the shield into the Mega it will look like this:


With bent pins I was able to bend them back use the shield with an Uno again.

Now you need to use three jumper wires to connect the SPI pins on the shield to the SPI pins on the Arduino board. In my example I connected the wires to pins 50,51,52 on the Arduino because I only had male-male jumper wires. If you have male-female jumper wires you can connect to the ICSP header instead.

Jumper wire connections
Mega Pin Shield Pin SPI Desc
50 12 MISO
51 11 MOSI
52 13 SCK


Here is what it looks like with the jumper wires installed




I would recommend you use coryjfowler's MCP2515 library instead of the Seeed's because his fork of the library has a configureable SS pin but Seeed's version will work with this mod because they hard coded the SS pin as digital pin 10.

I then loaded up one of the examples and the shield started up correctly.


If you want to make this modification more permanent you can simply snip off the three pins instead of bending them.



I found some male-female jumper wires at Fry's Electronics yesterday. Here is what it looks like when using the ICSP headers


ICSP Pin Shield Pin SPI Desc
1 12 MISO
4 11 MOSI
3 13 SCK


Sources
http://arduino.cc/en/Reference/SPI
http://forum.arduino.cc/index.php?topic=123367.0
http://www.seeedstudio.com/forum/viewtopic.php?f=23&t=5172
http://www.seeedstudio.com/wiki/Talk:CAN-BUS_Shield
http://www.seeedstudio.com/wiki/CAN-BUS_Shield


[Updated 2014-09-29] - Added photos of shield with the pins snipped off. Also added photo showing the male-female jumpers with the ICSP header.

[Updated 2014-10-23] - Added table with pinouts for connecting the shield to the ICSP header.